From e6a6a3aa0c6a7e051c7a3b7573befc5b710dc189 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Thu, 21 Nov 2024 23:39:59 +0100 Subject: [PATCH] fix: use com_google_protobuf in WORKSPACE (#2432) 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 https://github.com/bazelbuild/rules_python/issues/2429 --------- Co-authored-by: Richard Levasseur --- CHANGELOG.md | 5 ++++ MODULE.bazel | 2 +- docs/BUILD.bazel | 2 +- examples/bzlmod/MODULE.bazel | 2 +- examples/bzlmod/MODULE.bazel.lock | 12 +++++----- .../bzlmod_build_file_generation/MODULE.bazel | 2 +- examples/multi_python_versions/MODULE.bazel | 2 +- gazelle/MODULE.bazel | 1 + internal_deps.bzl | 20 +++++++--------- internal_setup.bzl | 4 ++++ python/private/py_repositories.bzl | 24 ++++++++++--------- sphinxdocs/docs/BUILD.bazel | 4 ++-- 12 files changed, 45 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b5d045edc..5d8398b835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/MODULE.bazel b/MODULE.bazel index d3edb0356c..913a7c49cb 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -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 diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index a4b6a5a440..a9a1db02a8 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -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 diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel index 27dd513762..0a31c3beb8 100644 --- a/examples/bzlmod/MODULE.bazel +++ b/examples/bzlmod/MODULE.bazel @@ -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 diff --git a/examples/bzlmod/MODULE.bazel.lock b/examples/bzlmod/MODULE.bazel.lock index 6e4d6e180b..41c52e888c 100644 --- a/examples/bzlmod/MODULE.bazel.lock +++ b/examples/bzlmod/MODULE.bazel.lock @@ -83,9 +83,9 @@ "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", "https://bcr.bazel.build/modules/rules_cc/0.0.13/MODULE.bazel": "0e8529ed7b323dad0775ff924d2ae5af7640b23553dfcd4d34344c7e7a867191", - "https://bcr.bazel.build/modules/rules_cc/0.0.14/MODULE.bazel": "5e343a3aac88b8d7af3b1b6d2093b55c347b8eefc2e7d1442f7a02dc8fea48ac", "https://bcr.bazel.build/modules/rules_cc/0.0.15/MODULE.bazel": "6704c35f7b4a72502ee81f61bf88706b54f06b3cbe5558ac17e2e14666cd5dcc", - "https://bcr.bazel.build/modules/rules_cc/0.0.15/source.json": "48e606af0e02a716974a8b74fba6988d9f0c93af9177e28cf474bfc5fa26ab10", + "https://bcr.bazel.build/modules/rules_cc/0.0.16/MODULE.bazel": "7661303b8fc1b4d7f532e54e9d6565771fea666fbdf839e0a86affcd02defe87", + "https://bcr.bazel.build/modules/rules_cc/0.0.16/source.json": "227e83737046aa4f50015da48e98e0d8ab42fd0ec74d8d653b6cc9f9a357f200", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", @@ -108,8 +108,8 @@ "https://bcr.bazel.build/modules/rules_java/7.3.2/MODULE.bazel": "50dece891cfdf1741ea230d001aa9c14398062f2b7c066470accace78e412bc2", "https://bcr.bazel.build/modules/rules_java/7.6.1/MODULE.bazel": "2f14b7e8a1aa2f67ae92bc69d1ec0fa8d9f827c4e17ff5e5f02e91caa3b2d0fe", "https://bcr.bazel.build/modules/rules_java/7.6.5/MODULE.bazel": "481164be5e02e4cab6e77a36927683263be56b7e36fef918b458d7a8a1ebadb1", - "https://bcr.bazel.build/modules/rules_java/8.3.0/MODULE.bazel": "cd0722696035d13523365e6a1eb1682c4b32c164aa3503f0731ef97bfad3df1e", - "https://bcr.bazel.build/modules/rules_java/8.3.0/source.json": "a2d2246ed61ea6391ca946b164d87c57644d4705072eda5b74531b48fb99b7d0", + "https://bcr.bazel.build/modules/rules_java/8.3.1/MODULE.bazel": "6df154d6cd5f9ede100d40621cc2f487071017f539caee021b24ecd91cf21034", + "https://bcr.bazel.build/modules/rules_java/8.3.1/source.json": "560c2e0e9586d38b3fe93e59ee1dee6ec39c194548eea4e619a5b37ebe6324af", "https://bcr.bazel.build/modules/rules_jvm_external/4.4.2/MODULE.bazel": "a56b85e418c83eb1839819f0b515c431010160383306d13ec21959ac412d2fe7", "https://bcr.bazel.build/modules/rules_jvm_external/5.1/MODULE.bazel": "33f6f999e03183f7d088c9be518a63467dfd0be94a11d0055fe2d210f89aa909", "https://bcr.bazel.build/modules/rules_jvm_external/5.2/MODULE.bazel": "d9351ba35217ad0de03816ef3ed63f89d411349353077348a45348b096615036", @@ -1350,8 +1350,8 @@ }, "@@rules_java~//java:extensions.bzl%compatibility_proxy": { "general": { - "bzlTransitiveDigest": "tOgQSybDmdV5ILDExAWYtVmkUV75YJN0iaLnD+0RizQ=", - "usagesDigest": "0/TyZruTcO4Acns2lBIfsdJDXcTS869yRn0gpAYMGww=", + "bzlTransitiveDigest": "4UrimEM7gTMnaF+uFyxkxI5Rm+iPRtuuQcf5X3BCIes=", + "usagesDigest": "xpjtNTHKNTxqBkAIM8kCjwvcMhXBoxJptRhR8vXpaoE=", "recordedFileInputs": {}, "recordedDirentsInputs": {}, "envVariables": {}, diff --git a/examples/bzlmod_build_file_generation/MODULE.bazel b/examples/bzlmod_build_file_generation/MODULE.bazel index 2ba52466ae..30ad567879 100644 --- a/examples/bzlmod_build_file_generation/MODULE.bazel +++ b/examples/bzlmod_build_file_generation/MODULE.bazel @@ -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") diff --git a/examples/multi_python_versions/MODULE.bazel b/examples/multi_python_versions/MODULE.bazel index 51ed6f134d..578315741f 100644 --- a/examples/multi_python_versions/MODULE.bazel +++ b/examples/multi_python_versions/MODULE.bazel @@ -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") diff --git a/gazelle/MODULE.bazel b/gazelle/MODULE.bazel index 0418b39036..d216ad5dc1 100644 --- a/gazelle/MODULE.bazel +++ b/gazelle/MODULE.bazel @@ -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", diff --git a/internal_deps.bzl b/internal_deps.bzl index 33decba9fc..f7c363c8c6 100644 --- a/internal_deps.bzl +++ b/internal_deps.bzl @@ -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" @@ -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( diff --git a/internal_setup.bzl b/internal_setup.bzl index b28c0e28b7..03b3c02e98 100644 --- a/internal_setup.bzl +++ b/internal_setup.bzl @@ -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") @@ -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) diff --git a/python/private/py_repositories.bzl b/python/private/py_repositories.bzl index 6283ad7cbc..46ca903df4 100644 --- a/python/private/py_repositories.bzl +++ b/python/private/py_repositories.bzl @@ -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() diff --git a/sphinxdocs/docs/BUILD.bazel b/sphinxdocs/docs/BUILD.bazel index 6af908dc4c..070e0485d7 100644 --- a/sphinxdocs/docs/BUILD.bazel +++ b/sphinxdocs/docs/BUILD.bazel @@ -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") @@ -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",