MODULE.bazel 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. # Exceptions. See /LICENSE for license information.
  3. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. """Example Bazel module that builds C++ with the Carbon toolchain.
  5. Note that this is at the root of an example Bazel project, not part of the
  6. larger Carbon Bazel project. To interact with this example, you'll want to
  7. `cd examples/bazel` so that you can operate Bazel entirely within this example
  8. (sub-)project.
  9. Once interacting with this subdirectory's project, you can use this and build
  10. with the Carbon toolchain in a few different ways:
  11. 1) Override the module with a local installation on the command line:
  12. `bazel build --override_module=carbon_toolchain=/path/to/carbon_toolchain/installation/lib/carbon`
  13. 2) Encode a local override into this file:
  14. ```
  15. local_path_override(
  16. module_name = "carbon_toolchain",
  17. path = "/path/to/carbon_toolchain/installation/lib/carbon",
  18. )
  19. ```
  20. 3) Encode a archive override into this file:
  21. ```
  22. version = "0.0.0-0.nightly.YYYY.MM.DD"
  23. archive_override(
  24. module_name = "carbon_toolchain",
  25. strip_prefix = "carbon_toolchain-{0}/lib/carbon".format(version),
  26. urls = ["https://github.com/carbon-language/carbon-lang/releases/download/v{0}/carbon_toolchain-{0}.tar.gz".format(version)],
  27. )
  28. ```
  29. Note: Initially, Bazel will warn about the lack of an `integrity` field,
  30. and will print the value it found by downloading the archive which you can
  31. verify on GitHub before encoding.
  32. You can use the provided script `update_module_to_nightly.py` to generate and
  33. add an `archive_override` of the current nightly release, including integrity
  34. from GitHub.
  35. Once the Carbon toolchain has established releases in the Bazel central
  36. registry, this file will work with an updated version out of the box.
  37. """
  38. module(name = "example")
  39. bazel_dep(name = "rules_cc", version = "0.2.14")
  40. # Declare the `carbon_toolchain` module. This is needed even if it will be
  41. # overridden with a local path or archive.
  42. bazel_dep(name = "carbon_toolchain", version = "0.0.0")
  43. register_toolchains("@carbon_toolchain//:all")