Skip to content

Commit cd7b01c

Browse files
authored
Merge branch 'bazel-contrib:main' into main
2 parents 3be616d + 6f0741b commit cd7b01c

41 files changed

Lines changed: 1470 additions & 356 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bazelrc

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@ build --explicit_java_test_deps
1818
test --verbose_failures
1919
test --test_output=errors
2020

21-
# Allow protoc to compile
22-
common --enable_platform_specific_config
23-
common:linux --cxxopt=-std=c++17
24-
common:linux --host_cxxopt=-std=c++17
25-
common:macos --cxxopt=-std=c++17
26-
common:macos --host_cxxopt=-std=c++17
27-
common:windows --define=protobuf_allow_msvc=true
28-
common:windows --cxxopt=/std:c++17
29-
common:windows --host_cxxopt=/std:c++17
30-
3121
import %workspace%/.bazelrc.windows
3222

3323
# Load any settings specific to the current user.
3424
try-import %workspace%/.bazelrc.user
3525

36-
# Ask the Protobuf rules to use the pre-built protoc rather than rebuilding from scratch
26+
# Use pre-built protoc and protoc-gen-grpc-java rather than rebuilding from C++ source.
27+
# Both flags are needed on Bazel < 9: the first registers the prebuilt toolchain,
28+
# the second tells Bazel to use toolchain resolution instead of the hard-coded protoc cc_binary.
3729
common --@com_google_protobuf//bazel/toolchains:prefer_prebuilt_protoc
30+
common --incompatible_enable_proto_toolchain_resolution

