Skip to content

Commit 8b0eaed

Browse files
authored
revert: upgrade to protobuf 27.0 and remove py_proto_library (bazel-contrib#1933) (bazel-contrib#1948)
This reverts commit d0e25cf. We have the following concerns with the associated change: - `sphinxdocs` is excluded entirely. Because protobuf fails to compile? But why? Protos are needed as part of our docgen, but it is unclear how the docgen is still working. Maybe we can get some clarification here? - The `py_proto_library` tests in the `bzlmod` example are excluded from CI. Because protos also fail to compile? But why? It's an example and should Just Work. - Adding the `copts` needs to be done by all downstream users now. But fixing that in protobuf blocks removing legacy struct providers? I don't understand the connection. Also @alexeagle noted extra [regression](bazel-contrib#1933 (comment)) being caused by the associated PR. Reverting in order to unblock a new release of `rules_python` and then we can work together with @comius on reverting the revert. Reverts bazel-contrib#1933
1 parent 49cdf7d commit 8b0eaed

File tree

18 files changed

+332
-77
lines changed

18 files changed

+332
-77
lines changed

.bazelci/presubmit.yml

+1-52
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,6 @@ 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'
158150
macos:
159151
<<: *reusable_config
160152
name: "Default: MacOS"
@@ -177,39 +169,19 @@ tasks:
177169
# build kite cc toolchain.
178170
- "--extra_toolchains=@buildkite_config//config:cc-toolchain"
179171
- "--build_tag_filters=-docs"
180-
build_targets:
181-
- "--"
182-
- "..."
183-
- '-//sphinxdocs/...' # protobuf compilation fails
184172
test_flags:
185173
- "--test_tag_filters=-integration-test,-acceptance-test,-docs"
186174
# BazelCI sets --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1,
187175
# which prevents cc toolchain autodetection from working correctly
188176
# on Bazel 5.4 and earlier. To workaround this, manually specify the
189177
# build kite cc toolchain.
190178
- "--extra_toolchains=@buildkite_config//config:cc-toolchain"
191-
test_targets:
192-
- "--"
193-
- "..."
194-
- '-//sphinxdocs/...' # protobuf compilation fails
195179
rbe:
196180
<<: *reusable_config
197181
name: "RBE: Ubuntu"
198182
platform: rbe_ubuntu1604
199-
build_flags:
200-
- "--build_tag_filters=-docs"
201-
build_targets:
202-
- "--"
203-
- "..."
204-
- '-//sphinxdocs/...' # protobuf compilation fails
205-
- '-//docs/...'
206183
test_flags:
207-
- "--test_tag_filters=-integration-test,-acceptance-test,-docs"
208-
test_targets:
209-
- "--"
210-
- "..."
211-
- '-//sphinxdocs/...' # protobuf compilation fails
212-
- '-//docs/...'
184+
- "--test_tag_filters=-integration-test,-acceptance-test"
213185

214186
integration_test_build_file_generation_ubuntu_minimum_supported_workspace:
215187
<<: *minimum_supported_version
@@ -262,21 +234,6 @@ tasks:
262234
name: "examples/bzlmod: Debian"
263235
working_directory: examples/bzlmod
264236
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/..."
280237
integration_test_bzlmod_macos:
281238
<<: *reusable_build_test_all
282239
<<: *coverage_targets_example_bzlmod
@@ -438,14 +395,6 @@ tasks:
438395
name: "examples/py_proto_library: Debian, workspace"
439396
working_directory: examples/py_proto_library
440397
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'
449398
integration_test_py_proto_library_macos_workspace:
450399
<<: *reusable_build_test_all
451400
<<: *common_workspace_flags

CHANGELOG.md

-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ 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.
3128
* (deps) Upgrade the `pip_install` dependencies to pick up a new version of pip.
3229
* (toolchains) Optional toolchain dependency: `py_binary`, `py_test`, and
3330
`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-
# 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")
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")
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,3 +148,9 @@ 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,3 +55,8 @@ 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

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ 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+
1417
# (py_proto_library specific) Add the protobuf library for well-known types (e.g. `Any`, `Timestamp`, etc)
15-
bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf")
18+
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
1619

1720
# We next initialize the python toolchain using the extension.
1821
# 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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2-
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@rules_python//python:proto.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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2-
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@rules_python//python:proto.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "pricetag_proto_py_pb2",

examples/py_proto_library/WORKSPACE

+16-3
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,24 @@ 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+
2740
http_archive(
2841
name = "com_google_protobuf",
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"],
42+
sha256 = "4fc5ff1b2c339fb86cd3a25f0b5311478ab081e65ad258c6789359cd84d421f8",
43+
strip_prefix = "protobuf-26.1",
44+
urls = ["https://github.com/protocolbuffers/protobuf/archive/v26.1.tar.gz"],
3245
)
3346

3447
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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2-
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@rules_python//python:proto.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("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
2-
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
1+
load("@rules_proto//proto:defs.bzl", "proto_library")
2+
load("@rules_python//python:proto.bzl", "py_proto_library")
33

44
py_proto_library(
55
name = "pricetag_proto_py_pb2",

internal_deps.bzl

+11-3
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,20 @@ 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+
167174
http_archive(
168175
name = "com_google_protobuf",
169-
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
170-
strip_prefix = "protobuf-27.0",
176+
sha256 = "75be42bd736f4df6d702a0e4e4d30de9ee40eac024c4b845d17ae4cc831fe4ae",
177+
strip_prefix = "protobuf-21.7",
171178
urls = [
172-
"https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
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",
173181
],
174182
)
175183

internal_setup.bzl

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ 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")
2324
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
2425
load("//python/pip_install:repositories.bzl", "pip_install_dependencies")
2526
load("//python/private:internal_config_repo.bzl", "internal_config_repo") # buildifier: disable=bzl-visibility
@@ -34,6 +35,9 @@ def rules_python_internal_setup():
3435

3536
bazel_skylib_workspace()
3637

38+
rules_proto_dependencies()
39+
rules_proto_toolchains()
40+
3741
protobuf_deps()
3842

3943
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-
"@com_google_protobuf//bazel:py_proto_library_bzl",
116+
"//python/private/proto:py_proto_library_bzl",
117117
],
118118
)
119119

python/private/BUILD.bazel

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

python/private/proto/BUILD.bazel

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright 2022 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
16+
load("@rules_proto//proto:defs.bzl", "proto_lang_toolchain")
17+
18+
package(default_visibility = ["//visibility:private"])
19+
20+
licenses(["notice"])
21+
22+
filegroup(
23+
name = "distribution",
24+
srcs = glob(["**"]),
25+
visibility = ["//python/private:__pkg__"],
26+
)
27+
28+
bzl_library(
29+
name = "py_proto_library_bzl",
30+
srcs = ["py_proto_library.bzl"],
31+
visibility = ["//python:__pkg__"],
32+
deps = [
33+
"//python:defs_bzl",
34+
"@rules_proto//proto:defs",
35+
],
36+
)
37+
38+
proto_lang_toolchain(
39+
name = "python_toolchain",
40+
command_line = "--python_out=%s",
41+
progress_message = "Generating Python proto_library %{label}",
42+
runtime = "@com_google_protobuf//:protobuf_python",
43+
# NOTE: This isn't *actually* public. It's an implicit dependency of py_proto_library,
44+
# so must be public so user usages of the rule can reference it.
45+
visibility = ["//visibility:public"],
46+
)

0 commit comments

Comments
 (0)