Skip to content

Commit

Permalink
Improve backwards compatibility
Browse files Browse the repository at this point in the history
* Gate `module_ctx.extension_metadata(reproducible = True)` usage behind a `bazel_features` check for compatibility with Bazel 6.
* Use the "well-known" name `com_google_protobuf` instead of `protobuf` with WORKSPACE to avoid missing deps and duplication of protobuf targets.
  • Loading branch information
fmeum committed Oct 12, 2024
1 parent ba3ec91 commit 9400a67
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,17 @@ tasks:
EXP_USE_CQUERY: 1 # Don't build incompatible targets
build_targets: *build_targets_bazel_6
test_targets: *test_targets_bazel_6
ubuntu2004_bazel_6_bzlmod:
name: Ubuntu 20.04 (Bazel 6)
bazel: 6.5.0
platform: ubuntu2004
environment:
EXP_USE_CQUERY: 1 # Don't build incompatible targets
build_flags:
- "--enable_bzlmod"
- "--ignore_dev_dependency"
build_targets: *build_targets_bazel_6
test_targets: *test_targets_bazel_6

ubuntu_rule_based_toolchains:
name: Ubuntu rule-based toolchains
Expand Down
3 changes: 2 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ module(
compatibility_level = 1,
)

bazel_dep(name = "bazel_features", version = "1.18.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "protobuf", version = "27.0")
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")

cc_configure = use_extension("//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains")
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ http_archive(
)

http_archive(
name = "protobuf",
name = "com_google_protobuf",
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
strip_prefix = "protobuf-27.0",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
Expand Down
2 changes: 1 addition & 1 deletion cc/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Starlark rules for building C++ projects."""

load("@protobuf//bazel:cc_proto_library.bzl", _cc_proto_library = "cc_proto_library")
load("@com_google_protobuf//bazel:cc_proto_library.bzl", _cc_proto_library = "cc_proto_library")
load("//cc:cc_binary.bzl", _cc_binary = "cc_binary")
load("//cc:cc_import.bzl", _cc_import = "cc_import")
load("//cc:cc_library.bzl", _cc_library = "cc_library")
Expand Down
5 changes: 4 additions & 1 deletion cc/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
# limitations under the License.
"""Module extension for cc auto configuration."""

load("@bazel_features//:features.bzl", "bazel_features")
load("//cc/private/toolchain:cc_configure.bzl", "cc_autoconf", "cc_autoconf_toolchains")

def _cc_configure_extension_impl(ctx):
cc_autoconf_toolchains(name = "local_config_cc_toolchains")
cc_autoconf(name = "local_config_cc")
return ctx.extension_metadata(reproducible = True)
if bazel_features.external_deps.extension_metadata_has_reproducible:
return ctx.extension_metadata(reproducible = True)
return None

cc_configure_extension = module_extension(implementation = _cc_configure_extension_impl)

0 comments on commit 9400a67

Please sign in to comment.