Skip to content

Commit 9efe3c2

Browse files
committed
Modernize build files, upgrade Bazel
* Upgrade to Bazel 7 * Upgrade to `rules_proto` 1.0.0 and fix breakage * Upgrade to protobuf 29.5 * Use `py_proto_library` from the protobuf repo, not `rules_proto` (deprecated) * Use `cc_proto_library` from the protobuf repo, not `rules_cc` (deprecated) * Actually run the cpp test in `bazel test` * Remove `repo_mapping` cruft (isn't supported in modern Bazel versions anyway).
1 parent b06983b commit 9efe3c2

9 files changed

Lines changed: 44 additions & 52 deletions

File tree

.bazeliskrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
USE_BAZEL_VERSION=5.4.1
1+
USE_BAZEL_VERSION=7.6.1
2+

.bazelrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
# Use a remote build cache that's world-readable. Don't write unless told otherwise.
1+
# Disable Bazel modules (for now).
2+
common --enable_bzlmod=false
3+
4+
build --cxxopt='-std=c++17'
5+
build --host_cxxopt='-std=c++17'
26

7+
# Use a remote build cache that's world-readable. Don't write unless told otherwise.
38
build --remote_cache=https://storage.googleapis.com/reboot-dev-bazel-remote-cache-reboot-us
49
build --remote_upload_local_results=false
510

611
# Print full test logs for failed tests.
7-
812
test --test_output=errors
13+
14+
# To debug errors using the remote cache we need the `--verbose_failures` flag to
15+
# get any useful information whatsoever.
16+
build --verbose_failures

WORKSPACE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ workspace(name = "com_github_reboot_dev_pyprotoc_plugin")
22

33
load("//bazel:repos.bzl", "repos")
44

5-
repos(external = False)
5+
repos()
66

77
load("//bazel:py_toolchains.bzl", "py_toolchains")
88

bazel/deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
44
load("@pyprotoc_plugin_pypi//:requirements.bzl", pypi_deps = "install_deps")
55

6-
def deps(repo_mapping = {}):
6+
def deps():
77
protobuf_deps()
88

9-
pypi_deps(repo_mapping = repo_mapping)
9+
pypi_deps()

bazel/py_toolchains.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")
44

5-
def py_toolchains(repo_mapping = {}):
5+
def py_toolchains():
66
py_repositories()
77

88
python_register_toolchains(
99
name = "python3_10_12",
1010
python_version = "3.10.12",
11-
repo_mapping = repo_mapping,
1211
)

bazel/pypi_repos.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ should be installed later in WORKSPACE file to be accessible.
33
`pip_parse` takes a `requirements_lock` file as input, which is
44
generated by the `bazel run :requirements.update` command."""
55

6-
load("@python3_10_12//:defs.bzl", "interpreter")
76
load("@rules_python//python:pip.bzl", "pip_parse")
87

98
def pypi_repos():
109
pip_parse(
1110
name = "pyprotoc_plugin_pypi",
12-
python_interpreter_target = interpreter,
11+
python_interpreter_target = "@python3_10_12_host//:python",
1312
requirements_lock = "@com_github_reboot_dev_pyprotoc_plugin//:requirements_lock.txt",
1413
)

bazel/repos.bzl

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,26 @@
99
# instructions at https://github.com/reboot-dev/pyprotoc-plugin.
1010
########################################################################
1111

12-
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
1312
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
13+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
1414

15-
def repos(external = True, repo_mapping = {}):
16-
"""Adds repositories/archives needed by pyprotoc-plugin
15+
def repos():
16+
"""Adds repositories/archives needed by pyprotoc-plugin."""
1717

18-
Args:
19-
external: whether or not we're invoking this function as though
20-
though we're an external dependency
21-
repo_mapping: passed through to all other functions that expect/use
22-
repo_mapping, e.g., 'git_repository'
23-
"""
24-
http_archive(
18+
maybe(
19+
http_archive,
2520
name = "rules_python",
26-
sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31",
27-
strip_prefix = "rules_python-0.27.0",
28-
url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz",
29-
repo_mapping = repo_mapping,
21+
sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07",
22+
strip_prefix = "rules_python-1.0.0",
23+
url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz",
3024
)
3125

32-
if "com_google_protobuf" not in native.existing_rules():
33-
git_repository(
34-
name = "com_google_protobuf",
35-
remote = "https://github.com/protocolbuffers/protobuf",
36-
# Release v3.19.4.
37-
# TODO(codingcanuck): Update to a newer release after
38-
# https://github.com/protocolbuffers/protobuf/issues/9688 is fixed.
39-
commit = "22d0e265de7d2b3d2e9a00d071313502e7d4cccf",
40-
shallow_since = "1643340956 -0800",
41-
repo_mapping = repo_mapping,
42-
)
43-
44-
if external and "com_github_reboot_dev_pyprotoc_plugin" not in native.existing_rules():
45-
git_repository(
46-
name = "com_github_reboot_dev_pyprotoc_plugin",
47-
remote = "https://github.com/reboot-dev/pyprotoc-plugin",
48-
commit = "9f7a281670f03b77140c4437ac2a56b86f978af6",
49-
shallow_since = "1649038239 +0000",
50-
repo_mapping = repo_mapping,
51-
)
26+
maybe(
27+
http_archive,
28+
name = "com_google_protobuf",
29+
sha256 = "955ef3235be41120db4d367be81efe6891c9544b3a71194d80c3055865b26e09",
30+
strip_prefix = "protobuf-29.5",
31+
urls = [
32+
"https://github.com/protocolbuffers/protobuf/archive/v29.5.tar.gz",
33+
],
34+
)

tests/cpp/BUILD.bazel

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "proto_library")
1+
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
2+
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
3+
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
34
load("@rules_python//python:defs.bzl", "py_binary")
45
load(":cpp_rule.bzl", "cc_generate_library")
56

@@ -54,7 +55,7 @@ cc_library(
5455
],
5556
)
5657

57-
cc_binary(
58+
cc_test(
5859
name = "cc_test",
5960
srcs = ["cc_generated_test.cc"],
6061
deps = [

tests/python/BUILD.bazel

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library")
2-
load("@rules_proto//proto:defs.bzl", "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
load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test")
44
load(":sample_rule.bzl", "py_sample_library")
55

66
py_test(
77
name = "library_tests",
8+
size = "small",
89
srcs = [
910
"library_tests.py",
1011
],
@@ -30,7 +31,7 @@ proto_library(
3031

3132
py_proto_library(
3233
name = "sample_messages_py_proto",
33-
srcs = ["sample_messages.proto"],
34+
deps = [":sample_messages_proto"],
3435
)
3536

3637
proto_library(
@@ -41,8 +42,7 @@ proto_library(
4142

4243
py_proto_library(
4344
name = "sample_service_py_proto",
44-
srcs = ["sample_service.proto"],
45-
deps = [":sample_messages_py_proto"],
45+
deps = [":sample_messages_proto"],
4646
)
4747

4848
py_sample_library(
@@ -62,6 +62,7 @@ py_library(
6262

6363
py_test(
6464
name = "sample_generated_library_test",
65+
size = "small",
6566
srcs = [
6667
"sample_generated_library_test.py",
6768
],

0 commit comments

Comments
 (0)