Skip to content

Commit d0e25cf

Browse files
authored
feat: Upgrade to protobuf 27.0 and remove py_proto_library (#1933)
Protobuf team is taking ownership of `py_proto_library` and the implementation was moved to protobuf repository. Remove py_proto_library from rules_python, to prevent divergent implementations. Make a redirect with a deprecation warning, so that this doesn't break any users. Expected side effect of this change is also that the protobuf version is sufficiently updated that there is no more use of legacy struct providers. Closes #1935 Closes #1924 Closes #1925 Closes #1703 Closes #1707 Closes #1597 Closes #1293 Closes #1080 Fixes #1438
1 parent ae1e1a0 commit d0e25cf

File tree

18 files changed

+77
-332
lines changed

18 files changed

+77
-332
lines changed

.bazelci/presubmit.yml

+52-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ tasks:
147147
<<: *reusable_config
148148
name: "Default: Debian"
149149
platform: debian11
150+
build_flags:
151+
# For protobuf compilation
152+
- '--host_copt=-Wno-deprecated-declarations'
153+
- '--copt=-Wno-deprecated-declarations'
154+
test_flags:
155+
# For protobuf compilation
156+
- '--host_copt=-Wno-deprecated-declarations'
157+
- '--copt=-Wno-deprecated-declarations'
150158
macos:
151159
<<: *reusable_config
152160
name: "Default: MacOS"
@@ -169,19 +177,39 @@ tasks:
169177
# build kite cc toolchain.
170178
- "--extra_toolchains=@buildkite_config//config:cc-toolchain"
171179
- "--build_tag_filters=-docs"
180+
build_targets:
181+
- "--"
182+
- "..."
183+
- '-//sphinxdocs/...' # protobuf compilation fails
172184
test_flags:
173185
- "--test_tag_filters=-integration-test,-acceptance-test,-docs"
174186
# BazelCI sets --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1,
175187
# which prevents cc toolchain autodetection from working correctly
176188
# on Bazel 5.4 and earlier. To workaround this, manually specify the
177189
# build kite cc toolchain.
178190
- "--extra_toolchains=@buildkite_config//config:cc-toolchain"
191+
test_targets:
192+
- "--"
193+
- "..."
194+
- '-//sphinxdocs/...' # protobuf compilation fails
179195
rbe:
180196
<<: *reusable_config
181197
name: "RBE: Ubuntu"
182198
platform: rbe_ubuntu1604
199+
build_flags:
200+
- "--build_tag_filters=-docs"
201+
build_targets:
202+
- "--"
203+
- "..."
204+
- '-//sphinxdocs/...' # protobuf compilation fails
205+
- '-//docs/...'
183206
test_flags:
184-
- "--test_tag_filters=-integration-test,-acceptance-test"
207+
- "--test_tag_filters=-integration-test,-acceptance-test,-docs"
208+
test_targets:
209+
- "--"
210+
- "..."
211+
- '-//sphinxdocs/...' # protobuf compilation fails
212+
- '-//docs/...'
185213

186214
integration_test_build_file_generation_ubuntu_minimum_supported_workspace:
187215
<<: *minimum_supported_version
@@ -234,6 +262,21 @@ tasks:
234262
name: "examples/bzlmod: Debian"
235263
working_directory: examples/bzlmod
236264
platform: debian11
265+
build_targets:
266+
# For protobuf compilation
267+
- "--"
268+
- "..."
269+
- "-//py_proto_library/..."
270+
test_targets:
271+
# For protobuf compilation
272+
- "--"
273+
- "..."
274+
- "-//py_proto_library/..."
275+
coverage_targets:
276+
# For protobuf compilation
277+
- "--"
278+
- "..."
279+
- "-//py_proto_library/..."
237280
integration_test_bzlmod_macos:
238281
<<: *reusable_build_test_all
239282
<<: *coverage_targets_example_bzlmod
@@ -395,6 +438,14 @@ tasks:
395438
name: "examples/py_proto_library: Debian, workspace"
396439
working_directory: examples/py_proto_library
397440
platform: debian11
441+
build_flags:
442+
# For protobuf compilation
443+
- '--host_copt=-Wno-deprecated-declarations'
444+
- '--copt=-Wno-deprecated-declarations'
445+
test_flags:
446+
# For protobuf compilation
447+
- '--host_copt=-Wno-deprecated-declarations'
448+
- '--copt=-Wno-deprecated-declarations'
398449
integration_test_py_proto_library_macos_workspace:
399450
<<: *reusable_build_test_all
400451
<<: *common_workspace_flags

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ A brief description of the categories of changes:
2525
[x.x.x]: https://github.com/bazelbuild/rules_python/releases/tag/x.x.x
2626

2727
### Changed
28+
* (rules) `py_proto_library` is deprecated in favour of the
29+
implementation in https://github.com/protocolbuffers/protobuf. It will be
30+
removed in the future release.
2831
* (deps) Upgrade the `pip_install` dependencies to pick up a new version of pip.
2932
* (toolchains) Optional toolchain dependency: `py_binary`, `py_test`, and
3033
`py_library` now depend on the `//python:exec_tools_toolchain_type` for build

MODULE.bazel

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ bazel_dep(name = "bazel_skylib", version = "1.6.1")
99
bazel_dep(name = "rules_cc", version = "0.0.9")
1010
bazel_dep(name = "platforms", version = "0.0.4")
1111

12-
# Those are loaded only when using py_proto_library
13-
bazel_dep(name = "rules_proto", version = "6.0.0-rc1")
14-
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
12+
# For backwards compatibility, those are loaded only when using py_proto_library
13+
# Use py_proto_library directly from protobuf repository
14+
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
1515

1616
internal_deps = use_extension("//python/private/bzlmod:internal_deps.bzl", "internal_deps")
1717
use_repo(

WORKSPACE

-6
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,3 @@ http_file(
148148
"https://files.pythonhosted.org/packages/50/67/3e966d99a07d60a21a21d7ec016e9e4c2642a86fea251ec68677daf71d4d/numpy-1.25.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl",
149149
],
150150
)
151-
152-
# rules_proto expects //external:python_headers to point at the python headers.
153-
bind(
154-
name = "python_headers",
155-
actual = "//python/cc:current_py_cc_headers",
156-
)

WORKSPACE.bzlmod

-5
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,3 @@ http_file(
5555
],
5656
)
5757

