Skip to content

Commit 4957aa3

Browse files
authored
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**
1 parent beb2bbc commit 4957aa3

File tree

3 files changed

+4
-25
lines changed

3 files changed

+4
-25
lines changed

go/private/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ bzl_library(
6464
"@bazel_skylib//rules:common_settings",
6565
"@bazel_tools//tools/build_defs/cc:action_names.bzl",
6666
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
67-
"@io_bazel_rules_go_bazel_features//:features",
6867
"@io_bazel_rules_nogo//:scope.bzl",
6968
],
7069
)

go/private/context.bzl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ load(
3434
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
3535
"find_cpp_toolchain",
3636
)
37-
load("@io_bazel_rules_go_bazel_features//:features.bzl", "bazel_features")
3837
load(
3938
"@io_bazel_rules_nogo//:scope.bzl",
4039
NOGO_EXCLUDES = "EXCLUDES",
@@ -707,10 +706,7 @@ def _cgo_context_data_impl(ctx):
707706
# toolchain (to be inputs into actions that need it).
708707
# ctx.files._cc_toolchain won't work when cc toolchain resolution
709708
# is switched on.
710-
if bazel_features.cc.find_cpp_toolchain_has_mandatory_param:
711-
cc_toolchain = find_cpp_toolchain(ctx, mandatory = False)
712-
else:
713-
cc_toolchain = find_cpp_toolchain(ctx)
709+
cc_toolchain = find_cpp_toolchain(ctx, mandatory = False)
714710
if not cc_toolchain or cc_toolchain.compiler in _UNSUPPORTED_C_COMPILERS:
715711
return []
716712

@@ -924,7 +920,7 @@ def _cgo_context_data_impl(ctx):
924920
cgo_context_data = rule(
925921
implementation = _cgo_context_data_impl,
926922
attrs = {
927-
"_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"),
923+
"_cc_toolchain": attr.label(default = "@bazel_tools//tools/cpp:optional_current_cc_toolchain"),
928924
"_xcode_config": attr.label(
929925
default = "@bazel_tools//tools/osx:current_xcode_config",
930926
),
@@ -933,8 +929,7 @@ cgo_context_data = rule(
933929
# In pure mode, a C++ toolchain isn't needed when transitioning.
934930
# But if we declare a mandatory toolchain dependency here, a cross-compiling C++ toolchain is required at toolchain resolution time.
935931
# So we make this toolchain dependency optional, so that it's only attempted to be looked up if it's actually needed.
936-
# Optional toolchain support was added in bazel 6.0.0.
937-
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",
932+
config_common.toolchain_type("@bazel_tools//tools/cpp:toolchain_type", mandatory = False),
938933
],
939934
fragments = ["apple", "cpp"],
940935
doc = """Collects information about the C/C++ toolchain. The C/C++ toolchain

go/private/polyfill_bazel_features.bzl

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
# 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.
66

77
_POLYFILL_BAZEL_FEATURES = """bazel_features = struct(
8-
cc = struct(
9-
find_cpp_toolchain_has_mandatory_param = {find_cpp_toolchain_has_mandatory_param},
10-
),
118
external_deps = struct(
129
# WORKSPACE users have no use for bazel mod tidy.
1310
bazel_mod_tidy = False,
@@ -16,16 +13,6 @@ _POLYFILL_BAZEL_FEATURES = """bazel_features = struct(
1613
"""
1714

1815
def _polyfill_bazel_features_impl(rctx):
19-
# An empty string is treated as a "dev version", which is greater than anything.
20-
bazel_version = native.bazel_version or "999999.999999.999999"
21-
version_parts = bazel_version.split("-")[0].split(".")
22-
if len(version_parts) != 3:
23-
fail("invalid Bazel version '{}': got {} dot-separated segments, want 3".format(bazel_version, len(version_parts)))
24-
major_version_int = int(version_parts[0])
25-
minor_version_int = int(version_parts[1])
26-
27-
find_cpp_toolchain_has_mandatory_param = major_version_int > 6 or (major_version_int == 6 and minor_version_int >= 1)
28-
2916
rctx.file("BUILD.bazel", """
3017
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
3118
bzl_library(
@@ -35,9 +22,7 @@ bzl_library(
3522
)
3623
exports_files(["features.bzl"])
3724
""")
38-
rctx.file("features.bzl", _POLYFILL_BAZEL_FEATURES.format(
39-
find_cpp_toolchain_has_mandatory_param = repr(find_cpp_toolchain_has_mandatory_param),
40-
))
25+
rctx.file("features.bzl", _POLYFILL_BAZEL_FEATURES)
4126

4227
polyfill_bazel_features = repository_rule(
4328
implementation = _polyfill_bazel_features_impl,

0 commit comments

Comments
 (0)