Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bzlmod #11046

Merged
merged 19 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ jobs:
key: ${{ runner.os }}-bazel-${{ env.USE_BAZEL_VERSION }}-${{ hashFiles('WORKSPACE', 'repositories.bzl') }}

- name: Run bazel build
run: bazelisk build //...
run: bazelisk build //... --enable_bzlmod=false

- name: Run bazel build (bzlmod)
env:
USE_BAZEL_VERSION: 7.0.0
run: bazelisk build //... --enable_bzlmod=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bazel-genfiles
bazel-grpc-java
bazel-out
bazel-testlogs
MODULE.bazel.lock

# IntelliJ IDEA
.idea
Expand Down
172 changes: 172 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
module(
name = "grpc-java",
version = "0",
compatibility_level = 0,
repo_name = "io_grpc_grpc_java",
)

bazel_dep(name = "googleapis", version = "0.0.0-20240326-1c8d509c5", repo_name = "com_google_googleapis")
bazel_dep(name = "grpc", version = "1.56.3.bcr.1", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "protobuf", version = "23.1", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_jvm_external", version = "6.0")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")

non_module_deps = use_extension("//:repositories.bzl", "grpc_java_repositories_extension")
use_repo(
non_module_deps,
"com_github_cncf_xds",
"envoy_api",
"io_grpc_grpc_proto",
)

grpc_repo_deps_ext = use_extension("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_repo_deps_ext")
use_repo(
grpc_repo_deps_ext,
"com_envoyproxy_protoc_gen_validate",
"com_github_cncf_udpa",
"opencensus_proto",
)

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
artifacts = [
"com.google.android:annotations:4.1.1.4",
keith marked this conversation as resolved.
Show resolved Hide resolved
"com.google.api.grpc:proto-google-common-protos:2.29.0",
"com.google.auth:google-auth-library-credentials:1.22.0",
"com.google.auth:google-auth-library-oauth2-http:1.22.0",
"com.google.auto.value:auto-value-annotations:1.10.4",
"com.google.auto.value:auto-value:1.10.4",
"com.google.code.findbugs:jsr305:3.0.2",
"com.google.code.gson:gson:2.10.1",
"com.google.errorprone:error_prone_annotations:2.23.0",
"com.google.guava:failureaccess:1.0.1",
"com.google.guava:guava:32.1.3-android",
"com.google.re2j:re2j:1.7",
"com.google.truth:truth:1.1.5",
"com.squareup.okhttp:okhttp:2.7.5",
"com.squareup.okio:okio:2.10.0", # 3.0+ needs swapping to -jvm; need work to avoid flag-day
"io.netty:netty-buffer:4.1.100.Final",
"io.netty:netty-codec-http2:4.1.100.Final",
"io.netty:netty-codec-http:4.1.100.Final",
"io.netty:netty-codec-socks:4.1.100.Final",
"io.netty:netty-codec:4.1.100.Final",
"io.netty:netty-common:4.1.100.Final",
"io.netty:netty-handler-proxy:4.1.100.Final",
"io.netty:netty-handler:4.1.100.Final",
"io.netty:netty-resolver:4.1.100.Final",
"io.netty:netty-tcnative-boringssl-static:2.0.61.Final",
"io.netty:netty-tcnative-classes:2.0.61.Final",
"io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.1.100.Final",
"io.netty:netty-transport-native-unix-common:4.1.100.Final",
"io.netty:netty-transport:4.1.100.Final",
"io.opencensus:opencensus-api:0.31.0",
"io.opencensus:opencensus-contrib-grpc-metrics:0.31.0",
"io.perfmark:perfmark-api:0.26.0",
"junit:junit:4.13.2",
"org.apache.tomcat:annotations-api:6.0.53",
"org.codehaus.mojo:animal-sniffer-annotations:1.23",
],
repositories = [
"https://repo.maven.apache.org/maven2/",
],
strict_visibility = True,
)
use_repo(maven, "maven")
maven.override(
coordinates = "com.google.protobuf:protobuf-java",
target = "@com_google_protobuf//:protobuf_java",
)
maven.override(
coordinates = "com.google.protobuf:protobuf-java-util",
target = "@com_google_protobuf//:protobuf_java_util",
)
maven.override(
coordinates = "com.google.protobuf:protobuf-javalite",
target = "@com_google_protobuf//:protobuf_javalite",
)
maven.override(
coordinates = "io.grpc:grpc-alts",
target = "@io_grpc_grpc_java//alts",
)
maven.override(
coordinates = "io.grpc:grpc-api",
target = "@io_grpc_grpc_java//api",
)
maven.override(
coordinates = "io.grpc:grpc-auth",
target = "@io_grpc_grpc_java//auth",
)
maven.override(
coordinates = "io.grpc:grpc-census",
target = "@io_grpc_grpc_java//census",
)
maven.override(
coordinates = "io.grpc:grpc-context",
target = "@io_grpc_grpc_java//context",
)
maven.override(
coordinates = "io.grpc:grpc-core",
target = "@io_grpc_grpc_java//core:core_maven",
)
maven.override(
coordinates = "io.grpc:grpc-googleapis",
target = "@io_grpc_grpc_java//googleapis",
)
maven.override(
coordinates = "io.grpc:grpc-grpclb",
target = "@io_grpc_grpc_java//grpclb",
)
maven.override(
coordinates = "io.grpc:grpc-inprocess",
target = "@io_grpc_grpc_java//inprocess",
)
maven.override(
coordinates = "io.grpc:grpc-netty",
target = "@io_grpc_grpc_java//netty",
)
maven.override(
coordinates = "io.grpc:grpc-netty-shaded",
target = "@io_grpc_grpc_java//netty:shaded_maven",
)
maven.override(
coordinates = "io.grpc:grpc-okhttp",
target = "@io_grpc_grpc_java//okhttp",
)
maven.override(
coordinates = "io.grpc:grpc-protobuf",
target = "@io_grpc_grpc_java//protobuf",
)
maven.override(
coordinates = "io.grpc:grpc-protobuf-lite",
target = "@io_grpc_grpc_java//protobuf-lite",
)
maven.override(
coordinates = "io.grpc:grpc-rls",
target = "@io_grpc_grpc_java//rls",
)
maven.override(
coordinates = "io.grpc:grpc-services",
target = "@io_grpc_grpc_java//services:services_maven",
)
maven.override(
coordinates = "io.grpc:grpc-stub",
target = "@io_grpc_grpc_java//stub",
)
maven.override(
coordinates = "io.grpc:grpc-testing",
target = "@io_grpc_grpc_java//testing",
)
maven.override(
coordinates = "io.grpc:grpc-xds",
target = "@io_grpc_grpc_java//xds:xds_maven",
)
maven.override(
coordinates = "io.grpc:grpc-util",
target = "@io_grpc_grpc_java//util",
)

