Skip to content

Commit

Permalink
extensions: gate module_ctx.extension_metadata(reproducible = ...)
Browse files Browse the repository at this point in the history
…appropriately

`reproducible` was added in Bazel 7.1.0; gating this argument allows
older Bazel versions to use rules_cc 0.0.13 and newer.

Note that this change (use of `reproducible`) came from Bazel itself in
bazelbuild/bazel#22335; it made its way over to `rules_cc` via
bazelbuild@c2549f6
(see bazelbuild/bazel@1c4e78a).

More context [here](bazel-contrib/toolchains_llvm#389 (comment)).
  • Loading branch information
rrbutani committed Oct 11, 2024
1 parent ba3ec91 commit 14a11be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module(
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "protobuf", version = "27.0")
bazel_dep(name = "bazel_features", version = "1.19.0")

cc_configure = use_extension("//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains")
Expand Down
11 changes: 11 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

http_archive(
name = "bazel_features",
sha256 = "3646ffd447753490b77d2380fa63f4d55dd9722e565d84dfda01536b48e183da",
strip_prefix = "bazel_features-1.19.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.19.0/bazel_features-v1.19.0.tar.gz",
)

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

http_archive(
name = "rules_testing",
sha256 = "02c62574631876a4e3b02a1820cb51167bb9cdcdea2381b2fa9d9b8b11c407c4",
Expand Down
7 changes: 6 additions & 1 deletion cc/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@
# limitations under the License.
"""Module extension for cc auto configuration."""

load("@bazel_features//:feature.bzl", "bazel_features")
load("//cc/private/toolchain:cc_configure.bzl", "cc_autoconf", "cc_autoconf_toolchains")

def _cc_configure_extension_impl(ctx):
cc_autoconf_toolchains(name = "local_config_cc_toolchains")
cc_autoconf(name = "local_config_cc")
return ctx.extension_metadata(reproducible = True)

has_reproducible = bazel_features.external_deps.extension_metadata_has_reproducible
return ctx.extension_metadata(
**(dict(reproducible = True) if has_reproducible else {})
)

cc_configure_extension = module_extension(implementation = _cc_configure_extension_impl)

0 comments on commit 14a11be

Please sign in to comment.