Skip to content

Commit d1890c0

Browse files
authored
bazel: Add support for bzlmod (#11046)
1 parent b6ca908 commit d1890c0

File tree

6 files changed

+193
-9
lines changed

6 files changed

+193
-9
lines changed

.github/workflows/testing.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,9 @@ jobs:
9090
key: ${{ runner.os }}-bazel-${{ env.USE_BAZEL_VERSION }}-${{ hashFiles('WORKSPACE', 'repositories.bzl') }}
9191

9292
- name: Run bazel build
93-
run: bazelisk build //...
93+
run: bazelisk build //... --enable_bzlmod=false
94+
95+
- name: Run bazel build (bzlmod)
96+
env:
97+
USE_BAZEL_VERSION: 7.0.0
98+
run: bazelisk build //... --enable_bzlmod=true

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bazel-genfiles
1515
bazel-grpc-java
1616
bazel-out
1717
bazel-testlogs
18+
MODULE.bazel.lock
1819

1920
# IntelliJ IDEA
2021
.idea

MODULE.bazel

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
module(
2+
name = "grpc-java",
3+
version = "0",
4+
compatibility_level = 0,
5+
repo_name = "io_grpc_grpc_java",
6+
)
7+
8+
bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis")
9+
bazel_dep(name = "grpc", version = "1.56.3.bcr.1", repo_name = "com_github_grpc_grpc")
10+
bazel_dep(name = "protobuf", version = "23.1", repo_name = "com_google_protobuf")
11+
bazel_dep(name = "rules_cc", version = "0.0.9")
12+
bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go")
13+
bazel_dep(name = "rules_jvm_external", version = "6.0")
14+
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
15+
16+
non_module_deps = use_extension("//:repositories.bzl", "grpc_java_repositories_extension")
17+
use_repo(
18+
non_module_deps,
19+
"com_github_cncf_xds",
20+
"envoy_api",
21+
"io_grpc_grpc_proto",
22+
)
23+
24+
grpc_repo_deps_ext = use_extension("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_repo_deps_ext")
25+
use_repo(
26+
grpc_repo_deps_ext,
27+
"com_envoyproxy_protoc_gen_validate",
28+
"com_github_cncf_udpa",
29+
"opencensus_proto",
30+
)
31+
32+
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
33+
maven.install(
34+
artifacts = [
35+
"com.google.android:annotations:4.1.1.4",
36+
"com.google.api.grpc:proto-google-common-protos:2.29.0",
37+
"com.google.auth:google-auth-library-credentials:1.22.0",
38+
"com.google.auth:google-auth-library-oauth2-http:1.22.0",
39+
"com.google.auto.value:auto-value-annotations:1.10.4",
40+
"com.google.auto.value:auto-value:1.10.4",
41+
"com.google.code.findbugs:jsr305:3.0.2",
42+
"com.google.code.gson:gson:2.10.1",
43+
"com.google.errorprone:error_prone_annotations:2.23.0",
44+
"com.google.guava:failureaccess:1.0.1",
45+
"com.google.guava:guava:32.1.3-android",
46+
"com.google.re2j:re2j:1.7",
47+
"com.google.truth:truth:1.1.5",
48+
"com.squareup.okhttp:okhttp:2.7.5",
49+
"com.squareup.okio:okio:2.10.0", # 3.0+ needs swapping to -jvm; need work to avoid flag-day
50+
"io.netty:netty-buffer:4.1.100.Final",
51+
"io.netty:netty-codec-http2:4.1.100.Final",
52+
"io.netty:netty-codec-http:4.1.100.Final",
53+
"io.netty:netty-codec-socks:4.1.100.Final",
54+
"io.netty:netty-codec:4.1.100.Final",
55+
"io.netty:netty-common:4.1.100.Final",
56+
"io.netty:netty-handler-proxy:4.1.100.Final",
57+
"io.netty:netty-handler:4.1.100.Final",
58+
"io.netty:netty-resolver:4.1.100.Final",
59+
"io.netty:netty-tcnative-boringssl-static:2.0.61.Final",
60+
"io.netty:netty-tcnative-classes:2.0.61.Final",
61+
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.100.Final",
62+
"io.netty:netty-transport-native-unix-common:4.1.100.Final",
63+
"io.netty:netty-transport:4.1.100.Final",
64+
"io.opencensus:opencensus-api:0.31.0",
65+
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
66+
"io.perfmark:perfmark-api:0.26.0",
67+
"junit:junit:4.13.2",
68+
"org.apache.tomcat:annotations-api:6.0.53",
69+
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
70+
],
71+
repositories = [
72+
"https://repo.maven.apache.org/maven2/",
73+
],
74+
strict_visibility = True,
75+
)
76+
use_repo(maven, "maven")
77+
maven.override(
78+
coordinates = "com.google.protobuf:protobuf-java",
79+
target = "@com_google_protobuf//:protobuf_java",
80+
)
81+
maven.override(
82+
coordinates = "com.google.protobuf:protobuf-java-util",
83+
target = "@com_google_protobuf//:protobuf_java_util",
84+
)
85+
maven.override(
86+
coordinates = "com.google.protobuf:protobuf-javalite",
87+
target = "@com_google_protobuf//:protobuf_javalite",
88+
)
89+
maven.override(
90+
coordinates = "io.grpc:grpc-alts",
91+
target = "@io_grpc_grpc_java//alts",
92+
)
93+
maven.override(
94+
coordinates = "io.grpc:grpc-api",
95+
target = "@io_grpc_grpc_java//api",
96+
)
97+
maven.override(
98+
coordinates = "io.grpc:grpc-auth",
99+
target = "@io_grpc_grpc_java//auth",
100+
)
101+
maven.override(
102+
coordinates = "io.grpc:grpc-census",
103+
target = "@io_grpc_grpc_java//census",
104+
)
105+
maven.override(
106+
coordinates = "io.grpc:grpc-context",
107+
target = "@io_grpc_grpc_java//context",
108+
)
109+
maven.override(
110+
coordinates = "io.grpc:grpc-core",
111+
target = "@io_grpc_grpc_java//core:core_maven",
112+
)
113+
maven.override(
114+
coordinates = "io.grpc:grpc-googleapis",
115+
target = "@io_grpc_grpc_java//googleapis",
116+
)
117+
maven.override(
118+
coordinates = "io.grpc:grpc-grpclb",
119+
target = "@io_grpc_grpc_java//grpclb",
120+
)
121+
maven.override(
122+
coordinates = "io.grpc:grpc-inprocess",
123+
target = "@io_grpc_grpc_java//inprocess",
124+
)
125+
maven.override(
126+
coordinates = "io.grpc:grpc-netty",
127+
target = "@io_grpc_grpc_java//netty",
128+
)
129+
maven.override(
130+
coordinates = "io.grpc:grpc-netty-shaded",
131+
target = "@io_grpc_grpc_java//netty:shaded_maven",
132+
)
133+
maven.override(
134+
coordinates = "io.grpc:grpc-okhttp",
135+
target = "@io_grpc_grpc_java//okhttp",
136+
)
137+
maven.override(
138+
coordinates = "io.grpc:grpc-protobuf",
139+
target = "@io_grpc_grpc_java//protobuf",
140+
)
141+
maven.override(
142+
coordinates = "io.grpc:grpc-protobuf-lite",
143+
target = "@io_grpc_grpc_java//protobuf-lite",
144+
)
145+
maven.override(
146+
coordinates = "io.grpc:grpc-rls",
147+
target = "@io_grpc_grpc_java//rls",
148+
)
149+
maven.override(
150+
coordinates = "io.grpc:grpc-services",
151+
target = "@io_grpc_grpc_java//services:services_maven",
152+
)
153+
maven.override(
154+
coordinates = "io.grpc:grpc-stub",
155+
target = "@io_grpc_grpc_java//stub",
156+
)
157+
maven.override(
158+
coordinates = "io.grpc:grpc-testing",
159+
target = "@io_grpc_grpc_java//testing",
160+
)
161+
maven.override(
162+
coordinates = "io.grpc:grpc-xds",
163+
target = "@io_grpc_grpc_java//xds:xds_maven",
164+
)
165+
maven.override(
166+
coordinates = "io.grpc:grpc-util",
167+
target = "@io_grpc_grpc_java//util",
168+
)
169+
170+
switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
171+
switched_rules.use_languages(java = True)
172+
use_repo(switched_rules, "com_google_googleapis_imports")

WORKSPACE.bzlmod

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# When using bzlmod this makes sure nothing from the legacy WORKSPACE is loaded

protobuf-lite/BUILD.bazel

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ java_library(
1212
artifact("com.google.guava:guava"),
1313
artifact("com.google.j2objc:j2objc-annotations"),
1414
] + select({
15-
":android": ["@com_google_protobuf_javalite//:protobuf_javalite"],
16-
"//conditions:default": ["@com_google_protobuf//:protobuf_java"],
15+
":android": [artifact("com.google.protobuf:protobuf-javalite")],
16+
"//conditions:default": [artifact("com.google.protobuf:protobuf-java")],
1717
}),
1818
)
1919

