Skip to content

Commit

Permalink
fix: use com_google_protobuf in WORKSPACE (#2432)
Browse files Browse the repository at this point in the history
The only way to support both workspace and bzlmod mode, is to call
protobuf com_google_protobuf. This is because old Bazel's encode it in
default values of `--protoco_compiler` flag, and so new Bazel 8 needs to
do the same.

For bzlmod, upgrade rules_cc to 0.0.16 and rules_java (dev dep) to
8.3.1. Those are minimal versions that are also calling protobuf again
com_google_protobuf.

For workspace, upgrade rules_cc to 0.1.0. This is an incompatible
version that doesn't call Protobuf. rules_python users may use it. In
case they need cc_proto_library in `@rules_cc//cc/defs.bzl`, they can
overwrite the version to 0.0.16 in WORKSPACE (or use protobuf_deps that
already does that).

Disable docs generation targets on WORKSPACE CI setups. They are broken
by rules_java upgrade.

Upgrades dependencies:
* rules_cc 0.0.16 (Bzlmod) and rules_cc 0.1.0 (WORKSPACE)
* rules_java 8.3.1
* bazel_skylib 1.7.0 (workspace; bzlmod already specifying that version)
* protobuf 29.0-rc2 (workspace; bzlmod already specifying that version)

Fixes #2429

---------

Co-authored-by: Richard Levasseur <[email protected]>
  • Loading branch information
comius and rickeylev authored Nov 21, 2024
1 parent d73a74f commit e6a6a3a
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 35 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ Unreleased changes template.
bzlmod extension.
* (bzlmod) `pip.parse.parse_all_requirements_files` attribute has been removed.
See notes in the previous versions about what to do.
* (deps) rules_cc 0.1.0 (workspace) and 0.0.16 (bzlmod).
* (deps) protobuf 29.0-rc2 (workspace; bzlmod already specifying that version).

Other changes:
* (python_repository) Start honoring the `strip_prefix` field for `zstd` archives.
* (pypi) {bzl:obj}`pip_parse.extra_hub_aliases` now works in WORKSPACE files.
* (binaries/tests) For {obj}`--bootstrap_impl=script`, a binary-specific (but
otherwise empty) virtual env is used to customize `sys.path` initialization.
* (deps) bazel_skylib 1.7.0 (workspace; bzlmod already specifying that version)

{#v0-0-0-fixed}
### Fixed
Expand All @@ -88,6 +91,8 @@ Other changes:
* (binaries/tests) ({obj}`--bootstrap_impl=scipt`) Using `sys.executable` will
use the same `sys.path` setup as the calling binary.
([2169](https://github.com/bazelbuild/rules_python/issues/2169)).
* (workspace) Corrected protobuf's name to com_google_protobuf, the name is
hardcoded in Bazel, WORKSPACE mode.

{#v0-0-0-added}
### Added
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module(

bazel_dep(name = "bazel_features", version = "1.9.1")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_cc", version = "0.0.14")
bazel_dep(name = "rules_cc", version = "0.0.16")
bazel_dep(name = "platforms", version = "0.0.4")

# Those are loaded only when using py_proto_library
Expand Down
2 changes: 1 addition & 1 deletion docs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ _TARGET_COMPATIBLE_WITH = select({
"@platforms//os:linux": [],
"@platforms//os:macos": [],
"//conditions:default": ["@platforms//:incompatible"],
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
}) if BZLMOD_ENABLED else ["@platforms//:incompatible"]

# See README.md for instructions. Short version:
# * `bazel run //docs:docs.serve` in a separate terminal
Expand Down
2 changes: 1 addition & 1 deletion examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bazel_dep(name = "protobuf", version = "27.0", repo_name = "com_google_protobuf"

# Only needed to make rules_python's CI happy. rules_java 8.3.0+ is needed so
# that --java_runtime_version=remotejdk_11 works with Bazel 8.
bazel_dep(name = "rules_java", version = "8.3.0")
bazel_dep(name = "rules_java", version = "8.3.1")

# Only needed to make rules_python's CI happy. A test verifies that
# MODULE.bazel.lock is cross-platform friendly, and there are transitive
Expand Down
12 changes: 6 additions & 6 deletions examples/bzlmod/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/bzlmod_build_file_generation/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ local_path_override(
)

# Only needed to make rules_python's CI happy
bazel_dep(name = "rules_java", version = "8.3.0")
bazel_dep(name = "rules_java", version = "8.3.1")
2 changes: 1 addition & 1 deletion examples/multi_python_versions/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ bazel_dep(name = "rules_shell", version = "0.2.0", dev_dependency = True)

# Only needed to make rules_python's CI happy. rules_java 8.3.0+ is needed so
# that --java_runtime_version=remotejdk_11 works with Bazel 8.
bazel_dep(name = "rules_java", version = "8.3.0")
bazel_dep(name = "rules_java", version = "8.3.1")
1 change: 1 addition & 0 deletions gazelle/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bazel_dep(name = "bazel_skylib", version = "1.6.1")
bazel_dep(name = "rules_python", version = "0.18.0")
bazel_dep(name = "rules_go", version = "0.41.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.33.0", repo_name = "bazel_gazelle")
bazel_dep(name = "rules_cc", version = "0.0.16")

local_path_override(
module_name = "rules_python",
Expand Down
20 changes: 9 additions & 11 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,19 @@ def rules_python_internal_deps():

http_archive(
name = "com_google_protobuf",
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
strip_prefix = "protobuf-27.0",
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
],
sha256 = "23082dca1ca73a1e9c6cbe40097b41e81f71f3b4d6201e36c134acc30a1b3660",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc2/protobuf-29.0-rc2.zip",
strip_prefix = "protobuf-29.0-rc2",
)

# Needed for stardoc
http_archive(
name = "rules_java",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/6.3.0/rules_java-6.3.0.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/6.3.0/rules_java-6.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/rules_java/releases/download/8.3.1/rules_java-8.3.1.tar.gz",
"https://github.com/bazelbuild/rules_java/releases/download/8.3.1/rules_java-8.3.1.tar.gz",
],
sha256 = "29ba147c583aaf5d211686029842c5278e12aaea86f66bd4a9eb5e525b7f2701",
sha256 = "ee786b943e00da4fea7c233e70e5f5b8a01cc69b9341b3f49169f174fe0df1c5",
)

RULES_JVM_EXTERNAL_TAG = "5.2"
Expand Down Expand Up @@ -224,9 +222,9 @@ def rules_python_internal_deps():

http_archive(
name = "rules_cc",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.14/rules_cc-0.0.14.tar.gz"],
sha256 = "906e89286acc67c20819c3c88b3283de0d5868afda33635d70acae0de9777bb7",
strip_prefix = "rules_cc-0.0.14",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.16/rules_cc-0.0.16.tar.gz"],
sha256 = "bbf1ae2f83305b7053b11e4467d317a7ba3517a12cef608543c1b1c5bf48a4df",
strip_prefix = "rules_cc-0.0.16",
)

http_archive(
Expand Down
4 changes: 4 additions & 0 deletions internal_setup.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ load("@cgrindel_bazel_starlib//:deps.bzl", "bazel_starlib_dependencies")
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_bazel_integration_test//bazel_integration_test:deps.bzl", "bazel_integration_test_rules_dependencies")
load("@rules_bazel_integration_test//bazel_integration_test:repo_defs.bzl", "bazel_binaries")
load("@rules_java//java:repositories.bzl", "rules_java_dependencies", "rules_java_toolchains")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
load("@rules_shell//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains")
load("//:version.bzl", "SUPPORTED_BAZEL_VERSIONS")
Expand Down Expand Up @@ -52,6 +53,9 @@ def rules_python_internal_setup():

protobuf_deps()

rules_java_dependencies()
rules_java_toolchains()

bazel_integration_test_rules_dependencies()
bazel_starlib_dependencies()
bazel_binaries(versions = SUPPORTED_BAZEL_VERSIONS)
Expand Down
24 changes: 13 additions & 11 deletions python/private/py_repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,26 @@ def py_repositories():
)
http_archive(
name = "bazel_skylib",
sha256 = "74d544d96f4a5bb630d465ca8bbcfe231e3594e5aae57e1edbf17a6eb3ca2506",
sha256 = "d00f1389ee20b60018e92644e0948e16e350a7707219e7a390fb0a99b6ec9262",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.3.0/bazel-skylib-1.3.0.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.7.0/bazel-skylib-1.7.0.tar.gz",
],
)
http_archive(
name = "rules_cc",
sha256 = "d9bdd3ec66b6871456ec9c965809f43a0901e692d754885e89293807762d3d80",
strip_prefix = "rules_cc-0.0.13",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.13/rules_cc-0.0.13.tar.gz"],
sha256 = "4b12149a041ddfb8306a8fd0e904e39d673552ce82e4296e96fac9cbf0780e59",
strip_prefix = "rules_cc-0.1.0",
urls = ["https://github.com/bazelbuild/rules_cc/releases/download/0.1.0/rules_cc-0.1.0.tar.gz"],
)

# Needed by rules_cc, triggerred by @rules_java_prebuilt in Bazel by using @rules_cc//cc:defs.bzl
# Needed by rules_cc, triggered by @rules_java_prebuilt in Bazel by using @rules_cc//cc:defs.bzl
# NOTE: This name must be com_google_protobuf until Bazel drops WORKSPACE
# support; Bazel itself has references to com_google_protobuf.
http_archive(
name = "protobuf",
sha256 = "da288bf1daa6c04d03a9051781caa52aceb9163586bff9aa6cfb12f69b9395aa",
strip_prefix = "protobuf-27.0",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v27.0/protobuf-27.0.tar.gz",
name = "com_google_protobuf",
sha256 = "23082dca1ca73a1e9c6cbe40097b41e81f71f3b4d6201e36c134acc30a1b3660",
url = "https://github.com/protocolbuffers/protobuf/releases/download/v29.0-rc2/protobuf-29.0-rc2.zip",
strip_prefix = "protobuf-29.0-rc2",
)
pypi_deps()
4 changes: 2 additions & 2 deletions sphinxdocs/docs/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER") # buildifier: disable=bzl-visibility
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
load("//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
load("//sphinxdocs:sphinx_stardoc.bzl", "sphinx_stardocs")

Expand All @@ -14,7 +14,7 @@ _TARGET_COMPATIBLE_WITH = select({
"@platforms//os:linux": [],
"@platforms//os:macos": [],
"//conditions:default": ["@platforms//:incompatible"],
}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
}) if BZLMOD_ENABLED else ["@platforms//:incompatible"]

sphinx_docs_library(
name = "docs_lib",
Expand Down

0 comments on commit e6a6a3a

Please sign in to comment.