...

Text file src/github.com/bazelbuild/rules_go/go/private/polyfill_bazel_features.bzl

Documentation: github.com/bazelbuild/rules_go/go/private

     1# 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).
     2# rules_go only has one-step set-up, and it would be a breaking change to require a second step.
     3# Accordingly, we supply a polyfill implementation of bazel_features which is only used when using rules_go from a WORKSPACE file,
     4# to avoid complicating code in rules_go itself.
     5# 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.
     6
     7_POLYFILL_BAZEL_FEATURES = """bazel_features = struct(
     8  cc = struct(
     9    find_cpp_toolchain_has_mandatory_param = {find_cpp_toolchain_has_mandatory_param},
    10  )
    11)
    12"""
    13
    14def _polyfill_bazel_features_impl(rctx):
    15    # An empty string is treated as a "dev version", which is greater than anything.
    16    bazel_version = native.bazel_version or "999999.999999.999999"
    17    version_parts = bazel_version.split("-")[0].split(".")
    18    if len(version_parts) != 3:
    19        fail("invalid Bazel version '{}': got {} dot-separated segments, want 3".format(bazel_version, len(version_parts)))
    20    major_version_int = int(version_parts[0])
    21    minor_version_int = int(version_parts[1])
    22
    23    find_cpp_toolchain_has_mandatory_param = major_version_int > 6 or (major_version_int == 6 and minor_version_int >= 1)
    24
    25    rctx.file("BUILD.bazel", """exports_files(["features.bzl"])
    26""")
    27    rctx.file("features.bzl", _POLYFILL_BAZEL_FEATURES.format(
    28        find_cpp_toolchain_has_mandatory_param = repr(find_cpp_toolchain_has_mandatory_param),
    29    ))
    30
    31polyfill_bazel_features = repository_rule(
    32    implementation = _polyfill_bazel_features_impl,
    33    # Force reruns on server restarts to keep native.bazel_version up-to-date.
    34    local = True,
    35)

View as plain text