Skip to content

Commit 1cb12cf

Browse files
committed
fix: Upgrade Protobuf and gRPC in WORKSPACE
1 parent eceea95 commit 1cb12cf

6 files changed

Lines changed: 164 additions & 70 deletions

File tree

.github/workflows/gapic-generator-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ jobs:
219219
# Only runs if the Gatekeeper passed
220220
if: ${{ needs.python_config.result == 'success' }}
221221
runs-on: ubuntu-latest
222-
container: gcr.io/gapic-images/googleapis # zizmor: ignore[unpinned-images]
222+
container:
223+
image: gcr.io/gapic-images/googleapis # zizmor: ignore[unpinned-images]
223224
steps:
224225
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6
225226
with:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# See https://github.com/bazelbuild/bazelisk
2-
USE_BAZEL_VERSION=6.5.0
2+
USE_BAZEL_VERSION=7.7.1

packages/gapic-generator/.bazelrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
# New protobuf requires C++17
22
build --repo_env=BAZEL_CXXOPTS="-std=c++17"
3+
4+
# Workaround for rules_python precompilation bug with directory outputs:
5+
# Newer rules_python (v0.40.0+) attempts to precompile (.py -> .pyc) sources.
6+
# GAPIC code generator rules (e.g., //tests/integration:asset_py_gapic) output a
7+
# directory structure of generated code instead of discrete individual files.
8+
# This triggers: "Error in add: Cannot add directories to Args#add since they may expand to multiple values".
9+
# Disabling precompilation bypasses the bug without affecting runtime behavior.
10+
build --@rules_python//python/config_settings:precompile=force_disabled
11+
12+
# Disable Bzlmod to use legacy WORKSPACE file repository resolution
13+
common --noenable_bzlmod

packages/gapic-generator/WORKSPACE

Lines changed: 99 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,122 +2,157 @@ workspace(name = "gapic_generator_python")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44

5-
_bazel_skylib_version = "1.4.0"
5+
# Load Protobuf 35.1 first to ensure Bazel uses Protobuf 35.1 over older
6+
# transitive versions pulled in by downstream rules (e.g. gRPC or rules_gapic).
7+
_protobuf_version = "35.1"
8+
_protobuf_sha256 = "bf89df2fa0088de9c9890fbfba0076263a36c2f84847a7b54e7e32effd6201c7"
9+
http_archive(
10+
name = "com_google_protobuf",
11+
sha256 = _protobuf_sha256,
12+
strip_prefix = "protobuf-{}".format(_protobuf_version),
13+
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v{0}/protobuf-{0}.zip".format(_protobuf_version)],
14+
)
15+
16+
# Load rules_gapic v1.0.0. We patch rules_gapic's .bzl files to inject the
17+
# explicit load for Starlark ProtoInfo from @rules_proto to maintain symbol
18+
# resolution under rules_proto / Protobuf 35.1.
19+
_rules_gapic_version = "1.0.0"
20+
_rules_gapic_sha256 = "c21e78a42f69898e7c3142fa837e3a637b1993d27c08a64723262611971d2b96"
21+
http_archive(
22+
name = "rules_gapic",
23+
sha256 = _rules_gapic_sha256,
24+
strip_prefix = "rules_gapic-{}".format(_rules_gapic_version),
25+
urls = [
26+
"https://github.com/googleapis/rules_gapic/archive/v{}.tar.gz".format(_rules_gapic_version)
27+
]
28+
)
629

7-
_bazel_skylib_sha256 = "f24ab666394232f834f74d19e2ff142b0af17466ea0c69a3f4c276ee75f6efce"
30+
# Load C++ rules matching modern Protobuf C++ requirements
31+
_rules_cc_version = "0.1.5"
32+
_rules_cc_sha256 = "b8b918a85f9144c01f6cfe0f45e4f2838c7413961a8ff23bc0c6cdf8bb07a3b6"
33+
http_archive(
34+
name = "rules_cc",
35+
sha256 = _rules_cc_sha256,
36+
strip_prefix = "rules_cc-{}".format(_rules_cc_version),
37+
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/{0}/rules_cc-{0}.tar.gz".format(_rules_cc_version)],
38+
)
839

