tree: 4037e025f79d6155ec4c2150cd49ac9169380a80 [path history] [tgz]
  1. static/
  2. templates/
  3. files.py
  4. frontend.py
  5. generate.py
  6. README.md
  7. template_model.py
bazel_rules_generator/README.md

Bazel rules generator

This directory contains a template-based generator that reads JSON metadata from a given Fuchsia SDK and generates the corresponding Bazel rules.

This first version is mostly a copy and adaptation of the generator used in the Fuchsia source tree. In the upcoming revisions, it is expected that this tool changes and diverges significantly from the original tool, which will continue to be used to self-test the Fuchsia SDK.

Create a new set of Bazel rules

./generate.py --directory <FUCHSIA_SDK_DIRECTORY> --output <OUT_DIR>

At some point, the rules created by this tool will end up being pushed to the https://fuchsia.googlesource.com/fuchsia-bazel-rules/ repository. Currently, they are only local.

Using the Bazel rules

Add the following lines to your WORKSPACE file:

local_repository(
    name = "fuchsia_sdk",
    path = "../fuchsia-bazel-rules",
)

load("@fuchsia_sdk//build_defs:fuchsia_setup.bzl", "fuchsia_setup")
fuchsia_setup(
    with_toolchain = True,
)

And then, when you build, specify --config=fuchsia_<arch>, for example:

bazel build --config=fuchsia_x64 src/example_driver

Currently, the local_repository needs to be named fuchsia_sdk, but this is a bug and should be fixed soon.

List of upcoming changes

  • allow arbitrary names for the repository of the rules. Currently it has to be named fuchsia_sdk, since there are internal hardcoded references.

  • generate WORKSTATION and BUILD files in a directory structure parallel to the Fuchsia SDK. Currently, the generate.py script copies the content from the Fuchsia SDK and adds the Bazel build rules to the <OUT_DIR>, which essentially creates an entire new SDK. The goal is to have WORKSPACE and BUILD rules only, and have an external dependency on the Fuchsia SDK.

  • rename the generated rules and change their APIs to comply with the designed API.

  • make the generated rules fetch the pre-defined Fuchsia SDK on demand instead of (or in addition to) relying on a local directory.

  • add support for drivers and product assembly.

  • ensure the generator self-tests are passing and has good coverage.

  • clean up the generator code and make it more robust (TODO: specify exactly what needs to be done here)