Skip to content

Run rules_jvm_external jar tools with exec Java#30147

Open
dzbarsky wants to merge 1 commit into
bazelbuild:masterfrom
dzbarsky:codex/rules-jvm-external-exec-java-bootstrap
Open

Run rules_jvm_external jar tools with exec Java#30147
dzbarsky wants to merge 1 commit into
bazelbuild:masterfrom
dzbarsky:codex/rules-jvm-external-exec-java-bootstrap

Conversation

@dzbarsky

@dzbarsky dzbarsky commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary

  • patch rules_jvm_external 6.8 so jvm_import runs AddJarManifestEntry_deploy.jar with current_java_runtime in the exec configuration
  • use local_jdk for bootstrap Java runtimes so the offline source distribution build does not fetch remote JDK 21 archives
  • update MODULE.bazel.lock

Motivation

This replaces #29764, which was erased from master after an accidental GitHub merge. Invoking the deploy JAR through current_java_runtime avoids executing the generated Bash launcher on a Windows host with Linux remote execution. The new runtime dependency made //src/test/shell/bazel:bazel_bootstrap_distfile_test resolve remotejdk21_*, which is intentionally absent from the offline distribution repository cache; the bootstrap already requires JAVA_HOME, so selecting local_jdk keeps the bootstrap offline while retaining Java language level 21.

The corresponding upstream change is bazel-contrib/rules_jvm_external#1583.

Validation

  • bazel test //src/test/shell/bazel:bazel_bootstrap_distfile_test with JDK 21 (passed in 1671.2s)
  • bazel mod deps --lockfile_mode=error
  • bash -n scripts/bootstrap/bootstrap.sh

Invoke AddJarManifestEntry_deploy.jar with current_java_runtime in the exec configuration instead of executing the AddJarManifestEntry java_binary launcher. This preserves --tool_java_runtime_version and selects Java for the execution platform when the target and execution architectures differ.

Treat AddJarManifestEntry_deploy.jar and JavaRuntimeInfo.files as action tools, and preserve the AddJarManifestEntry -XX:-UsePerfData JVM flag.

Use local_jdk for bootstrap Java runtimes so the offline source distribution build does not download remote JDK 21 archives after jvm_import begins using current_java_runtime.

Test: bazel test //src/test/shell/bazel:bazel_bootstrap_distfile_test
@dzbarsky dzbarsky marked this pull request as ready for review July 6, 2026 23:04
@github-actions github-actions Bot added area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling awaiting-review PR is awaiting review from an assigned reviewer labels Jul 6, 2026
@dzbarsky

dzbarsky commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

@Wyverald @fmeum PTAL - resending this since it got deleted, confirmed manual bootstrap test passes

@fmeum fmeum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, but I would like to understand better why the changes result in the bootstrap build fetching a remotejdk when it previously didn't. Could you explain this in more detail in the PR description?

@github-actions github-actions Bot added the community-reviewed Reviewed by a trusted community contributor label Jul 7, 2026
@meisterT meisterT requested a review from hvadehra July 7, 2026 07:19

: ${JAVA_VERSION:="21"}

# The bootstrap runs offline and already requires JAVA_HOME, so use the local JDK for Java actions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should already be the case. Do you know what's going wrong?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JAVA_HOME already supplies the JDK used by scripts/bootstrap/BUILD.bootstrap, but the new @rules_java//toolchains:current_java_runtime dependency performs separate Java runtime toolchain resolution. The existing --java_runtime_version=21 and --tool_java_runtime_version=21 select local_jdk only when JAVA_HOME contains JDK 21. The bootstrap accepts any JDK >= 21, so with JDK 25 I reproduced toolchain resolution rejecting @@rules_java++toolchains+local_jdk//:runtime_toolchain_definition because its detected version is 25 and selecting @@rules_java++toolchains+remotejdk21_macos_aarch64//:jdk instead. That repository is intentionally absent from the offline bootstrap repository cache, so the nested bootstrap tries to download it and fails.

Selecting local_jdk by name makes both runtime selectors use JAVA_HOME regardless of its newer major version. The Java language selectors remain 21, and scripts/bootstrap/compile.sh checks that JAVA_HOME is at least that version. I also verified the inverse toolchain result: with both runtime selectors set to local_jdk, the JDK 25 run selects @@rules_java++toolchains+local_jdk//:jdk.

-zbarskybot

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reasoning does not sound right to me. I'll look further into this and report back.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30106 also runs into similar issues. It would be great to have more direct (in particular, early) checks for the expected host-provided dependencies of the bootstrap build.

@hvadehra hvadehra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try running //src/test/shell/bazel:bazel_determinism_test on this as well?


: ${JAVA_VERSION:="21"}

# The bootstrap runs offline and already requires JAVA_HOME, so use the local JDK for Java actions.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reasoning does not sound right to me. I'll look further into this and report back.

@dzbarsky

dzbarsky commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Confirmed at 3e7556408ff2d078996a2141c6d09eab188e5c08: //src/test/shell/bazel:bazel_determinism_test passes on macOS arm64 with JDK 21 (PASSED in 1926.8s). The two Bazel builds produced identical output hashes.

I ran the test action locally and disabled the test harness's forced IPv6 preference because this host advertises an IPv6 default route but cannot reach bcr.bazel.build over it; the initial attempts failed during registry fetches before either build. No PR change is needed.

-zbarskybot

@fmeum fmeum mentioned this pull request Jul 7, 2026
2 tasks
@iancha1992 iancha1992 added the team-Rules-Java Issues for Java rules label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-EngProd Bazel CI, infrastructure, bootstrapping, release, and distribution tooling awaiting-review PR is awaiting review from an assigned reviewer community-reviewed Reviewed by a trusted community contributor team-Rules-Java Issues for Java rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants