diff --git a/.bazelci/presubmit.yml b/.bazelci/presubmit.yml index d500c05cd..0714d0280 100644 --- a/.bazelci/presubmit.yml +++ b/.bazelci/presubmit.yml @@ -8,7 +8,7 @@ tasks: ubuntu2204: name: Ubuntu 22.04 with WORKSPACE platform: ubuntu2204 - bazel: 7.0.2 + bazel: 7.1.1 build_flags: - "--noexperimental_enable_bzlmod" test_flags: @@ -24,7 +24,7 @@ tasks: ubuntu2204_bzlmod: name: Ubuntu 22.04 with Bzlmod platform: ubuntu2204 - bazel: 7.0.2 + bazel: 7.1.1 build_targets: - "..." run_targets: @@ -84,7 +84,7 @@ tasks: macos_arm64_bzlmod: name: Mac OS Arm 64 with Bzlmod platform: macos_arm64 - bazel: 7.0.2 + bazel: 7.1.1 build_targets: - "..." test_targets: @@ -94,7 +94,7 @@ tasks: macos_arm64: name: Mac OS Arm 64 with WORKSPACE platform: macos_arm64 - bazel: 7.0.2 + bazel: 7.1.1 build_flags: - "--noexperimental_enable_bzlmod" test_flags: @@ -106,7 +106,7 @@ tasks: macos_bzlmod: name: Mac OS with Bzlmod platform: macos - bazel: 7.0.2 + bazel: 7.1.1 build_targets: - "..." test_targets: @@ -116,7 +116,7 @@ tasks: macos: name: Mac OS with WORKSPACE platform: macos - bazel: 7.0.2 + bazel: 7.1.1 build_flags: - "--noexperimental_enable_bzlmod" test_flags: @@ -128,7 +128,7 @@ tasks: windows_bzlmod: name: Windows with Bzlmod platform: windows - bazel: 7.0.2 + bazel: 7.1.1 build_targets: - "--" - "..." @@ -152,7 +152,7 @@ tasks: windows: name: Windows with WORKSPACE platform: windows - bazel: 7.0.2 + bazel: 7.1.1 build_flags: - "--noexperimental_enable_bzlmod" test_flags: @@ -179,7 +179,7 @@ tasks: incompatible: name: Ubuntu 22.04 with WORKSPACE and --config=incompatible platform: ubuntu2204 - bazel: 7.0.2 + bazel: 7.1.1 build_flags: - "--noexperimental_enable_bzlmod" - "--config=incompatible" diff --git a/.bazelversion b/.bazelversion index a8907c025..21c8c7b46 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.0.2 +7.1.1 diff --git a/MODULE.bazel b/MODULE.bazel index ba9c3c66b..cf81b6ea2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -4,7 +4,7 @@ module( repo_name = "bazel_gazelle", ) -bazel_dep(name = "bazel_features", version = "1.9.0") +bazel_dep(name = "bazel_features", version = "1.9.1") bazel_dep(name = "bazel_skylib", version = "1.5.0") bazel_dep(name = "protobuf", version = "3.19.6", repo_name = "com_google_protobuf") bazel_dep(name = "rules_go", version = "0.44.0", repo_name = "io_bazel_rules_go") diff --git a/WORKSPACE b/WORKSPACE index f40c89f52..bfbabf6f4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,20 +15,32 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "io_bazel_rules_go", - integrity = "sha256-fHbWI2so/2laoozzX5XeMXqUcv0fsUrHl8m/aE8Js3w=", + sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip", - "https://github.com/bazelbuild/rules_go/releases/download/v0.44.2/rules_go-v0.44.2.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.46.0/rules_go-v0.46.0.zip", ], ) +# TODO: The rules_go bazel_features shim doesn't provide targets for .bzl files. +http_archive( + name = "bazel_features", + sha256 = "d7787da289a7fb497352211ad200ec9f698822a9e0757a4976fd9f713ff372b3", + strip_prefix = "bazel_features-1.9.1", + url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.9.1/bazel_features-v1.9.1.tar.gz", +) + +load("@bazel_features//:deps.bzl", "bazel_features_deps") + +bazel_features_deps() + load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") go_rules_dependencies() go_register_toolchains( nogo = "@bazel_gazelle//:nogo", - version = "1.21.3", + version = "1.22.0", ) load("//:deps.bzl", "gazelle_dependencies") diff --git a/internal/bzlmod/BUILD.bazel b/internal/bzlmod/BUILD.bazel index 16528376b..2bac102aa 100644 --- a/internal/bzlmod/BUILD.bazel +++ b/internal/bzlmod/BUILD.bazel @@ -53,6 +53,7 @@ bzl_library( name = "utils", srcs = ["utils.bzl"], visibility = ["//:__subpackages__"], + deps = ["@bazel_features//:features"], ) bzl_library( diff --git a/internal/bzlmod/go_deps.bzl b/internal/bzlmod/go_deps.bzl index 5dc7d60c2..e0bd42841 100644 --- a/internal/bzlmod/go_deps.bzl +++ b/internal/bzlmod/go_deps.bzl @@ -24,11 +24,11 @@ load(":semver.bzl", "semver") load( ":utils.bzl", "drop_nones", + "extension_metadata", "format_rule_call", "get_directive_value", "with_replaced_or_new_fields", ) -load("@bazel_features//:features.bzl", "bazel_features") visibility("//") @@ -244,14 +244,6 @@ def _process_archive_override(archive_override_tag): patch_strip = archive_override_tag.patch_strip, ) -def _extension_metadata(module_ctx, *, root_module_direct_deps, root_module_direct_dev_deps): - if not hasattr(module_ctx, "extension_metadata"): - return None - return module_ctx.extension_metadata( - root_module_direct_deps = root_module_direct_deps, - root_module_direct_dev_deps = root_module_direct_dev_deps, - ) - def _go_repository_config_impl(ctx): repos = [] for name, importpath in sorted(ctx.attr.importpaths.items()): @@ -569,10 +561,7 @@ def _go_deps_impl(module_ctx): dep_files = dep_files, ) - metadata_kwargs = {} - if bazel_features.external_deps.extension_metadata_has_reproducible: - metadata_kwargs["reproducible"] = True - return _extension_metadata( + return extension_metadata( module_ctx, root_module_direct_deps = root_module_direct_deps.keys(), # If a Go module appears as both a dev and a non-dev dependency, it has to be imported as a @@ -582,7 +571,7 @@ def _go_deps_impl(module_ctx): for repo_name in root_module_direct_dev_deps.keys() if repo_name not in root_module_direct_deps }.keys(), - **metadata_kwargs + reproducible = True, ) def _get_sum_from_module(path, module, sums): diff --git a/internal/bzlmod/non_module_deps.bzl b/internal/bzlmod/non_module_deps.bzl index 0d3f920e3..1a97eb7ec 100644 --- a/internal/bzlmod/non_module_deps.bzl +++ b/internal/bzlmod/non_module_deps.bzl @@ -24,6 +24,10 @@ load( "//internal:is_bazel_module.bzl", "is_bazel_module", ) +load( + "//internal/bzlmod:utils.bzl", + "extension_metadata", +) load( "@go_host_compatible_sdk_label//:defs.bzl", "HOST_COMPATIBLE_SDK", @@ -35,7 +39,7 @@ load( visibility("//") -def _non_module_deps_impl(_): +def _non_module_deps_impl(module_ctx): go_repository_cache( name = "bazel_gazelle_go_repository_cache", # Label.workspace_name is always a canonical name, so use a canonical label. @@ -50,6 +54,7 @@ def _non_module_deps_impl(_): name = "bazel_gazelle_is_bazel_module", is_bazel_module = True, ) + return extension_metadata(module_ctx, reproducible = True) non_module_deps = module_extension( _non_module_deps_impl, diff --git a/internal/bzlmod/utils.bzl b/internal/bzlmod/utils.bzl index 56ce3b400..53d1cad5f 100644 --- a/internal/bzlmod/utils.bzl +++ b/internal/bzlmod/utils.bzl @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +load("@bazel_features//:features.bzl", "bazel_features") + visibility([ "//tests/bzlmod/...", ]) @@ -116,3 +118,20 @@ def with_replaced_or_new_fields(_struct, **replacements): new_struct_assignments[key] = value return struct(**new_struct_assignments) + +def extension_metadata( + module_ctx, + *, + root_module_direct_deps = None, + root_module_direct_dev_deps = None, + reproducible = False): + if not hasattr(module_ctx, "extension_metadata"): + return None + metadata_kwargs = {} + if bazel_features.external_deps.extension_metadata_has_reproducible: + metadata_kwargs["reproducible"] = reproducible + return module_ctx.extension_metadata( + root_module_direct_deps = root_module_direct_deps, + root_module_direct_dev_deps = root_module_direct_dev_deps, + **metadata_kwargs + )