Contributing to FIDL

Overview

The FIDL toolchain is composed of roughly three parts:

  1. Front-end, a.k.a. fidlc
    • Parses and validates .fidl files
    • Calculates size, alignment, and offset of various structures
    • Produces a JSON IR (Intermediate Representation)
  2. Back-end
    • Works off the IR (except the C back-end)
    • Produces target language specific code, which ties into the libraries for that language
  3. Runtime Libraries
    • Implement encoding/decoding/validation of messages
    • Method dispatching mechanics

Code Location

The front-end lives at //zircon/system/host/fidl/, with tests in //zircon/system/utest/fidl/.

The back-end and runtime library locations are based on the target:

TargetBack-endRuntime Libraries
C//zircon/system/host/fidl/lib/c_generator.cpp//zircon/system/ulib/fidl/
C++//garnet/go/src/fidl/compiler/backend/cpp///zircon/system/ulib/fidl/ & //garnet/public/lib/fidl/cpp/
Go//garnet/go/src/fidl/compiler/backend/golang///third_party/go/src/syscall/zx/fidl/
Rust//garnet/go/src/fidl/compiler/backend/rust///garnet/public/lib/fidl/rust/fidl/
Dart//topaz/bin/fidlgen_dart///topaz//public/dart/fidl/
//topaz/bin/fidl_bindings_test/
JavaSciptchromium:build/fuchsia/fidlgen_fschromium:build/fuchsia/fidlgen_js/runtime

Other Tools

TBD: linter, formatter, gidl, difl, regen scripts, etc.

General Setup

Fuchsia Setup

Read the Fuchsia Getting Started guide first.

fx set

fx set core.x64 --with //bundles:tests --with //topaz/packages/tests:all --with //sdk:modular_testing

or, to ensure there's no breakage with lots of bindings etc.:

fx set terminal.x64 --with //bundles:kitchen_sink --with //vendor/google/bundles:buildbot

Compiling, and Running Tests

We provide mostly one-liners to run tests for the various parts. When in doubt, refer to the “Test:” comment in the git commit message; we do our best to describe the commands used to validate our work there.

fidlc

In zircon/:

# optional; builds fidlc for the host with ASan <https://github.com/google/sanitizers/wiki/AddressSanitizer>
fx set core.x64 --variant=host_asan

# build fidlc
fx build zircon/tools

fidlc tests

fidlc tests are at:

# build & run fidlc tests
fx build zircon/system/utest:host
$FUCHSIA_DIR/out/default.zircon/host_tests/fidl-compiler-test.debug

# build & run fidl-coding-tables tests
# --with-base puts all zircon tests under /boot with the bringup.x64 target, or /system when using the core.x64 target
fx set bringup.x64 --with-base //garnet/packages/tests:zircon   # optionally append "--variant asan"
fx build
fx run -k -c zircon.autorun.boot=/boot/bin/runtests+-t+fidl-coding-tables-test

fidlgen (LLCPP, HLCPP, Rust, Go)

Some example tests you can run:

fx run-host-tests fidlgen_cpp_ir_test
fx run-host-tests fidlgen_golang_ir_test

To regenerate the goldens:

fx exec garnet/go/src/fidl/compiler/backend/typestest/regen.sh

fidlgen_dart

Some example tests you can run:

fx run-host-tests fidlgen_dart_backend_ir_test

To regenerate the goldens:

fx exec topaz/bin/fidlgen_dart/regen.sh

C runtime

fx set bringup.x64 --with-base //garnet/packages/tests:zircon
fx build
fx run -k -c zircon.autorun.boot=/boot/bin/runtests+-t+fidl-test

When the test completes, you're running in the QEMU emulator. To exit, use Ctrl-A x.

C++ runtime

You first need to have Fuchsia running in an emulator. Here are the steps:

Tab 1> fx build && fx serve-updates

Tab 2> fx run -kN

Tab 3> fx run-test fidl_tests

Go runtime

You first need to have Fuchsia running in an emulator. Here are the steps:

Tab 1> fx build && fx serve-updates

Tab 2> fx run -kN

Tab 3> fx run-test go_fidl_tests

As with normal Go tests, you can pass various flags to control execution, filter test cases, run benchmarks, etc. For instance:

Tab 3> fx run-test go_fidl_tests-- -test.v -test.run 'TestAllSuccessCases/.*xunion.*'

Rust runtime

TBD

Dart runtime

The Dart FIDL bindings tests are in //topaz/bin/fidl_bindings_test/.

You first need to have Fuchsia running in an emulator. Here are the steps:

Tab 1> fx build && fx serve-updates

Tab 2> fx run -kN

Tab 3> fx run-test fidl_bindings_test

Compatibility Test

The language bindings compatibility test is located in //topaz/bin/fidl_compatibility_test, and is launched from a shell script.

To build this test, use:

fx build topaz/bin/fidl_compatibility_test/dart:fidl_compatibility_test_server_dart
``

To run this test, you first need to have a Fuchsia instance running in an emulator:

```sh
fx run -N

Then, copy the script to the device, and run it:

fx cp `find topaz -name run_fidl_compatibility_test_topaz.sh` /tmp/
fx shell /tmp/run_fidl_compatibility_test_topaz.sh

Workflows

Language evolutions

One common task is to evolve the language, or introduce stricter checks in fidlc. These changes typically follow a three phase approach:

  1. Write the new compiler code in fidlc;
  2. Use this updated fidlc to compile all layers, including vendor/google, make changes as needed;
  3. When all is said and done, the fidlc changes can finally be merged.

All of this assumes that (a) code which wouldn't pass the new checks, or (b) code that has new features, is not introduced concurrently between step 2 and step 3. That typically is the case, however, it is ok to deal with breaking rollers once in a while.

Go fuchsia.io and fuchsia.net

To update all the saved fidlgen files, run the following command, which automatically searches for and generates the necessary go files:

fx exec third_party/go/regen-fidl

FAQs

Why is the C back-end different than all other back-ends?

TBD

Why is fidlc in the zircon repo?

TBD

Why aren't all back-ends in one tool?

We'd actually like all back-ends to be in separate tools!

Down the road, we plan to have a script over all the various tools (fidlc, fidlfmt, the various back-ends) to make all things accessible easily, and manage the chaining of these things. For instance, it should be possible to generate Go bindings in one command such as:

fidl gen --library my_library.fidl --binding go --out-dir go/src/my/library

Or format a library in place with:

fidl fmt --library my_library.fidl -i