.bcr/metadata.template.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
"name": "Simon Stewart",
1616
"email": "simon.m.stewart@gmail.com",
1717
"github": "shs96c"
18+
},
19+
{
20+
"name": "Romain Chossart",
21+
"email": "romainchossart@gmail.com",
22+
"github": "sitaktif"
1823
}
1924
],
2025
"repository": [

.github/workflows/publish.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Publish to the BCR
2+
name: Publish to BCR
3+
4+
on:
5+
workflow_call:
6+
inputs:
7+
tag_name:
8+
required: true
9+
type: string
10+
secrets:
11+
BCR_PUBLISH_TOKEN:
12+
required: true
13+
workflow_dispatch:
14+
inputs:
15+
tag_name:
16+
required: true
17+
type: string
18+
19+
jobs:
20+
publish:
21+
uses: bazel-contrib/publish-to-bcr/.github/workflows/publish.yaml@v1.2.0
22+
with:
23+
tag_name: ${{ inputs.tag_name }}
24+
# GitHub repository which is a fork of the upstream where the Pull Request will be opened.
25+
registry_fork: bazel-contrib/bazel-central-registry
26+
attest: false
27+
draft: false
28+
permissions:
29+
contents: write
30+
secrets:
31+
# Necessary to push to the BCR fork, and to open a pull request against a registry
32+
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,10 @@ jobs:
2626
body_path: release_notes.txt
2727
files: rules_jvm-*.tar.gz
2828
fail_on_unmatched_files: true
29+
publish:
30+
needs: build
31+
uses: ./.github/workflows/publish.yaml
32+
with:
33+
tag_name: ${{ inputs.tag_name || github.ref_name }}
34+
secrets:
35+
publish_token: ${{ secrets.BCR_PUBLISH_TOKEN }}

MODULE.bazel

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ bazel_dep(name = "apple_rules_lint", version = "0.4.0")
1313
bazel_dep(name = "bazel_skylib", version = "1.8.1")
1414
bazel_dep(name = "gazelle", version = "0.42.0", repo_name = "bazel_gazelle")
1515
bazel_dep(name = "protobuf", version = PROTOBUF_VERSION, repo_name = "com_google_protobuf")
16+
bazel_dep(name = "platforms", version = "0.0.11")
1617
bazel_dep(name = "rules_cc", version = "0.1.1")
1718
bazel_dep(name = "rules_go", version = "0.52.0")
1819
bazel_dep(name = "rules_java", version = "8.15.2")
@@ -47,7 +48,18 @@ use_repo(
4748

4849
# There is a `grpc_java` bazel_dep we could use, but that pollutes the main
4950
# `maven` namespace and patches `protobuf` too. Instead, we pull the http
50-
# archive and patch it so we can use it in the one target we care about
51+
# archive and patch it so we can use it in the one target we care about.
52+
#
53+
# IMPORTANT: `@grpc-java` is declared via `use_repo_rule` and is therefore
54+
# scoped to this module. Downstream consumers of `contrib_rules_jvm` cannot
55+
# reference it and are not affected by the patches below. Because of that,
56+
# the patches in `third_party/grpc-java.patch` are deliberately *not*
57+
# upstream-safe — they rewrite `_protoc` and `grpc_java_plugin` to point at
58+
# our prebuilt binaries and rewire maven artifacts to our internal repo.
59+
# Do not try to generalise these patches or expose `@grpc-java` to other
60+
# modules; keep this fork strictly internal.
61+
GRPC_JAVA_VERSION = "1.79.0"
62+
5163
http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
5264

5365
http_archive(
@@ -57,8 +69,102 @@ http_archive(
5769
patches = [
5870
"//third_party:grpc-java.patch",
5971
],
60-
strip_prefix = "grpc-java-1.79.0",
61-
url = "https://github.com/grpc/grpc-java/archive/refs/tags/v1.79.0.tar.gz",
72+
strip_prefix = "grpc-java-{}".format(GRPC_JAVA_VERSION),
73+
url = "https://github.com/grpc/grpc-java/archive/refs/tags/v{}.tar.gz".format(GRPC_JAVA_VERSION),
74+
)
75+
76+
# Precompiled protoc-gen-grpc-java plugin binaries from Maven Central.
77+
# These replace the cc_binary build of the plugin from C++ source,
78+
# eliminating the need for a C++ toolchain.
79+
http_file = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
80+
81+
_PROTOC_GEN_GRPC_JAVA_URL = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java/{v}/protoc-gen-grpc-java-{v}-{{platform}}.exe".format(v = GRPC_JAVA_VERSION)
82+
83+
http_file(
84+
name = "protoc_gen_grpc_java_linux_x86_64",
85+
executable = True,
86+
sha256 = "3d16b70b18854988b29c41e20d06ca3358c47008edb9e6986b926c5bca790816",
87+
url = _PROTOC_GEN_GRPC_JAVA_URL.format(platform = "linux-x86_64"),
88+
)
89+
90+
http_file(
91+
name = "protoc_gen_grpc_java_linux_aarch_64",
92+
executable = True,
93+
sha256 = "445b924ba4d3f55abd651f71017d592552be706b3918af0d7837b70468137473",
94+
url = _PROTOC_GEN_GRPC_JAVA_URL.format(platform = "linux-aarch_64"),
95+
)
96+
97+
http_file(
98+
name = "protoc_gen_grpc_java_osx_x86_64",
99+
executable = True,
100+
sha256 = "7b0dcbe2cbc02ebaf03e571eb295f43c0ba3d919b5d9e8fe34015846c9887289",
101+
url = _PROTOC_GEN_GRPC_JAVA_URL.format(platform = "osx-x86_64"),
102+
)
103+
104+
http_file(
105+
name = "protoc_gen_grpc_java_osx_aarch_64",
106+
executable = True,
107+
sha256 = "7b0dcbe2cbc02ebaf03e571eb295f43c0ba3d919b5d9e8fe34015846c9887289",
108+
url = _PROTOC_GEN_GRPC_JAVA_URL.format(platform = "osx-aarch_64"),
109+
)
110+
111+
http_file(
112+
name = "protoc_gen_grpc_java_windows_x86_64",
113+
executable = True,
114+
sha256 = "37a04cc3a35680bf17ba08e89d694d292f028e6f7ba24ef4b5bd8a1c43fa2e52",
115+
url = _PROTOC_GEN_GRPC_JAVA_URL.format(platform = "windows-x86_64"),
116+
)
117+
118+
# Precompiled protoc binaries from the protobuf release.
119+
# The java_grpc_library rule hard-codes a reference to protoc, so we provide
120+
# prebuilt binaries to avoid compiling protoc from C++ source.
121+
_PROTOC_URL = "https://github.com/protocolbuffers/protobuf/releases/download/v{v}/protoc-{v}-{{platform}}.zip".format(v = PROTOBUF_VERSION)
122+
123+
_PREBUILT_PROTOC_BUILD_FILE = """\
124+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
125+
package(default_visibility = ["//visibility:public"])
126+
native_binary(name = "protoc", src = "bin/protoc", out = "protoc_bin")
127+
"""
128+
129+
_PREBUILT_PROTOC_WIN_BUILD_FILE = """\
130+
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
131+
package(default_visibility = ["//visibility:public"])
132+
native_binary(name = "protoc", src = "bin/protoc.exe", out = "protoc_bin.exe")
133+
"""
134+
135+
http_archive(
136+
name = "prebuilt_protoc_linux_x86_64",
137+
build_file_content = _PREBUILT_PROTOC_BUILD_FILE,
138+
sha256 = "c0040ea9aef08fdeb2c74ca609b18d5fdbfc44ea0042fcfbfb38860d35f7dd66",
139+
url = _PROTOC_URL.format(platform = "linux-x86_64"),
140+
)
141+
142+
http_archive(
143+
name = "prebuilt_protoc_linux_aarch_64",
144+
build_file_content = _PREBUILT_PROTOC_BUILD_FILE,
145+
sha256 = "15aa988f4a6090636525ec236a8e4b3aab41eef402751bd5bb2df6afd9b7b5a5",
146+
url = _PROTOC_URL.format(platform = "linux-aarch_64"),
147+
)
148+
149+
http_archive(
150+
name = "prebuilt_protoc_osx_x86_64",
151+
build_file_content = _PREBUILT_PROTOC_BUILD_FILE,
152+
sha256 = "a49bec10d039e902d3b43e49938c42526f90011467609864fa6386ac4014da58",
153+
url = _PROTOC_URL.format(platform = "osx-x86_64"),
154+
)
155+
156+
http_archive(
157+
name = "prebuilt_protoc_osx_aarch_64",
158+
build_file_content = _PREBUILT_PROTOC_BUILD_FILE,
159+
sha256 = "726297dcfed58592fd35620a5a6246ae020c39e88f3fd4cb1827df7bcf3dfcf1",
160+
url = _PROTOC_URL.format(platform = "osx-aarch_64"),
161+
)
162+
163+
http_archive(
164+
name = "prebuilt_protoc_win64",
165+
build_file_content = _PREBUILT_PROTOC_WIN_BUILD_FILE,
166+
sha256 = "0b31be019b9fe45a388e93bf1f16d70afdf9ce5caf958ea47892fbc868b5a1b3",
167+
url = _PROTOC_URL.format(platform = "win64"),
62168
)
63169

64170
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")

java/gazelle/private/java_export_index/java_export_index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (jei *JavaExportIndex) FinalizeIndex() {
183183
conflictingExports := []string{conflict.wantedToExportFrom.String(), conflict.alreadyExportedFrom.String()}
184184
sort.Strings(conflictingExports)
185185

186-
jei.logger.Error().
186+
jei.logger.Warn().
187187
Str("dependency", conflict.dep.String()).
188188
Strs("java_exports", conflictingExports).
189189
Msg("Two `java_export` targets want to export the same dependency. This can lead to incorrect results, please disambiguate, e.g. by having export depend on other export explicitly.")

java/gazelle/resolve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ func (jr *Resolver) resolveSinglePackageWithAmbiguity(c *config.Config, pc *java
454454
return label.NoLabel, false
455455
}
456456

457-
jr.lang.logger.Warn().
457+
jr.lang.logger.Error().
458458
Str("package", imp.Name).
459459
Str("from rule", from.String()).
460460
Strs("classes", pkgClasses).
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
{"level":"error","label":"//other_deps/src/main/java/com/example/other_deps/plain_deps:plain_deps_export","message":"java_export rule contained a non-empty `srcs` attribute, but it will be ignored during resolution. Instead, please use the `exports` or `runtime_deps` attributes and depend on the generated `java_library`"}
2-
{"level":"error","dependency":"//shared_dep/src/main/java/com/example/shared_dep/shared_dep","java_exports":["//shared_dep/src/main/java/com/example/shared_dep/export_one","//shared_dep/src/main/java/com/example/shared_dep/export_two"],"message":"Two `java_export` targets want to export the same dependency. This can lead to incorrect results, please disambiguate, e.g. by having export depend on other export explicitly."}
2+
{"level":"warn","dependency":"//shared_dep/src/main/java/com/example/shared_dep/shared_dep","java_exports":["//shared_dep/src/main/java/com/example/shared_dep/export_one","//shared_dep/src/main/java/com/example/shared_dep/export_two"],"message":"Two `java_export` targets want to export the same dependency. This can lead to incorrect results, please disambiguate, e.g. by having export depend on other export explicitly."}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{"level":"warn","package":"com.idonotexist","from rule":"//src/main/java/com/example/hello","classes":["MyClass"],"message":"Unable to find package for import in any dependency"}
1+
{"level":"error","package":"com.idonotexist","from rule":"//src/main/java/com/example/hello","classes":["MyClass"],"message":"Unable to find package for import in any dependency"}
22
{"level":"fatal","message":"the java extension encountered errors that will create invalid build files"}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
Copied from
22
[bazelbuild/examples/java-maven](https://github.com/bazelbuild/examples/tree/b29794fb55f6714442dd86946c77f8908321a430/java-maven).
3+
4+
This fixture also covers same-package class references without imports in split source roots.
5+
`src/test/java/com/example/myproject/AppTest.java` references `App` as a bare type (`App app = ...`) with no import, which is valid because both files are in `com.example.myproject`.
6+
7+
`src/sample/java/com/example/myproject/SampleOnly.java` is intentionally present to create a second provider of `com.example.myproject` (in addition to `src/main`). That forces ambiguous package-level resolution and requires class-level disambiguation using `imported_classes`.
8+
9+
If the parser drops same-package bare type references, class-level input is missing and the test target can no longer reliably resolve to `//src/main/java/com/example/myproject` (the target that actually provides `App`). With the fix, `com.example.myproject.App` is retained and resolution succeeds.

0 commit comments

Comments
 (0)