40+
# Load bazel_skylib required by Starlark rules
41+
_bazel_skylib_version = "1.9.0"
42+
_bazel_skylib_sha256 = "3b5b49006181f5f8ff626ef8ddceaa95e9bb8ad294f7b5d7b11ea9f7ddaf8c59"
943
http_archive(
1044
name = "bazel_skylib",
1145
sha256 = _bazel_skylib_sha256,
1246
url = "https://github.com/bazelbuild/bazel-skylib/releases/download/{0}/bazel-skylib-{0}.tar.gz".format(_bazel_skylib_version),
1347
)
1448

49+
# Load Abseil C++ matching Protobuf 35 C++ dependencies
50+
_com_google_absl_version = "20240722.1"
51+
_com_google_absl_sha256 = "40cee67604060a7c8794d931538cb55f4d444073e556980c88b6c49bb9b19bb7"
52+
http_archive(
53+
name = "com_google_absl",
54+
sha256 = _com_google_absl_sha256,
55+
strip_prefix = "abseil-cpp-{}".format(_com_google_absl_version),
56+
urls = [
57+
"https://github.com/abseil/abseil-cpp/releases/download/{0}/abseil-cpp-{0}.tar.gz".format(_com_google_absl_version),
58+
],
59+
)
60+
61+
# Load Go rules required for GAPIC plugin building
1562
_io_bazel_rules_go_version = "0.33.0"
63+
_io_bazel_rules_go_sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369"
1664
http_archive(
1765
name = "io_bazel_rules_go",
18-
sha256 = "685052b498b6ddfe562ca7a97736741d87916fe536623afb7da2824c0211c369",
66+
sha256 = _io_bazel_rules_go_sha256,
1967
urls = [
2068
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v{0}/rules_go-v{0}.zip".format(_io_bazel_rules_go_version),
2169
"https://github.com/bazelbuild/rules_go/releases/download/v{0}/rules_go-v{0}.zip".format(_io_bazel_rules_go_version),
2270
],
2371
)
2472

25-
_rules_python_version = "0.26.0"
26-
27-
_rules_python_sha256 = "9d04041ac92a0985e344235f5d946f71ac543f1b1565f2cdbc9a2aaee8adf55b"
28-
73+
# Upgraded to rules_python 1.1.0 for modern C-extension toolchain support.
74+
_rules_python_version = "1.1.0"
75+
_rules_python_sha256 = "9c6e26911a79fbf510a8f06d8eedb40f412023cf7fa6d1461def27116bff022c"
2976
http_archive(
3077
name = "rules_python",
3178
sha256 = _rules_python_sha256,
3279
strip_prefix = "rules_python-{}".format(_rules_python_version),
33-
url = "https://github.com/bazelbuild/rules_python/archive/{}.tar.gz".format(_rules_python_version),
80+
url = "https://github.com/bazelbuild/rules_python/releases/download/{0}/rules_python-{0}.tar.gz".format(_rules_python_version),
3481
)
3582

36-
load("@rules_python//python:repositories.bzl", "py_repositories")
37-
83+
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains")
3884
py_repositories()
3985

40-
load("@rules_python//python:pip.bzl", "pip_parse")
41-
86+
# Register multi-version hermetic Python toolchains (3.10 - 3.13) to ensure
87+
# Bazel can resolve both execution and C-header toolchains for any Python target.
88+
# Set ignore_root_user_error = True so toolchains unpack safely in Docker CI containers (EUID=0).
89+
python_register_multi_toolchains(
90+
name = "python",
91+
ignore_root_user_error = True,
92+
python_versions = [
93+
"3.10",
94+
"3.11",
95+
"3.12",
96+
"3.13",
97+
],
98+
)
4299

100+
load("@rules_python//python:pip.bzl", "pip_parse")
43101
pip_parse(
44102
name = "gapic_generator_python_pip_deps",
45-
requirements_lock = "//:requirements.txt",
103+
requirements_lock = "//:requirements.txt",
46104
)
47-
load("@gapic_generator_python_pip_deps//:requirements.bzl", "install_deps")
48105

106+
load("@gapic_generator_python_pip_deps//:requirements.bzl", "install_deps")
49107
install_deps()
50-
#
51-
# Import gapic-generator-python specific dependencies
52-
#
53-
load(
54-
"//:repositories.bzl",
55-
"gapic_generator_python",
56-
"gapic_generator_register_toolchains",
57-
)
58-
59-
gapic_generator_python()
60-
61-
gapic_generator_register_toolchains()
62-
63-
_grpc_version = "1.71.0"
64-
65-
_grpc_sha256 = "9313c3f8f4dd3341597f152d506a50caf571fe40f886e24ea9078891990df285"
66108

109+
# Load gRPC v1.83.0 with temporary patch for legacy_channel.cc.
110+
# The fix is merged upstream (https://github.com/grpc/grpc/commit/816506e5c0434a42414af6955cc9eef0c562ff3a)
111+
# and this patch is temporary until released in a future gRPC release.
112+
_grpc_version = "1.83.0"
113+
_grpc_sha256 = "876ff5c9c26f364cd603531761268a5b58ccc1479afc78d6dab1d8e839da00c0"
67114
http_archive(
68115
name = "com_github_grpc_grpc",
69116
sha256 = _grpc_sha256,
70-
strip_prefix = "grpc-%s" % _grpc_version,
71-
urls = ["https://github.com/grpc/grpc/archive/v%s.zip" % _grpc_version],
72-
)
73-
# instantiated in grpc_deps().
74-
75-
_protobuf_version = "30.2"
76-
77-
_protobuf_sha256 = "07a43d88fe5a38e434c7f94129cad56a4c43a51f99336074d0799c2f7d4e44c5"
78-
79-
http_archive(
80-
name = "com_google_protobuf",
81-
sha256 = _protobuf_sha256,
82-
strip_prefix = "protobuf-%s" % _protobuf_version,
83-
urls = ["https://github.com/protocolbuffers/protobuf/archive/v%s.tar.gz" % _protobuf_version],
117+
strip_prefix = "grpc-{}".format(_grpc_version),
118+
urls = ["https://github.com/grpc/grpc/archive/v{}.zip".format(_grpc_version)],
119+
patch_cmds = [
120+
"python3 -c \"f='src/core/lib/surface/legacy_channel.cc'; c=open(f).read(); open(f,'w').write(c.replace('args.arena_init_function = arena_init_function;', 'if (arena_init_function.has_value()) { args.arena_init_function.emplace(*arena_init_function); }')) if 'args.arena_init_function = arena_init_function;' in c else None\""
121+
],
84122
)
85123
load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps")
86-
87124
grpc_deps()
88125

