Drop compatibility with 6.0.0 (#4411)
**What type of PR is this?**
Cleanup
**What does this PR do? Why is it needed?**
Simplify C++ toolchain handling by requiring at least Bazel 6.1.0. This
will be used in future PRs to implement proper, exec-platform aware
resolution for the combination of Go and (optional) C++ toolchain.
**Which issues(s) does this PR fix?**
**Other notes for review**
diff --git a/go/private/BUILD.bazel b/go/private/BUILD.bazel
index 0301cc6..5abbd1b 100644
--- a/go/private/BUILD.bazel
+++ b/go/private/BUILD.bazel
@@ -64,7 +64,6 @@
"@bazel_skylib//rules:common_settings",
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
- "@io_bazel_rules_go_bazel_features//:features",
"@io_bazel_rules_nogo//:scope.bzl",
],
)
diff --git a/go/private/context.bzl b/go/private/context.bzl
index f5cd735..c2b459f 100644
--- a/go/private/context.bzl
+++ b/go/private/context.bzl
@@ -34,7 +34,6 @@
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
"find_cpp_toolchain",
)
-load("@io_bazel_rules_go_bazel_features//:features.bzl", "bazel_features")
load(
"@io_bazel_rules_nogo//:scope.bzl",
NOGO_EXCLUDES = "EXCLUDES",
@@ -707,10 +706,7 @@
# toolchain (to be inputs into actions that need it).
# ctx.files._cc_toolchain won't work when cc toolchain resolution
# is switched on.
- if bazel_features.cc.find_cpp_toolchain_has_mandatory_param:
- cc_toolchain = find_cpp_toolchain(ctx, mandatory = False)
- else:
- cc_toolchain = find_cpp_toolchain(ctx)
+ cc_toolchain = find_cpp_toolchain(ctx, mandatory = False)
if not cc_toolchain or cc_toolchain.compiler in _UNSUPPORTED_C_COMPILERS:
return []
@@ -924,7 +920,7 @@
cgo_context_data = rule(
implementation = _cgo_context_data_impl,
attrs = {
- "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:optional_current_cc_toolchain" if bazel_features.cc.find_cpp_toolchain_has_mandatory_param else "@bazel_tools//tools/cpp:current_cc_toolchain"),
+ "_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:optional_current_cc_toolchain"),
"_xcode_config": attr.label(
default = "@bazel_tools//tools/osx:current_xcode_config",
),
@@ -933,8 +929,7 @@
# In pure mode, a C++ toolchain isn't needed when transitioning.
# But if we declare a mandatory toolchain dependency here, a cross-compiling C++ toolchain is required at toolchain resolution time.
# So we make this toolchain dependency optional, so that it's only attempted to be looked up if it's actually needed.
- # Optional toolchain support was added in bazel 6.0.0.
- config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False) if hasattr(config_common, "toolchain_type") else "@bazel_tools//tools/cpp:toolchain_type",
+ config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
],
fragments = ["apple", "cpp"],
doc = """Collects information about the C/C++ toolchain. The C/C++ toolchain
diff --git a/go/private/polyfill_bazel_features.bzl b/go/private/polyfill_bazel_features.bzl
index 7d28a3e..986a4c2 100644
--- a/go/private/polyfill_bazel_features.bzl
+++ b/go/private/polyfill_bazel_features.bzl
@@ -5,9 +5,6 @@
# We just implement the checks we've seen we actually need, and hope to delete this completely when we are in a pure-bzlmod world.
_POLYFILL_BAZEL_FEATURES = """bazel_features = struct(
- cc = struct(
- find_cpp_toolchain_has_mandatory_param = {find_cpp_toolchain_has_mandatory_param},
- ),
external_deps = struct(
# WORKSPACE users have no use for bazel mod tidy.
bazel_mod_tidy = False,
@@ -16,16 +13,6 @@
"""
def _polyfill_bazel_features_impl(rctx):
- # An empty string is treated as a "dev version", which is greater than anything.
- bazel_version = native.bazel_version or "999999.999999.999999"
- version_parts = bazel_version.split("-")[0].split(".")
- if len(version_parts) != 3:
- fail("invalid Bazel version '{}': got {} dot-separated segments, want 3".format(bazel_version, len(version_parts)))
- major_version_int = int(version_parts[0])
- minor_version_int = int(version_parts[1])
-
- find_cpp_toolchain_has_mandatory_param = major_version_int > 6 or (major_version_int == 6 and minor_version_int >= 1)
-
rctx.file("BUILD.bazel", """
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(
@@ -35,9 +22,7 @@
)
exports_files(["features.bzl"])
""")
- rctx.file("features.bzl", _POLYFILL_BAZEL_FEATURES.format(
- find_cpp_toolchain_has_mandatory_param = repr(find_cpp_toolchain_has_mandatory_param),
- ))
+ rctx.file("features.bzl", _POLYFILL_BAZEL_FEATURES)
polyfill_bazel_features = repository_rule(
implementation = _polyfill_bazel_features_impl,