Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Java Runtime Universal Binary (x86_64+arm64)
#!/bin/sh -e
UNIVERSAL_JDK=$(pwd)/$3
ARM64_JDK=$(pwd)/$1
X86_64_JDK=$(pwd)/$2
${ARM64_JDK}/Contents/Home/bin/jlink --add-modules ALL-MODULE-PATH --strip-debug --no-man-pages --no-header-files --compress=2 --output ${ARM64_JDK}/Contents/jre
rm -rf ${ARM64_JDK}/Contents/Home
mv ${ARM64_JDK}/Contents/jre ${ARM64_JDK}/Contents/Home
${X86_64_JDK}/Contents/Home/bin/jlink --add-modules ALL-MODULE-PATH --strip-debug --no-man-pages --no-header-files --compress=2 --output ${X86_64_JDK}/Contents/jre
rm -rf ${X86_64_JDK}/Contents/Home
mv ${X86_64_JDK}/Contents/jre ${X86_64_JDK}/Contents/Home
# We ditto both in case there is something present in one but not both.
ditto ${ARM64_JDK} ${UNIVERSAL_JDK}
ditto ${X86_64_JDK} ${UNIVERSAL_JDK}
for subdir in MacOS Home/bin Home/lib ; do
pushd ${UNIVERSAL_JDK}/Contents/${subdir}
find . -type f | while read file ; do
FILE_TYPE=$(file "${file}")
[[ ${FILE_TYPE} =~ "Mach-O" ]] || continue
if [[ -f "${ARM64_JDK}/Contents/${subdir}/${file}" && -f "${X86_64_JDK}/Contents/${subdir}/${file}" ]] ; then
lipo -output ${file} -create ${ARM64_JDK}/Contents/${subdir}/${file} ${X86_64_JDK}/Contents/${subdir}/${file}
fi
done
done
sed -i '' 's:x86_64:x86_64+arm64:' ${UNIVERSAL_JDK}/Contents/Home/release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment