From 47386ce4e616d0fdde25f03def9f41e88c37ab2f Mon Sep 17 00:00:00 2001 From: Bryce Date: Sun, 22 Mar 2026 09:26:43 -0700 Subject: [PATCH] Add build-jres.sh script for minimal JRE creation and update packr configs - Creates minimal JREs (~50MB vs ~300MB) using jlink - Downloads Corretto JDKs for specified Java version - Supports linux-x64, windows-x64, macos-x64, macos-arm64 - Note: Windows ARM64 not available from Corretto - Updates all packr configs to use minimal JREs - Adds macOS ARM64 build configs --- desktop/build-jres.sh | 241 +++++++++++++++++++++++++++++ desktop/build-linux-64-steam.json | 3 +- desktop/build-linux-64.json | 3 +- desktop/build-osx-arm64-steam.json | 12 ++ desktop/build-osx-arm64.json | 12 ++ desktop/build-osx-steam.json | 3 +- desktop/build-osx.json | 3 +- desktop/build-windows-steam.json | 3 +- desktop/build-windows.json | 3 +- 9 files changed, 271 insertions(+), 12 deletions(-) create mode 100755 desktop/build-jres.sh create mode 100644 desktop/build-osx-arm64-steam.json create mode 100644 desktop/build-osx-arm64.json diff --git a/desktop/build-jres.sh b/desktop/build-jres.sh new file mode 100755 index 00000000..c5d552ed --- /dev/null +++ b/desktop/build-jres.sh @@ -0,0 +1,241 @@ +#!/bin/bash + +set -e + +JAVA_VERSION="${1:-11}" +JVM_DIR="$(cd "$(dirname "$0")/jvms" && pwd)" +MODULES="java.base,java.desktop,java.logging,java.sql,java.xml,java.naming,java.management,jdk.unsupported" + +CORRETTO_BASE_URL="https://corretto.aws/downloads/latest" + +build_linux_x64() { + local platform="linux-x64" + local url="${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-linux-jdk.tar.gz" + local archive="${JVM_DIR}/corretto${JAVA_VERSION}-${platform}.tar.gz" + local extract_dir="${JVM_DIR}/tmp-${platform}" + local jre_dir="${JVM_DIR}/jre-${platform}" + + echo "=== Building $platform ===" + + echo "Downloading..." + curl -L -o "$archive" "$url" + + echo "Extracting..." + rm -rf "$extract_dir" "$jre_dir" + mkdir -p "$extract_dir" + tar -xzf "$archive" -C "$extract_dir" --strip-components=1 + + echo "Creating minimal JRE..." + "$extract_dir/bin/jlink" \ + --no-header-files \ + --no-man-pages \ + --compress=2 \ + --add-modules "$MODULES" \ + --output "$jre_dir" + + rm -rf "$extract_dir" + + echo "Done: $(du -sh "$jre_dir" | cut -f1)" + echo "" +} + +build_windows_x64() { + local platform="windows-x64" + local url="${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-windows-jdk.zip" + local archive="${JVM_DIR}/corretto${JAVA_VERSION}-${platform}.zip" + local extract_dir="${JVM_DIR}/tmp-${platform}" + local jre_dir="${JVM_DIR}/jre-${platform}" + local host_jdk="${JVM_DIR}/tmp-linux-x64" + + echo "=== Building $platform ===" + + if [ ! -d "$host_jdk" ]; then + echo "Downloading host JDK for jlink..." + local host_archive="${JVM_DIR}/corretto${JAVA_VERSION}-linux-x64.tar.gz" + curl -L -o "$host_archive" "${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-linux-jdk.tar.gz" + mkdir -p "$host_jdk" + tar -xzf "$host_archive" -C "$host_jdk" --strip-components=1 + fi + + echo "Downloading..." + curl -L -o "$archive" "$url" + + echo "Extracting..." + rm -rf "$extract_dir" "$jre_dir" + mkdir -p "$extract_dir" + unzip -q "$archive" -d "$extract_dir" + + local jdk_dir=$(find "$extract_dir" -maxdepth 1 -type d -name "jdk*" | head -1) + local jmods_path="$jdk_dir/jmods" + + echo "Creating minimal JRE..." + "$host_jdk/bin/jlink" \ + --no-header-files \ + --no-man-pages \ + --compress=2 \ + --add-modules "$MODULES" \ + --module-path "$jmods_path" \ + --output "$jre_dir" + + rm -rf "$extract_dir" + + echo "Done: $(du -sh "$jre_dir" | cut -f1)" + echo "" +} + +build_windows_arm64() { + echo "=== Building windows-arm64 ===" + echo "ERROR: Windows ARM64 JDK is not available from Amazon Corretto" + echo "Skipping..." + echo "" +} + +build_macos_x64() { + local platform="macos-x64" + local url="${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-macos-jdk.tar.gz" + local archive="${JVM_DIR}/corretto${JAVA_VERSION}-${platform}.tar.gz" + local extract_dir="${JVM_DIR}/tmp-${platform}" + local jre_dir="${JVM_DIR}/jre-${platform}" + local host_jdk="${JVM_DIR}/tmp-linux-x64" + + echo "=== Building $platform ===" + + if [ ! -d "$host_jdk" ]; then + echo "Downloading host JDK for jlink..." + local host_archive="${JVM_DIR}/corretto${JAVA_VERSION}-linux-x64.tar.gz" + curl -L -o "$host_archive" "${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-linux-jdk.tar.gz" + mkdir -p "$host_jdk" + tar -xzf "$host_archive" -C "$host_jdk" --strip-components=1 + fi + + echo "Downloading..." + curl -L -o "$archive" "$url" + + echo "Extracting..." + rm -rf "$extract_dir" "$jre_dir" + mkdir -p "$extract_dir" + tar -xzf "$archive" -C "$extract_dir" + + local jdk_dir=$(find "$extract_dir" -maxdepth 1 -type d -name "jdk*" -o -name "amazon-corretto*" | head -1) + local jmods_path="$jdk_dir/Contents/Home/jmods" + + if [ ! -d "$jmods_path" ]; then + jmods_path="$jdk_dir/jmods" + fi + + echo "Creating minimal JRE..." + "$host_jdk/bin/jlink" \ + --no-header-files \ + --no-man-pages \ + --compress=2 \ + --add-modules "$MODULES" \ + --module-path "$jmods_path" \ + --output "$jre_dir" + + rm -rf "$extract_dir" + + echo "Done: $(du -sh "$jre_dir" | cut -f1)" + echo "" +} + +build_macos_arm64() { + local platform="macos-arm64" + local url="${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-aarch64-macos-jdk.tar.gz" + local archive="${JVM_DIR}/corretto${JAVA_VERSION}-${platform}.tar.gz" + local extract_dir="${JVM_DIR}/tmp-${platform}" + local jre_dir="${JVM_DIR}/jre-${platform}" + local host_jdk="${JVM_DIR}/tmp-linux-x64" + + echo "=== Building $platform ===" + + if [ ! -d "$host_jdk" ]; then + echo "Downloading host JDK for jlink..." + local host_archive="${JVM_DIR}/corretto${JAVA_VERSION}-linux-x64.tar.gz" + curl -L -o "$host_archive" "${CORRETTO_BASE_URL}/amazon-corretto-${JAVA_VERSION}-x64-linux-jdk.tar.gz" + mkdir -p "$host_jdk" + tar -xzf "$host_archive" -C "$host_jdk" --strip-components=1 + fi + + echo "Downloading..." + curl -L -o "$archive" "$url" + + echo "Extracting..." + rm -rf "$extract_dir" "$jre_dir" + mkdir -p "$extract_dir" + tar -xzf "$archive" -C "$extract_dir" + + local jdk_dir=$(find "$extract_dir" -maxdepth 1 -type d -name "jdk*" -o -name "amazon-corretto*" | head -1) + local jmods_path="$jdk_dir/Contents/Home/jmods" + + if [ ! -d "$jmods_path" ]; then + jmods_path="$jdk_dir/jmods" + fi + + echo "Creating minimal JRE..." + "$host_jdk/bin/jlink" \ + --no-header-files \ + --no-man-pages \ + --compress=2 \ + --add-modules "$MODULES" \ + --module-path "$jmods_path" \ + --output "$jre_dir" + + rm -rf "$extract_dir" + + echo "Done: $(du -sh "$jre_dir" | cut -f1)" + echo "" +} + +main() { + mkdir -p "$JVM_DIR" + + local target="${2:-all}" + + echo "Building JREs for Java $JAVA_VERSION" + echo "Modules: $MODULES" + echo "Target: $target" + echo "" + + case "$target" in + linux-x64) + build_linux_x64 + ;; + windows-x64) + build_windows_x64 + ;; + windows-arm64) + build_windows_arm64 + ;; + macos-x64) + build_macos_x64 + ;; + macos-arm64) + build_macos_arm64 + ;; + all) + build_linux_x64 + build_windows_x64 + build_macos_x64 + build_macos_arm64 + ;; + *) + echo "Unknown target: $target" + echo "Valid targets: linux-x64, windows-x64, macos-x64, macos-arm64, all" + echo "Note: windows-arm64 is not available from Corretto" + exit 1 + ;; + esac + + echo "=== Summary ===" + for platform in linux-x64 windows-x64 macos-x64 macos-arm64; do + local jre_dir="${JVM_DIR}/jre-${platform}" + if [ -d "$jre_dir" ]; then + local size=$(du -sh "$jre_dir" | cut -f1) + echo "$platform: $size" + fi + done + + rm -rf "${JVM_DIR}/tmp-linux-x64" +} + +main "$@" diff --git a/desktop/build-linux-64-steam.json b/desktop/build-linux-64-steam.json index 59824dc8..33adfc13 100644 --- a/desktop/build-linux-64-steam.json +++ b/desktop/build-linux-64-steam.json @@ -1,11 +1,10 @@ { "platform": "linux64", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop"], - "jdk": "./jvms/corretto11-linux.tar.gz", + "jdk": "./jvms/jre-linux-x64", "executable": "Tick's Tales", "classpath": ["target/advent-standalone.jar"], "mainclass": "advent.core.desktop_launcher", "resources": ["steam_appid.txt", "resources/icon"], - "minimizejre": "soft", "output": "target/linux/amd64" } diff --git a/desktop/build-linux-64.json b/desktop/build-linux-64.json index 9d3f601b..48887336 100644 --- a/desktop/build-linux-64.json +++ b/desktop/build-linux-64.json @@ -1,11 +1,10 @@ { "platform": "linux64", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dno-steam=true", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop"], - "jdk": "./jvms/corretto11-linux.tar.gz", + "jdk": "./jvms/jre-linux-x64", "executable": "Tick's Tales", "classpath": ["target/advent-standalone.jar"], "mainclass": "advent.core.desktop_launcher", "resources": ["steam_appid.txt", "resources/icon"], - "minimizejre": "soft", "output": "target/linux/amd64" } diff --git a/desktop/build-osx-arm64-steam.json b/desktop/build-osx-arm64-steam.json new file mode 100644 index 00000000..28db1d60 --- /dev/null +++ b/desktop/build-osx-arm64-steam.json @@ -0,0 +1,12 @@ +{ + "platform": "mac", + "jdk": "./jvms/jre-macos-arm64", + "executable": "Tick's Tales", + "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop", "-XstartOnFirstThread"], + "classpath": ["target/advent-standalone.jar"], + "mainclass": "advent.core.desktop_launcher", + "resources": ["resources/icon", "steam_appid.txt"], + "output": "target/osx-arm64/Tick's Tales.app", + "bundle": "com.tickstales.upallknight", + "verbose": true +} diff --git a/desktop/build-osx-arm64.json b/desktop/build-osx-arm64.json new file mode 100644 index 00000000..4caebf7e --- /dev/null +++ b/desktop/build-osx-arm64.json @@ -0,0 +1,12 @@ +{ + "platform": "mac", + "jdk": "./jvms/jre-macos-arm64", + "executable": "Tick's Tales", + "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dno-steam=true", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop", "-XstartOnFirstThread"], + "classpath": ["target/advent-standalone.jar"], + "mainclass": "advent.core.desktop_launcher", + "resources": ["resources/icon", "steam_appid.txt"], + "output": "target/osx-arm64/Tick's Tales.app", + "bundle": "com.tickstales.upallknight", + "verbose": true +} diff --git a/desktop/build-osx-steam.json b/desktop/build-osx-steam.json index 102dc0df..1661910d 100644 --- a/desktop/build-osx-steam.json +++ b/desktop/build-osx-steam.json @@ -1,12 +1,11 @@ { "platform": "mac", - "jdk": "./jvms/corretto11-macos.tar.gz", + "jdk": "./jvms/jre-macos-x64", "executable": "Tick's Tales", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop", "-XstartOnFirstThread"], "classpath": ["target/advent-standalone.jar"], "mainclass": "advent.core.desktop_launcher", "resources": ["resources/icon", "steam_appid.txt"], - "minimizejre": "soft", "output": "target/osx/Tick's Tales.app", "bundle": "com.tickstales.upallknight", "verbose": true diff --git a/desktop/build-osx.json b/desktop/build-osx.json index 201321b7..c68e0013 100644 --- a/desktop/build-osx.json +++ b/desktop/build-osx.json @@ -1,12 +1,11 @@ { "platform": "mac", - "jdk": "./jvms/corretto11-macos.tar.gz", + "jdk": "./jvms/jre-macos-x64", "executable": "Tick's Tales", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dno-steam=true", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop", "-XstartOnFirstThread"], "classpath": ["target/advent-standalone.jar"], "mainclass": "advent.core.desktop_launcher", "resources": ["resources/icon", "steam_appid.txt"], - "minimizejre": "soft", "output": "target/osx/Tick's Tales.app", "bundle": "com.tickstales.upallknight", "verbose": true diff --git a/desktop/build-windows-steam.json b/desktop/build-windows-steam.json index b522b71a..ed08d441 100644 --- a/desktop/build-windows-steam.json +++ b/desktop/build-windows-steam.json @@ -1,11 +1,10 @@ { "platform": "windows64", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop"], - "jdk": "./jvms/corretto11-windows.zip", + "jdk": "./jvms/jre-windows-x64", "executable": "TicksTales", "mainclass": "advent.core.desktop_launcher", "resources": ["steam_appid.txt", "resources/icon"], "classpath": ["target/advent-standalone.jar"], - "minimizejre": "soft", "output": "target/windows/" } diff --git a/desktop/build-windows.json b/desktop/build-windows.json index bf96a04f..5a4e9945 100644 --- a/desktop/build-windows.json +++ b/desktop/build-windows.json @@ -1,11 +1,10 @@ { "platform": "windows64", "vmargs": ["-Duse-repl=false", "-Dui_scale=1.0", "-Dno-steam=true", "-Dclojure.compiler.direct-linking=true", "-Dis-desktop=true", "-Dplatform=desktop"], - "jdk": "./jvms/corretto11-windows.zip", + "jdk": "./jvms/jre-windows-x64", "executable": "TicksTales", "mainclass": "advent.core.desktop_launcher", "resources": ["steam_appid.txt", "resources/icon"], "classpath": ["target/advent-standalone.jar"], - "minimizejre": "soft", "output": "target/windows/" }