58-
# rules_proto expects //external:python_headers to point at the python headers.
59-
bind(
60-
name = "python_headers",
61-
actual = "//python/cc:current_py_cc_headers",
62-
)

examples/bzlmod/MODULE.bazel

+1-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ local_path_override(
1111
path = "../..",
1212
)
1313

14-
# (py_proto_library specific) We are using rules_proto to define rules_proto targets to be consumed by py_proto_library.
15-
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
16-
1714
# (py_proto_library specific) Add the protobuf library for well-known types (e.g. `Any`, `Timestamp`, etc)
18-
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
15+
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
1916

2017
# We next initialize the python toolchain using the extension.
2118
# You can set different Python versions in this block.

examples/bzlmod/py_proto_library/example.com/another_proto/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_proto//proto:defs.bzl", "proto_library")
2-
load("@rules_python//python:proto.bzl", "py_proto_library")
1+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "message_proto_py_pb2",

examples/bzlmod/py_proto_library/example.com/proto/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_proto//proto:defs.bzl", "proto_library")
2-
load("@rules_python//python:proto.bzl", "py_proto_library")
1+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "pricetag_proto_py_pb2",

examples/py_proto_library/WORKSPACE

+3-16
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,11 @@ python_register_toolchains(
2424
# Then we need to setup dependencies in order to use py_proto_library
2525
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
2626

27-
http_archive(
28-
name = "rules_proto",
29-
sha256 = "904a8097fae42a690c8e08d805210e40cccb069f5f9a0f6727cf4faa7bed2c9c",
30-
strip_prefix = "rules_proto-6.0.0-rc1",
31-
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0-rc1/rules_proto-6.0.0-rc1.tar.gz",
32-
)
33-
34-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
35-
36-
rules_proto_dependencies()
37-
38-
rules_proto_toolchains()
39-
4027
http_archive(
4128
name = "com_google_protobuf",
42-
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
43-
strip_prefix = "protobuf-26.1",
44-
urls = ["https://github.com/protocolbuffers/protobuf/archive/v26.1.tar.gz"],
29+
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
30+
strip_prefix = "protobuf-27.0",
31+
urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz"],
4532
)
4633

4734
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

examples/py_proto_library/example.com/another_proto/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_proto//proto:defs.bzl", "proto_library")
2-
load("@rules_python//python:proto.bzl", "py_proto_library")
1+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "message_proto_py_pb2",

examples/py_proto_library/example.com/proto/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
load("@rules_proto//proto:defs.bzl", "proto_library")
2-
load("@rules_python//python:proto.bzl", "py_proto_library")
1+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2+
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "pricetag_proto_py_pb2",

internal_deps.bzl

+3-11
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,12 @@ def rules_python_internal_deps():
164164
],
165165
)
166166

167-
http_archive(
168-
name = "rules_proto",
169-
sha256 = "904a8097fae42a690c8e08d805210e40cccb069f5f9a0f6727cf4faa7bed2c9c",
170-
strip_prefix = "rules_proto-6.0.0-rc1",
171-
url = "https://github.com/bazelbuild/rules_proto/releases/download/6.0.0-rc1/rules_proto-6.0.0-rc1.tar.gz",
172-
)
173-
174167
http_archive(
175168
name = "com_google_protobuf",
176-
sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae",
177-
strip_prefix = "protobuf-21.7",
169+
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
170+
strip_prefix = "protobuf-27.0",
178171
urls = [
179-
"https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz",
180-
"https://github.com/protocolbuffers/protobuf/archive/v21.7.tar.gz",
172+
"https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
181173
],
182174
)
183175

internal_setup.bzl

-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
2020
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
2121
load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")
2222
load("@rules_bazel_integration_test//bazel_integration_test:repo_defs.bzl", "bazel_binaries")
23-
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
2423
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
2524
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
2625
load("//python/private:internal_config_repo.bzl", "internal_config_repo") # buildifier: disable=bzl-visibility
@@ -35,9 +34,6 @@ def rules_python_internal_setup():
3534

3635
bazel_skylib_workspace()
3736

38-
rules_proto_dependencies()
39-
rules_proto_toolchains()
40-
4137
protobuf_deps()
4238

4339
bazel_integration_test_rules_dependencies()

python/BUILD.bazel

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ bzl_library(
113113
],
114114
visibility = ["//visibility:public"],
115115
deps = [
116-
"//python/private/proto:py_proto_library_bzl",
116+
"@com_google_protobuf//bazel:py_proto_library_bzl",
117117
],
118118
)
119119

python/private/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ filegroup(
2929
srcs = glob(["**"]) + [
3030
"//python/private/bzlmod:distribution",
3131
"//python/private/common:distribution",
32-
"//python/private/proto:distribution",
3332
"//python/private/whl_filegroup:distribution",
3433
"//tools/build_defs/python/private:distribution",
3534
],

python/private/proto/BUILD.bazel

-46
This file was deleted.

0 commit comments

Comments
 (0)