From fa02f768e3a793195e62ad70f9694106b893b0f3 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Mon, 13 Jan 2025 12:22:55 -0800 Subject: [PATCH] Remove reference to cc_proto_aspect The symbol has been removed from Bazel 8, so any reference to it results in an error. Using bazel_features, a bzl file with a reference is generated, based on Bazel version. Protobuf 29.x doesn't have this problem because cc_proto_aspect wasn't exposed. But we should still cherry-pick exposing the aspect and this change to 29.x line, to make transition of rules_rust easier. Closes: https://github.com/protocolbuffers/protobuf/pull/19576 PiperOrigin-RevId: 715064854 --- MODULE.bazel | 2 +- bazel/private/cc_proto_aspect.bzl | 5 +++-- bazel/private/native.bzl | 2 -- bazel/private/proto_bazel_features.bzl | 5 ++++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index 74a215ac5f564..7c51a049461e6 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -27,7 +27,7 @@ bazel_dep(name = "rules_python", version = "0.28.0") bazel_dep(name = "rules_rust", version = "0.51.0") bazel_dep(name = "platforms", version = "0.0.8") bazel_dep(name = "zlib", version = "1.3.1") -bazel_dep(name = "bazel_features", version = "1.17.0", repo_name = "proto_bazel_features") +bazel_dep(name = "bazel_features", version = "1.23.0", repo_name = "proto_bazel_features") bazel_dep( name = "rules_shell", version = "0.2.0", diff --git a/bazel/private/cc_proto_aspect.bzl b/bazel/private/cc_proto_aspect.bzl index ebe473572b6fe..a05fbae6c776d 100644 --- a/bazel/private/cc_proto_aspect.bzl +++ b/bazel/private/cc_proto_aspect.bzl @@ -1,6 +1,7 @@ """Exposes cc_proto_aspect to rules_rust""" +load("@proto_bazel_features//:features.bzl", "bazel_features") load("//bazel/private:bazel_cc_proto_library.bzl", _cc_proto_aspect = "cc_proto_aspect") # buildifier: disable=bzl-visibility -load("//bazel/private:native.bzl", _native_cc_proto_aspect = "native_cc_proto_aspect") # buildifier: disable=bzl-visibility -cc_proto_aspect = _cc_proto_aspect if not hasattr(native, "cc_proto_library") else _native_cc_proto_aspect +# This resolves to Starlark cc_proto_aspect in Bazel 8 or with --incompatible_enable_autoload flag +cc_proto_aspect = getattr(bazel_features.globals, "cc_proto_aspect", None) or _cc_proto_aspect diff --git a/bazel/private/native.bzl b/bazel/private/native.bzl index 51a55f9f77553..87d980c624849 100644 --- a/bazel/private/native.bzl +++ b/bazel/private/native.bzl @@ -1,5 +1,3 @@ """Renames toplevel symbols so they can be exported in Starlark under the same name""" native_proto_common = proto_common_do_not_use - -native_cc_proto_aspect = cc_proto_aspect diff --git a/bazel/private/proto_bazel_features.bzl b/bazel/private/proto_bazel_features.bzl index f839a10c5fd4c..a295b8a348181 100644 --- a/bazel/private/proto_bazel_features.bzl +++ b/bazel/private/proto_bazel_features.bzl @@ -16,7 +16,8 @@ _PROTO_BAZEL_FEATURES = """bazel_features = struct( ), globals = struct( PackageSpecificationInfo = {PackageSpecificationInfo}, - ProtoInfo = getattr(getattr(native, 'legacy_globals', None), 'ProtoInfo', {ProtoInfo}) + ProtoInfo = getattr(getattr(native, 'legacy_globals', None), 'ProtoInfo', {ProtoInfo}), + cc_proto_aspect = getattr(getattr(native, 'legacy_globals', None), 'cc_proto_aspect', {cc_proto_aspect}), ), ) """ @@ -35,6 +36,7 @@ def _proto_bazel_features_impl(rctx): protobuf_on_allowlist = major_version_int > 7 ProtoInfo = "ProtoInfo" if major_version_int < 8 else "None" + cc_proto_aspect = "cc_proto_aspect" if major_version_int < 8 else "None" rctx.file("BUILD.bazel", """ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") @@ -50,6 +52,7 @@ exports_files(["features.bzl"]) PackageSpecificationInfo = "PackageSpecificationInfo" if PackageSpecificationInfo else "None", protobuf_on_allowlist = repr(protobuf_on_allowlist), ProtoInfo = ProtoInfo, + cc_proto_aspect = cc_proto_aspect, )) proto_bazel_features = repository_rule(