Skip to content

Commit fa02f76

Browse files
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: #19576 PiperOrigin-RevId: 715064854
1 parent 4a92a1c commit fa02f76

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bazel_dep(name = "rules_python", version = "0.28.0")
2727
bazel_dep(name = "rules_rust", version = "0.51.0")
2828
bazel_dep(name = "platforms", version = "0.0.8")
2929
bazel_dep(name = "zlib", version = "1.3.1")
30-
bazel_dep(name = "bazel_features", version = "1.17.0", repo_name = "proto_bazel_features")
30+
bazel_dep(name = "bazel_features", version = "1.23.0", repo_name = "proto_bazel_features")
3131
bazel_dep(
3232
name = "rules_shell",
3333
version = "0.2.0",

bazel/private/cc_proto_aspect.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Exposes cc_proto_aspect to rules_rust"""
22

3+
load("@proto_bazel_features//:features.bzl", "bazel_features")
34
load("//bazel/private:bazel_cc_proto_library.bzl", _cc_proto_aspect = "cc_proto_aspect") # buildifier: disable=bzl-visibility
4-
load("//bazel/private:native.bzl", _native_cc_proto_aspect = "native_cc_proto_aspect") # buildifier: disable=bzl-visibility
55

6-
cc_proto_aspect = _cc_proto_aspect if not hasattr(native, "cc_proto_library") else _native_cc_proto_aspect
6+
# This resolves to Starlark cc_proto_aspect in Bazel 8 or with --incompatible_enable_autoload flag
7+
cc_proto_aspect = getattr(bazel_features.globals, "cc_proto_aspect", None) or _cc_proto_aspect

bazel/private/native.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
"""Renames toplevel symbols so they can be exported in Starlark under the same name"""
22

33
native_proto_common = proto_common_do_not_use
4-
5-
native_cc_proto_aspect = cc_proto_aspect

bazel/private/proto_bazel_features.bzl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ _PROTO_BAZEL_FEATURES = """bazel_features = struct(
1616
),
1717
globals = struct(
1818
PackageSpecificationInfo = {PackageSpecificationInfo},
19-
ProtoInfo = getattr(getattr(native, 'legacy_globals', None), 'ProtoInfo', {ProtoInfo})
19+
ProtoInfo = getattr(getattr(native, 'legacy_globals', None), 'ProtoInfo', {ProtoInfo}),
20+
cc_proto_aspect = getattr(getattr(native, 'legacy_globals', None), 'cc_proto_aspect', {cc_proto_aspect}),
2021
),
2122
)
2223
"""
@@ -35,6 +36,7 @@ def _proto_bazel_features_impl(rctx):
3536

3637
protobuf_on_allowlist = major_version_int > 7
3738
ProtoInfo = "ProtoInfo" if major_version_int < 8 else "None"
39+
cc_proto_aspect = "cc_proto_aspect" if major_version_int < 8 else "None"
3840

3941
rctx.file("BUILD.bazel", """
4042
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
@@ -50,6 +52,7 @@ exports_files(["features.bzl"])
5052
PackageSpecificationInfo = "PackageSpecificationInfo" if PackageSpecificationInfo else "None",
5153
protobuf_on_allowlist = repr(protobuf_on_allowlist),
5254
ProtoInfo = ProtoInfo,
55+
cc_proto_aspect = cc_proto_aspect,
5356
))
5457

5558
proto_bazel_features = repository_rule(

0 commit comments

Comments
 (0)