Skip to content

Commit

Permalink
Migrate to Bazel 8, refresh other dependencies
Browse files Browse the repository at this point in the history
Update to Bazel 8 and the latest release of rules-python. Also move
from depending on a Git snapshot of protobuf to the latest release of
rules_proto.

We currently use Bazel 8 but explicitly disable module support and
enable workspace support. Moving to Bazel modules is deferred to
future work.
  • Loading branch information
neilconway committed Dec 21, 2024
1 parent b06983b commit bbf46e3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
USE_BAZEL_VERSION=5.4.1
USE_BAZEL_VERSION=8.0.0
8 changes: 6 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Use a remote build cache that's world-readable. Don't write unless told otherwise.
# TODO: migrate to Bazel modules
common --enable_workspace
common --enable_bzlmod=false

build --verbose_failures

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

# Print full test logs for failed tests.

test --test_output=errors
4 changes: 2 additions & 2 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Dependency specific initialization."""

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@pyprotoc_plugin_pypi//:requirements.bzl", pypi_deps = "install_deps")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

def deps(repo_mapping = {}):
protobuf_deps()
rules_proto_dependencies()

pypi_deps(repo_mapping = repo_mapping)
4 changes: 4 additions & 0 deletions bazel/py_toolchains.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Defines a local python toolchain for use in rules_python."""

load("@rules_proto//proto:toolchains.bzl", "rules_proto_toolchains")
load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_toolchains")

def py_toolchains(repo_mapping = {}):
Expand All @@ -10,3 +11,6 @@ def py_toolchains(repo_mapping = {}):
python_version = "3.10.12",
repo_mapping = repo_mapping,
)

# TODO: not really a Python toolchain?
rules_proto_toolchains()
3 changes: 1 addition & 2 deletions bazel/pypi_repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ should be installed later in WORKSPACE file to be accessible.
`pip_parse` takes a `requirements_lock` file as input, which is
generated by the `bazel run :requirements.update` command."""

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

def pypi_repos():
pip_parse(
name = "pyprotoc_plugin_pypi",
python_interpreter_target = interpreter,
python_interpreter_target = "@python3_10_12_host//:python",
requirements_lock = "@com_github_reboot_dev_pyprotoc_plugin//:requirements_lock.txt",
)
28 changes: 12 additions & 16 deletions bazel/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,26 @@ def repos(external = True, repo_mapping = {}):
"""Adds repositories/archives needed by pyprotoc-plugin
Args:
external: whether or not we're invoking this function as though
though we're an external dependency
external: whether we are invoking this function as though we are
an external dependency
repo_mapping: passed through to all other functions that expect/use
repo_mapping, e.g., 'git_repository'
"""
http_archive(
name = "rules_python",
sha256 = "9acc0944c94adb23fba1c9988b48768b1bacc6583b52a2586895c5b7491e2e31",
strip_prefix = "rules_python-0.27.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.27.0/rules_python-0.27.0.tar.gz",
sha256 = "4f7e2aa1eb9aa722d96498f5ef514f426c1f55161c3c9ae628c857a7128ceb07",
strip_prefix = "rules_python-1.0.0",
url = "https://github.com/bazelbuild/rules_python/releases/download/1.0.0/rules_python-1.0.0.tar.gz",
repo_mapping = repo_mapping,
)

if "com_google_protobuf" not in native.existing_rules():
git_repository(
name = "com_google_protobuf",
remote = "https://github.com/protocolbuffers/protobuf",
# Release v3.19.4.
# TODO(codingcanuck): Update to a newer release after
# https://github.com/protocolbuffers/protobuf/issues/9688 is fixed.
commit = "22d0e265de7d2b3d2e9a00d071313502e7d4cccf",
shallow_since = "1643340956 -0800",
repo_mapping = repo_mapping,
)
http_archive(
name = "rules_proto",
sha256 = "14a225870ab4e91869652cfd69ef2028277fc1dc4910d65d353b62d6e0ae21f4",
strip_prefix = "rules_proto-7.1.0",
url = "https://github.com/bazelbuild/rules_proto/releases/download/7.1.0/rules_proto-7.1.0.tar.gz",
repo_mapping = repo_mapping,
)

if external and "com_github_reboot_dev_pyprotoc_plugin" not in native.existing_rules():
git_repository(
Expand Down
2 changes: 1 addition & 1 deletion rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _protoc_plugin_rule_implementation(context):
else:
fail(
"Handling this type of (generated?) .proto file " +
"was not forseen and is not implemented. " +
"was not foreseen and is not implemented. " +
"Please create an issue at " +
"https://github.com/reboot-dev/pyprotoc-plugin/issues " +
"with your proto file and we will have a look!",
Expand Down
5 changes: 3 additions & 2 deletions tests/cpp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_proto_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@com_google_protobuf//bazel:cc_proto_library.bzl", "cc_proto_library")
load(":cpp_rule.bzl", "cc_generate_library")

py_binary(
Expand Down

0 comments on commit bbf46e3

Please sign in to comment.