switched_rules = use_extension("@com_google_googleapis//:extensions.bzl", "switched_rules")
switched_rules.use_languages(java = True)
use_repo(switched_rules, "com_google_googleapis_imports")
1 change: 1 addition & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# When using bzlmod this makes sure nothing from the legacy WORKSPACE is loaded
4 changes: 2 additions & 2 deletions protobuf-lite/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ java_library(
artifact("com.google.guava:guava"),
artifact("com.google.j2objc:j2objc-annotations"),
] + select({
":android": ["@com_google_protobuf_javalite//:protobuf_javalite"],
"//conditions:default": ["@com_google_protobuf//:protobuf_java"],
":android": [artifact("com.google.protobuf:protobuf-javalite")],
"//conditions:default": [artifact("com.google.protobuf:protobuf-java")],
}),
)

Expand Down
17 changes: 11 additions & 6 deletions repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ IO_GRPC_GRPC_JAVA_OVERRIDE_TARGETS = {
"io.grpc:grpc-util": "@io_grpc_grpc_java//util",
}

def grpc_java_repositories():
def grpc_java_repositories(bzlmod = False):
"""Imports dependencies for grpc-java."""
if not native.existing_rule("com_github_cncf_udpa"):
http_archive(
Expand All @@ -104,7 +104,7 @@ def grpc_java_repositories():
"https://github.com/cncf/xds/archive/e9ce68804cb4e64cab5a52e3c8baf840d4ff87b7.tar.gz",
],
)
if not native.existing_rule("com_github_grpc_grpc"):
if not bzlmod and not native.existing_rule("com_github_grpc_grpc"):
http_archive(
name = "com_github_grpc_grpc",
strip_prefix = "grpc-1.46.0",
Expand All @@ -113,11 +113,11 @@ def grpc_java_repositories():
"https://github.com/grpc/grpc/archive/v1.46.0.tar.gz",
],
)
if not native.existing_rule("com_google_protobuf"):
if not bzlmod and not native.existing_rule("com_google_protobuf"):
com_google_protobuf()
if not native.existing_rule("com_google_protobuf_javalite"):
if not bzlmod and not native.existing_rule("com_google_protobuf_javalite"):
com_google_protobuf_javalite()
if not native.existing_rule("com_google_googleapis"):
if not bzlmod and not native.existing_rule("com_google_googleapis"):
http_archive(
name = "com_google_googleapis",
sha256 = "49930468563dd48283e8301e8d4e71436bf6d27ac27c235224cc1a098710835d",
Expand All @@ -126,7 +126,7 @@ def grpc_java_repositories():
"https://github.com/googleapis/googleapis/archive/ca1372c6d7bcb199638ebfdb40d2b2660bab7b88.tar.gz",
],
)
if not native.existing_rule("io_bazel_rules_go"):
if not bzlmod and not native.existing_rule("io_bazel_rules_go"):
http_archive(
name = "io_bazel_rules_go",
sha256 = "ab21448cef298740765f33a7f5acee0607203e4ea321219f2a4c85a6e0fb0a27",
Expand Down Expand Up @@ -175,3 +175,8 @@ def io_grpc_grpc_proto():
strip_prefix = "grpc-proto-4f245d272a28a680606c0739753506880cf33b5f",
urls = ["https://github.com/grpc/grpc-proto/archive/4f245d272a28a680606c0739753506880cf33b5f.zip"],
)

def _grpc_java_repositories_extension(_):
grpc_java_repositories(bzlmod = True)

grpc_java_repositories_extension = module_extension(implementation = _grpc_java_repositories_extension)
Loading