repositories.bzl

+11-6
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS = {
8383
"io.grpc:grpc-util": "@io_grpc_grpc_java//util",
8484
}
8585

86-
def grpc_java_repositories():
86+
def grpc_java_repositories(bzlmod = False):
8787
"""Imports dependencies for grpc-java."""
8888
if not native.existing_rule("com_github_cncf_udpa"):
8989
http_archive(
@@ -104,7 +104,7 @@ def grpc_java_repositories():
104104
"https://github.com/cncf/xds/archive/e9ce68804cb4e64cab5a52e3c8baf840d4ff87b7.tar.gz",
105105
],
106106
)
107-
if not native.existing_rule("com_github_grpc_grpc"):
107+
if not bzlmod and not native.existing_rule("com_github_grpc_grpc"):
108108
http_archive(
109109
name = "com_github_grpc_grpc",
110110
strip_prefix = "grpc-1.46.0",
@@ -113,11 +113,11 @@ def grpc_java_repositories():
113113
"https://github.com/grpc/grpc/archive/v1.46.0.tar.gz",
114114
],
115115
)
116-
if not native.existing_rule("com_google_protobuf"):
116+
if not bzlmod and not native.existing_rule("com_google_protobuf"):
117117
com_google_protobuf()
118-
if not native.existing_rule("com_google_protobuf_javalite"):
118+
if not bzlmod and not native.existing_rule("com_google_protobuf_javalite"):
119119
com_google_protobuf_javalite()
120-
if not native.existing_rule("com_google_googleapis"):
120+
if not bzlmod and not native.existing_rule("com_google_googleapis"):
121121
http_archive(
122122
name = "com_google_googleapis",
123123
sha256 = "49930468563dd48283e8301e8d4e71436bf6d27ac27c235224cc1a098710835d",
@@ -126,7 +126,7 @@ def grpc_java_repositories():
126126
"https://github.com/googleapis/googleapis/archive/ca1372c6d7bcb199638ebfdb40d2b2660bab7b88.tar.gz",
127127
],
128128
)
129-
if not native.existing_rule("io_bazel_rules_go"):
129+
if not bzlmod and not native.existing_rule("io_bazel_rules_go"):
130130
http_archive(
131131
name = "io_bazel_rules_go",
132132
sha256 = "ab21448cef298740765f33a7f5acee0607203e4ea321219f2a4c85a6e0fb0a27",
@@ -175,3 +175,8 @@ def io_grpc_grpc_proto():
175175
strip_prefix = "grpc-proto-4f245d272a28a680606c0739753506880cf33b5f",
176176
urls = ["https://github.com/grpc/grpc-proto/archive/4f245d272a28a680606c0739753506880cf33b5f.zip"],
177177
)
178+
179+
def _grpc_java_repositories_extension(_):
180+
grpc_java_repositories(bzlmod = True)
181+
182+
grpc_java_repositories_extension = module_extension(implementation = _grpc_java_repositories_extension)

0 commit comments

Comments
 (0)