89-
http_archive(
90-
name = "rules_cc",
91-
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.1/rules_cc-0.1.1.tar.gz"],
92-
sha256 = "712d77868b3152dd618c4d64faaddefcc5965f90f5de6e6dd1d5ddcd0be82d42",
93-
strip_prefix = "rules_cc-0.1.1",
126+
load(
127+
"//:repositories.bzl",
128+
"gapic_generator_python",
129+
"gapic_generator_register_toolchains",
94130
)
131+
gapic_generator_python()
132+
gapic_generator_register_toolchains()
95133

96-
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps", "PROTOBUF_MAVEN_ARTIFACTS")
97-
# This is actually already done within grpc_deps but calling this for Bazel convention.
98-
protobuf_deps()
99-
100-
# Add rules_java to resolve the following error
101-
# `The repository '@compatibility_proxy' could not be resolved: Repository '@compatibility_proxy' is not defined`
134+
# Add rules_java to resolve compatibility proxy errors
102135
load("@rules_java//java:rules_java_deps.bzl", "rules_java_dependencies")
103-
104136
rules_java_dependencies()
105137

106-
# gRPC enforces a specific version of Go toolchain which conflicts with our build.
107-
# All the relevant parts of grpc_extra_deps() are imported in this WORKSPACE file
108-
# explicitly, that is why we do not call grpc_extra_deps() here and call
109-
# apple_rules_dependencies and apple_support_dependencies macros explicitly.
138+
# Load transitive proto dependencies and register proto toolchains
139+
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
140+
protobuf_deps()
141+
142+
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")
143+
rules_proto_dependencies()
110144

111-
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
145+
load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
146+
rules_proto_toolchains()
112147

148+
# Load platform dependencies
149+
load("@build_bazel_rules_apple//apple:repositories.bzl", "apple_rules_dependencies")
113150
apple_rules_dependencies()
114151

115152
load("@build_bazel_apple_support//lib:repositories.bzl", "apple_support_dependencies")
116-
117153
apple_support_dependencies()
118154

119155
load("@com_google_googleapis//:repository_rules.bzl", "switched_rules_by_language")
120-
121156
switched_rules_by_language(
122157
name = "com_google_googleapis_imports",
123158
gapic = True,

packages/gapic-generator/repositories.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def gapic_generator_python():
1616
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/2169ae1c374aab4a09aa90e65efe1a3aad4e279b.tar.gz"],
1717
)
1818

19-
_grpc_version = "1.47.0"
20-
_grpc_sha256 = "edf25f4db6c841853b7a29d61b0980b516dc31a1b6cdc399bcf24c1446a4a249"
19+
_grpc_version = "1.83.0"
20+
_grpc_sha256 = "876ff5c9c26f364cd603531761268a5b58ccc1479afc78d6dab1d8e839da00c0"
2121
_maybe(
2222
http_archive,
2323
name = "com_github_grpc_grpc",

packages/gapic-generator/rules_python_gapic/py_gapic.bzl

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,39 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
load("@rules_gapic//:gapic.bzl", "proto_custom_library", "unzipped_srcjar")
15+
load("@rules_gapic//:gapic.bzl", "proto_custom_library", "unzipped_srcjar", "CustomProtoInfo")
1616
load("@rules_python//python:defs.bzl", "py_library")
1717
load("@gapic_generator_python_pip_deps//:requirements.bzl", "requirement")
1818

19+
# Load modern rules_proto Starlark ProtoInfo provider.
20+
# Needed because modern rules_proto targets output Starlark ProtoInfo, whereas
21+
# rules_gapic's proto_custom_library expects rules_gapic's CustomProtoInfo provider.
22+
load("@rules_proto//proto:defs.bzl", StarlarkProtoInfo = "ProtoInfo")
23+
24+
# Compatibility adapter rule to convert modern rules_proto Starlark ProtoInfo
25+
# into rules_gapic CustomProtoInfo provider required by proto_custom_library.
26+
def _gapic_compat_proto_library_impl(ctx):
27+
dep = ctx.attr.dep
28+
starlark_proto = dep[StarlarkProtoInfo]
29+
return [
30+
# Construct CustomProtoInfo provider needed by rules_gapic's proto_custom_library.
31+
# Must not return ProtoInfo here so proto_custom_library selects CustomProtoInfo (which has transitive_imports).
32+
CustomProtoInfo(
33+
direct_sources = starlark_proto.direct_sources,
34+
check_deps_sources = starlark_proto.check_deps_sources,
35+
# Map modern transitive_sources to CustomProtoInfo's transitive_imports field
36+
transitive_imports = starlark_proto.transitive_sources,
37+
transitive_descriptor_sets = starlark_proto.transitive_descriptor_sets,
38+
)
39+
]
40+
41+
gapic_compat_proto_library = rule(
42+
implementation = _gapic_compat_proto_library_impl,
43+
attrs = {
44+
"dep": attr.label(mandatory = True, providers = [StarlarkProtoInfo]),
45+
}
46+
)
47+
1948
def _gapic_test_file_impl(ctx):
2049
generated_test_file = ctx.actions.declare_file(ctx.label.name)
2150

@@ -46,6 +75,22 @@ def py_gapic_library(
4675
rest_numeric_enums = False,
4776
deps = [],
4877
**kwargs):
78+
79+
# Dynamically wrap input proto targets with the gapic_compat_proto_library adapter
80+
# to convert modern Starlark ProtoInfo into rules_gapic's expected CustomProtoInfo.
81+
# We extract and propagate 'testonly' from kwargs to prevent Bazel dependency analysis
82+
# errors when py_gapic_library or its input proto targets are marked testonly = True.
83+
testonly = kwargs.get("testonly", None)
84+
compat_srcs = []
85+
for i, src in enumerate(srcs):
86+
compat_name = "%s_compat_src_%d" % (name, i)
87+
gapic_compat_proto_library(
88+
name = compat_name,
89+
dep = src,
90+
testonly = testonly,
91+
)
92+
compat_srcs.append(":%s" % compat_name)
93+
4994
srcjar_target_name = "%s_srcjar" % name
5095
srcjar_output_suffix = ".srcjar"
5196

@@ -67,9 +112,11 @@ def py_gapic_library(
67112
if rest_numeric_enums:
68113
opt_args = opt_args + ["rest-numeric-enums"]
69114

115+
# Point deps to compat_srcs so proto_custom_library receives targets providing
116+
# the CustomProtoInfo provider instead of raw Starlark ProtoInfo targets.
70117
proto_custom_library(
71118
name = srcjar_target_name,
72-
deps = srcs,
119+
deps = compat_srcs,
73120
plugin = Label("@gapic_generator_python//:gapic_plugin"),
74121
plugin_args = plugin_args,
75122
plugin_file_args = file_args,

0 commit comments

Comments
 (0)