feat: expose bazel_version

It's a fair amount of code that wires up the version here.
See https://github.com/bazelbuild/bazel/issues/8305#issuecomment-1954690199 for a published workaround, but it's not complete due to subtleties like https://github.com/bazel-contrib/bazel_features/issues/25

In my opinion the maintenance burden of bazel_features exposing this one string is worth it to avoid other rules like bazelrc-preset.bzl having to copy dozens of lines of code.
1 file changed
tree: 832affd219440eb8aaf1a0b539e9c5b4a12bca18
  1. .bcr/
  2. .github/
  3. private/
  4. test/
  5. .bazelignore
  6. .bazelrc
  7. .bazelversion
  8. .gitignore
  9. .pre-commit-config.yaml
  10. BUILD.bazel
  11. CONTRIBUTING.md
  12. deps.bzl
  13. features.bzl
  14. LICENSE
  15. MODULE.bazel
  16. README.md
  17. renovate.json
  18. WORKSPACE.bazel
  19. WORKSPACE.bzlmod
README.md

Bazel Features

Use this to determine the availability of a Bazel feature in your ruleset. It works under the hood by comparing the Bazel version against a known range in which the feature is available. Example usage:

load("@bazel_features//:features.bzl", "bazel_features")
if bazel_features.toolchains.has_optional_toolchains:
    # Do something

The features.bzl file contains the list of features.

Accessing globals

References to global Starlark symbols that do not exist cause load time errors, which means that their availability in Bazel cannot be tested via a regular feature. Instead, use bazel_features.globals.<symbol>, which is <symbol> if the symbol is available and None else.

See globals.bzl for the list of symbols that can be checked for in this way.