Skip to content

Commit 0f7154b

Browse files
fmeumcopybara-github
authored andcommitted
Correctly cross-jlink Windows arm64 builds (#28988)
### Description Download the extracted post-[JEP 493](https://openjdk.org/jeps/493) jmods for Windows ARM64 and add a safety check to ensure that we don't unknowingly jlink the tool JDK's jmods. ### Motivation Fixes #28941 ### Build API Changes No ### Checklist - [ ] I have added tests for the new use cases (if any). - [ ] I have updated the documentation (if applicable). ### Release Notes RELNOTES: None Closes #28988. PiperOrigin-RevId: 884547112 Change-Id: If6dadd9a23960d1dcceab6d487f4fc92911288f5
1 parent e46bed7 commit 0f7154b

File tree

5 files changed

+68
-5
lines changed

5 files changed

+68
-5
lines changed

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ use_repo(
369369
"openjdk_linux_vanilla",
370370
"openjdk_macos_aarch64_vanilla",
371371
"openjdk_macos_x86_64_vanilla",
372+
"openjdk_win_arm64_jmods",
372373
"openjdk_win_arm64_vanilla",
373374
"openjdk_win_vanilla",
374375
)

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

repositories.bzl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ def embedded_jdk_repositories():
138138
url = "https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.3%2B1-ea-beta/OpenJDK25U-jdk_aarch64_windows_hotspot_25.0.3_1-ea.zip",
139139
)
140140

141+
# The Adoptium Temurin JDK above has JEP 493 enabled, which means it does not ship with jmods.
142+
# These are needed for cross-jlinking (minimizing the JDK on a different platform).
143+
# https://adoptium.net/news/2025/08/eclipse-temurin-jdk24-JEP493-enabled
144+
http_file(
145+
name = "openjdk_win_arm64_jmods",
146+
integrity = "sha256-2rjwZCoUIYD7L9nLwLJindsYPkDMvpI4km5a9UlxFtg=",
147+
downloaded_file_path = "temurin-win-arm64-jmods.zip",
148+
url = "https://github.com/adoptium/temurin25-binaries/releases/download/jdk-25.0.3%2B1-ea-beta/OpenJDK25U-jmods_aarch64_windows_hotspot_25.0.3_1-ea.zip",
149+
)
150+
141151
def _async_profiler_repos(ctx):
142152
http_file(
143153
name = "async_profiler",

src/BUILD

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,15 @@ genrule(
235235
srcs = [
236236
":embedded_jdk_vanilla",
237237
":jdeps_modules.golden",
238-
],
238+
] + select({
239+
"//src/conditions:windows_arm64": ["@openjdk_win_arm64_jmods//file"],
240+
"//conditions:default": [],
241+
}),
239242
outs = ["minimal_jdk.zip"],
240-
cmd = "$(location :minimize_jdk) $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@",
243+
cmd = "$(location :minimize_jdk) $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@" + select({
244+
"//src/conditions:windows_arm64": " $(location @openjdk_win_arm64_jmods//file)",
245+
"//conditions:default": "",
246+
}),
241247
tools = [
242248
":jdk_for_jlink",
243249
":minimize_jdk",
@@ -250,9 +256,15 @@ genrule(
250256
srcs = [
251257
":embedded_jdk_vanilla",
252258
":jdeps_modules.golden",
253-
],
259+
] + select({
260+
"//src/conditions:windows_arm64": ["@openjdk_win_arm64_jmods//file"],
261+
"//conditions:default": [],
262+
}),
254263
outs = ["allmodules_jdk.zip"],
255-
cmd = "$(location :minimize_jdk) --allmodules $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@",
264+
cmd = "$(location :minimize_jdk) --allmodules $(location :jdk_for_jlink) $(location :embedded_jdk_vanilla) $(location :jdeps_modules.golden) $@" + select({
265+
"//src/conditions:windows_arm64": " $(location @openjdk_win_arm64_jmods//file)",
266+
"//conditions:default": "",
267+
}),
256268
tools = [
257269
":jdk_for_jlink",
258270
":minimize_jdk",

src/minimize_jdk.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ fi
5050
tooljdk=$1
5151
fulljdk=$2
5252
out=$4
53+
# Optional 5th argument: a separate jmods archive for JDKs that don't ship
54+
# with jmods (e.g. Adoptium Temurin with JEP 493 enabled).
55+
jmods_archive=${5:-}
56+
# Convert to absolute path since we cd later.
57+
if [ -n "$jmods_archive" ]; then
58+
jmods_archive=$(cd "$(dirname "$jmods_archive")" && echo "$(pwd)/$(basename "$jmods_archive")")
59+
fi
5360

5461
UNAME=$(uname -s | tr 'A-Z' 'a-z')
5562
# Options for the JVM that runs the Bazel server, which are either required or
@@ -66,6 +73,25 @@ if [[ "$UNAME" =~ msys_nt* ]]; then
6673
# The archives contain a single top-level directory.
6774
tool_jdk_home=$(cd tool_jdk.$$/* && pwd)
6875
cd full_jdk.$$/*
76+
# If the full JDK doesn't ship with jmods (e.g. JEP 493), use the separately
77+
# provided jmods archive.
78+
if [ ! -f jmods/java.base.jmod ]; then
79+
if [ -n "$jmods_archive" ]; then
80+
unzip -q "$jmods_archive" -d jmods_tmp
81+
# The archive contains a single top-level directory with jmod files.
82+
mv jmods_tmp/*/* jmods_tmp/ 2>/dev/null || true
83+
# Move all .jmod files into the jmods directory.
84+
mkdir -p jmods
85+
mv jmods_tmp/*.jmod jmods/
86+
rm -rf jmods_tmp
87+
else
88+
echo >&2 "ERROR: Full JDK does not contain jmods/java.base.jmod and no" \
89+
"separate jmods archive was provided. Cross-jlinking requires jmods." \
90+
"JDKs with JEP 493 enabled (e.g. Adoptium Temurin 24+) need a separate" \
91+
"jmods download."
92+
exit 1
93+
fi
94+
fi
6995
# We have to add this module explicitly because it is windows specific, it allows
7096
# the usage of the Windows truststore
7197
# e.g. -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT
@@ -98,6 +124,20 @@ else
98124
mkdir target_jdk
99125
tar xf "$fulljdk" --no-same-owner --strip-components=1 -C target_jdk
100126
cd target_jdk
127+
# If the full JDK doesn't ship with jmods (e.g. JEP 493), use the separately
128+
# provided jmods archive.
129+
if [ ! -f jmods/java.base.jmod ]; then
130+
if [ -n "$jmods_archive" ]; then
131+
mkdir -p jmods
132+
tar xf "$jmods_archive" --no-same-owner --strip-components=1 -C jmods --wildcards '*.jmod'
133+
else
134+
echo >&2 "ERROR: Full JDK does not contain jmods/java.base.jmod and no" \
135+
"separate jmods archive was provided. Cross-jlinking requires jmods." \
136+
"JDKs with JEP 493 enabled (e.g. Adoptium Temurin 24+) need a separate" \
137+
"jmods download."
138+
exit 1
139+
fi
140+
fi
101141
"../tool_jdk/bin/jlink" --module-path ./jmods/ --add-modules "$modules" \
102142
--vm=server --strip-debug --no-man-pages --no-header-files \
103143
--add-options=" ${JVM_OPTIONS}" \

0 commit comments

Comments
 (0)