tree: a91bf6ed4ddc82e10435a0424945645b81771178 [path history] [tgz]
  4. examples/
  5. fidlmerge.go
  6. flags.go


A host tool for generating arbitrary code from FIDL namespace JSON.

fidlmerge merges the FIDL namespace JSON generated by the FIDL compiler front end with a template. Templates are based on go's text/template package.


fidlmerge -template <template path> -json <json path> -output-base <output file base name> [ -options key=value,... ] [ -amend <amend path> ]

Example templates reside in the examples subdirectory.

The json path is something like out/x64/fidling/gen/sdk/fidl/fuchsia.netstack.fidl.json.

The output file base name is used to generate output file names. The template can add extensions to the base name.

Options can be accessed by templates using the getOption function or one of its variants.

The amend path refers to a json file that contains amendments to the FIDL json. Declarations can be omitted from the FIDL data using the “exclusions” property:

  "exclusions": [


Template format documentation is here. Also see the example templates in the examples subdirectory.

Template files contain multiple named templates. The main template is invoked initially and given a main.Root struct (see generator.go) as the dot value. Text generated by the template is routed to stdout, which will be unsuitable for most purposes. Normally, the main template will use main.Root.Generate to generate a specific file or files. Here, for example, we're generating two files, one a .h and the other a .cc:

{{- define "Main" }}
    {{- $include_path := .Output ".h" }}
    {{- $implementation_path := .Output ".cc" }}
    {{ .Generate $include_path "IncludeFile" . }}
    {{ .Generate $implementation_path "ImplementationFile" . }}
{{ end }}

The .h file is generated by a template named IncludeFile, and the .cc file is generated by a template named ImplmentationFile.

main.Root provides the .Output and .Generate methods. The description of the FIDL namespace is defined by types.Root (in fidl/compiler/backend/types), which is part of main.Root.