-
-
Notifications
You must be signed in to change notification settings - Fork 678
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also switch from @bazel_tools//tools/cpp:current_cc_toolchain to @bazel_tools//tools/cpp:optional_current_cc_toolchain because otherwise we still get a hard error if the toolchain can't be found.
- Loading branch information
1 parent
9751277
commit 4e457d5
Showing
4 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# bazel_features when used from a WORKSPACE rather than bzlmod context requires a two-step set-up (loading bazel_features, then calling a function from inside it). | ||
# rules_go only has one-step set-up, and it would be a breaking change to require a second step. | ||
# Accordingly, we supply a fake implementation of bazel_features which is only used when using rules_go from a WORKSPACE file, | ||
# to avoid complicating code in rules_go itself. | ||
# 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. | ||
|
||
_FAKE_BAZEL_FEATURES = """bazel_features = struct( | ||
cc = struct( | ||
find_cpp_toolchain_has_mandatory_param = {find_cpp_toolchain_has_mandatory_param}, | ||
) | ||
) | ||
""" | ||
|
||
def _fake_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(".") | ||
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", """exports_files(["features.bzl"]) | ||
""") | ||
rctx.file("features.bzl", _FAKE_BAZEL_FEATURES.format( | ||
find_cpp_toolchain_has_mandatory_param = repr(find_cpp_toolchain_has_mandatory_param), | ||
)) | ||
|
||
fake_bazel_features = repository_rule( | ||
implementation = _fake_bazel_features_impl, | ||
# Force reruns on server restarts to keep native.bazel_version up-to-date. | ||
local = True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters