Skip to content

Commit 85a4838

Browse files
committed
Add WORKSPACE compatibility for bazel-worker-api
Implements workspace_compat.bzl to enable bazel-worker-api usage in WORKSPACE mode, similar to rules_scala's approach but supporting both proto and java components. Changes: - Created workspace_compat.bzl to download bazel_worker_api and bazel_worker_java from GitHub releases - Updated setup.bzl to add required Maven dependencies (gson, error_prone_annotations) and upgrade guava to 33.0.0-jre - Updated versions.bzl with BAZEL_WORKER_API version constant - Modified initialize.bzl to call workspace_compat() in kotlin_repositories() - Synchronized MODULE.bazel dependencies with WORKSPACE setup - Repinned Maven dependencies This allows PR bazelbuild#1218 to work with both bzlmod and WORKSPACE builds.
1 parent 7769d61 commit 85a4838

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

MODULE.bazel

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ bazel_dep(name = "rules_python", version = "0.23.1")
1616
bazel_dep(name = "rules_android", version = "0.6.4")
1717
bazel_dep(name = "bazel_features", version = "1.25.0")
1818
bazel_dep(name = "rules_shell", version = "0.4.1")
19+
bazel_dep(name = "bazel_worker_api", version = "0.0.6")
20+
bazel_dep(name = "bazel_worker_java", version = "0.0.6")
1921

2022
bazel_dep(name = "buildifier_prebuilt", version = "8.2.0.2", dev_dependency = True)
21-
bazel_dep(name = "bazel_worker_api", version = "0.0.4")
22-
bazel_dep(name = "bazel_worker_java", version = "0.0.4")
2323

2424
rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
2525
use_repo(rules_java_toolchains, "remote_java_tools")
@@ -60,10 +60,12 @@ maven.install(
6060
name = "kotlin_rules_maven",
6161
artifacts = [
6262
"com.google.code.findbugs:jsr305:3.0.2",
63+
"com.google.code.gson:gson:2.10.1",
64+
"com.google.errorprone:error_prone_annotations:2.23.0",
6365
"junit:junit:4.13-beta-3",
6466
"com.google.protobuf:protobuf-java:4.29.0",
6567
"com.google.protobuf:protobuf-java-util:4.29.0",
66-
"com.google.guava:guava:27.1-jre",
68+
"com.google.guava:guava:33.0.0-jre",
6769
"com.google.truth:truth:0.45",
6870
"com.google.auto.service:auto-service:1.1.1",
6971
"com.google.auto.service:auto-service-annotations:1.1.1",

MODULE.release.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ bazel_dep(name = "protobuf", version = "29.0", repo_name = "com_google_protobuf"
1414
bazel_dep(name = "rules_proto", version = "6.0.2", repo_name = "rules_proto")
1515
bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "py_absl")
1616
bazel_dep(name = "rules_cc", version = "0.0.16")
17+
bazel_dep(name = "bazel_worker_api", version = "0.0.6")
18+
bazel_dep(name = "bazel_worker_java", version = "0.0.6")
1719

1820
rules_java_toolchains = use_extension("@rules_java//java:extensions.bzl", "toolchains")
1921
use_repo(rules_java_toolchains, "remote_java_tools")

kotlin_rules_maven_install.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
22
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
3-
"__INPUT_ARTIFACTS_HASH": -129239194,
4-
"__RESOLVED_ARTIFACTS_HASH": -667872389,
3+
"__INPUT_ARTIFACTS_HASH": -1911586658,
4+
"__RESOLVED_ARTIFACTS_HASH": -1900729030,
55
"conflict_resolution": {
6-
"com.google.guava:guava:27.1-jre": "com.google.guava:guava:33.2.1-jre"
6+
"com.google.errorprone:error_prone_annotations:2.23.0": "com.google.errorprone:error_prone_annotations:2.26.1",
7+
"com.google.guava:guava:33.0.0-jre": "com.google.guava:guava:33.2.1-jre"
78
},
89
"artifacts": {
910
"com.google.auto.service:auto-service": {
@@ -50,10 +51,10 @@
5051
},
5152
"com.google.code.gson:gson": {
5253
"shasums": {
53-
"jar": "d3999291855de495c94c743761b8ab5176cfeabe281a5ab0d8e8d45326fd703e",
54-
"sources": "ba5bddb1a89eb721fcca39f3b34294532060f851e2407a82d82134a41eec4719"
54+
"jar": "4241c14a7727c34feea6507ec801318a3d4a90f070e4525681079fb94ee4c593",
55+
"sources": "eee1cc5c1f4267ee194cc245777e68084738ef390acd763354ce0ff6bfb7bcc1"
5556
},
56-
"version": "2.8.9"
57+
"version": "2.10.1"
5758
},
5859
"com.google.dagger:dagger": {
5960
"shasums": {

src/main/starlark/core/repositories/initialize.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ load(
2222
)
2323
load(":setup.bzl", "kt_configure")
2424
load(":versions.bzl", _versions = "versions")
25+
load(":workspace_compat.bzl", "workspace_compat")
2526

2627
# exports
2728
versions = _versions
@@ -39,4 +40,5 @@ def kotlin_repositories(
3940
ksp_compiler_release: (internal) version provider from versions.bzl.
4041
"""
4142
_release_kotlin_repositories(is_bzlmod = is_bzlmod, compiler_release = compiler_release, ksp_compiler_release = ksp_compiler_release)
43+
workspace_compat()
4244
kt_configure()

src/main/starlark/core/repositories/setup.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def kt_configure():
3030
fetch_sources = True,
3131
artifacts = [
3232
"com.google.code.findbugs:jsr305:3.0.2",
33+
"com.google.code.gson:gson:2.10.1",
34+
"com.google.errorprone:error_prone_annotations:2.23.0",
3335
"junit:junit:4.13-beta-3",
3436
"com.google.protobuf:protobuf-java:4.29.0",
3537
"com.google.protobuf:protobuf-java-util:4.29.0",
36-
"com.google.guava:guava:27.1-jre",
38+
"com.google.guava:guava:33.0.0-jre",
3739
"com.google.truth:truth:0.45",
3840
"com.google.auto.service:auto-service:1.1.1",
3941
"com.google.auto.service:auto-service-annotations:1.1.1",

src/main/starlark/core/repositories/versions.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ versions = struct(
117117
],
118118
sha256 = "26d4021f6898e23b82ef953078389dd49ac2b5618ac564ade4ef87cced147b38",
119119
),
120+
BAZEL_WORKER_API = version(
121+
version = "0.0.6",
122+
sha256 = "5aac6ae6a23015cc7984492a114dc539effc244ec5ac7f8f6b1539c15fb376eb",
123+
strip_prefix_template = "bazel-worker-api-{version}",
124+
url_templates = [
125+
"https://github.com/bazelbuild/bazel-worker-api/releases/download/v{version}/bazel-worker-api-v{version}.tar.gz",
126+
],
127+
),
120128
KOTLINX_SERIALIZATION_CORE_JVM = version(
121129
version = "1.8.1",
122130
url_templates = [
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2018 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+
"""Macro to translate Bazel modules into legacy WORKSPACE compatible repos.
16+
17+
Used only for Bazel modules that don't offer a legacy WORKSPACE compatible API
18+
already. This became necessary for bazel-worker-api which only provides bzlmod
19+
support.
20+
"""
21+
22+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
23+
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
24+
25+
def _bazel_worker_api_repo(name, strip_prefix):
26+
"""Download bazel-worker-api from GitHub releases.
27+
28+
Args:
29+
name: The name of the repository to create.
30+
strip_prefix: The path within the archive to use as the root (e.g., "proto" or "java").
31+
"""
32+
maybe(
33+
http_archive,
34+
name = name,
35+
sha256 = "5aac6ae6a23015cc7984492a114dc539effc244ec5ac7f8f6b1539c15fb376eb",
36+
urls = [
37+
"https://github.com/bazelbuild/bazel-worker-api/releases/download/v0.0.6/bazel-worker-api-v0.0.6.tar.gz",
38+
],
39+
strip_prefix = "bazel-worker-api-0.0.6/" + strip_prefix,
40+
)
41+
42+
def workspace_compat():
43+
"""Setup bazel-worker-api repositories for WORKSPACE.
44+
45+
This function creates the necessary repository rules for bazel-worker-api
46+
proto and java implementations, making them available in WORKSPACE mode.
47+
In bzlmod mode, these are loaded via bazel_dep in MODULE.bazel.
48+
"""
49+
50+
# Proto definitions (worker_protocol.proto)
51+
_bazel_worker_api_repo(
52+
name = "bazel_worker_api",
53+
strip_prefix = "proto",
54+
)
55+
56+
# Java implementation (WorkRequestHandler, etc.)
57+
_bazel_worker_api_repo(
58+
name = "bazel_worker_java",
59+
strip_prefix = "java",
60+
)

0 commit comments

Comments
 (0)