This tutorial builds on the [Compiling FIDL][compiling] tutorial. For the full set of FIDL tutorials, refer to the overview.
This tutorial walks through how to add debug printing to HLCPP types, using the fostr tool.
If you'd like to follow along by writing the code yourself, feel free to delete the following directories to get started:
rm -r examples/fidl/hlcpp/fostr garnet/public/lib/fostr/fidl
This tutorial contains the following steps:
fostr_fidl target for a FIDL library. This will allow debug printing for types in the library by defining an operator<< for each type.fostr_fidl target.Create a directory for the BUILD file inside //garnet/public/lib/fostr/fidl
mkdir -p garnet/public/lib/fostr/fidl/fuchsia.examples
Create the BUILD file
touch garnet/public/lib/fostr/fidl/fuchsia.examples/BUILD.gn
Add the following definition to the build file:
{%includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="garnet/public/lib/fostr/fidl/fuchsia.examples/BUILD.gn" %}
This defines a fostr target for the fuchsia.examples library. Any dependencies to the library needs to be specified in the build file as well, but this doesn't apply to our library as it has no dependencies. For more complex examples, refer to the existing definitions in the fostr fidl directory.
The target library that the tutorial uses is a simple host test, which is located in examples/fidl/hlcpp/fostr. Notice that the BUILD file for the test includes the fostr_fidl target as a dependency:
{%includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/fidl/hlcpp/fostr/BUILD.gn" region_tag="bin" highlight="7" %}
The included library automatically overloads the << operator. The path is based on the name of the FIDL library it is generated for:
{%includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/fidl/hlcpp/fostr/main.cc" region_tag="includes" %}
Write some placeholder tests to show off the output:
{%includecode gerrit_repo="fuchsia/fuchsia" gerrit_path="examples/fidl/hlcpp/fostr/main.cc" region_tag="tests" %}
Configure the GN build to include the example
fx set core.x64 --with //examples/fidl/hlcpp/fostr
Run the test
fx test -vo fostr-example-test