build_info.bzl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. """
  10. Defines a Bazel rule that executes a Python script, that will generate a Rust
  11. file with static values for all of the "workspace status" variables.
  12. """
  13. def _impl(ctx):
  14. # Arguments that we pass to `gen_rust_module.py`.
  15. #
  16. # Bazel provides all of the 'volatile' variables in the 'version_file' and
  17. # 'stable' variables in the 'info_file', no idea why they chose this naming
  18. # scheme, but see <https://bazel.build/rules/lib/builtins/ctx#info_file>
  19. # for more info.
  20. args = ["--rust_file", ctx.outputs.rust_file.path] + \
  21. ["--volatile_file", ctx.version_file.path] + \
  22. ["--stable_file", ctx.info_file.path]
  23. ctx.actions.run(
  24. inputs = [ctx.version_file, ctx.info_file],
  25. outputs = [ctx.outputs.rust_file],
  26. arguments = args,
  27. progress_message = "Generating build info to {}".format(ctx.outputs.rust_file.path),
  28. executable = ctx.executable._gen_rust_module,
  29. )
  30. gen_build_info = rule(
  31. implementation = _impl,
  32. attrs = {
  33. "_gen_rust_module": attr.label(
  34. executable = True,
  35. cfg = "host",
  36. allow_files = True,
  37. default = Label("//misc/bazel/build-info:gen_rust_module"),
  38. ),
  39. "rust_file": attr.output(mandatory = True),
  40. },
  41. )