Compare commits

..

2 Commits

Author SHA1 Message Date
e1f937bb2c Merge pull request 'Adding support to build x64 application on linux aarch64 architecture' (#9) from feature/support_arm_as_build_system_for_x64 into develop
All checks were successful
continuous-integration/drone Build is passing
Reviewed-on: #9
2024-05-13 08:08:31 +02:00
david
83e17c9c42 Adding support to build x64 application on linux aarch64 architecture
All checks were successful
continuous-integration/drone/pr Build is passing
2024-05-13 08:05:17 +02:00

103
warp4j
View File

@ -93,6 +93,22 @@ function get_this_platform() {
esac
}
# platform Machine
X64=x64
AARCH64=aarch64
# returns this platform machine
function get_this_machine() {
local this_machine="$(uname -m)"
case $this_machine in
x86_64) echo $X64 ;;
aarch64) echo $AARCH64 ;;
*)
fail_with "Unsupported machine $this_machine"
;;
esac
}
# show help if no arguments specified
if [[ $# -eq 0 ]]; then
print_help
@ -169,6 +185,7 @@ done
set -- "${POSITIONAL[@]}" # restore positional arguments
THIS_PLATFORM=$(get_this_platform)
THIS_MACHINE=$(get_this_machine)
# checks if all dependencies are available
function check_deps() {
@ -260,15 +277,15 @@ JAVA_DISTRO_TYPE=$(choose_distro_type)
# generates adoptium api url
function api_url() {
local request=$1 # info/binary
local platform=$2 # windows/linux/macos
local platform=$1 # windows/linux/macos
local architecture=$2
# adoptium uses "mac" instead of "macos"
if [[ $platform == "macos" ]]; then
platform="mac"
fi
echo -n "https://api.adoptium.net/v3/assets/feature_releases/\
$JAVA_VERSION_BASE/ga?architecture=x64&heap_size=normal&image_type=jdk&\
$JAVA_VERSION_BASE/ga?architecture=$architecture&heap_size=normal&image_type=jdk&\
os=$platform&page=0&page_size=20&project=$JAVA_DISTRO_TYPE&\
sort_method=DEFAULT&sort_order=DESC&vendor=eclipse"
@ -277,8 +294,9 @@ sort_method=DEFAULT&sort_order=DESC&vendor=eclipse"
# requests info about all releases for given platform and java branch
function fetch_distro_info() {
local platform=$1 # platform ID
local branch=$2 # 8/9/10/11...
curl -s $(api_url info $platform)
local architecture=$2
local branch=$3 # 8/9/10/11...
curl -s $(api_url $platform $architecture)
fail_if $? "Failed to fetch java $branch info"
}
@ -308,7 +326,7 @@ function list_releases() {
local matched
local printed
local platform="linux" # just picked any
info=$(fetch_distro_info $platform $JAVA_VERSION_BASE)
info=$(fetch_distro_info $platform $X64 $JAVA_VERSION_BASE)
matched=$(find_matched_versions "$info" $JAVA_VERSION)
if [[ $matched ]]; then
echo "Releases that match $JAVA_VERSION:"
@ -329,8 +347,8 @@ if [[ $LIST_RELEASES ]]; then
exit
fi
JAR_FILE_BASE_NAME=$(basename -- "$JAR") # "my-app.jAr"
JAR_EXTENSION="${JAR_FILE_BASE_NAME##*.}" # "jAr"
JAR_FILE_BASE_NAME=$(basename -- "$JAR") # "my-app.jar"
JAR_EXTENSION="${JAR_FILE_BASE_NAME##*.}" # "jar"
JAR_EXTENSION_LOWERCASE=$(printf "%s" "$JAR_EXTENSION" | tr '[:upper:]' '[:lower:]') # "jar"
JAR_NAME="${JAR_FILE_BASE_NAME%.*}" # "my-app"
@ -352,7 +370,8 @@ fi
# even if this platform is not targeted, we still need
# a JDK for this platform to optimize JDKs for other platforms
TARGETS_TO_CACHE=${TARGETS[@]}
if [[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]] && # if usind JDK (not JRE)
if [[ $THIS_MACHINE == $X64 ]] && # if architecture is x86
[[ $JAVA_DISTRO_TYPE == $DISTRO_TYPE_JDK ]] && # and if using JDK (not JRE)
[[ ${TARGETS[@]} != *"$THIS_PLATFORM"* ]]; then # and this platform is not targeted
TARGETS_TO_CACHE+=($THIS_PLATFORM)
fi
@ -430,8 +449,9 @@ MARKER_UNPACKED="unpacked" # after runtime uncompress
# returns latest cached version that matches version specified by user
function find_latest_cached() {
local platform=$1
local user_version=$2
local platform_dir=$JAVA_DOWNLOAD_PATH/$platform/
local architecture=$2
local user_version=$3
local platform_dir=$JAVA_DOWNLOAD_PATH/$platform/$architecture
# turning something like "11.0.1+13" into regexp like "^11\.0\.1\+13"
local pattern="^"$(echo $user_version \
| sed -e 's/\./\\\./g' -e 's/\+/\\\+/g')
@ -498,9 +518,11 @@ function find_distro_link() {
# downloads runtime distro
function download_distro() {
local platform=$1
local version=$2
local link=$3
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$version
local architecture=$2
local version=$3
local link=$4
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$architecture/$version
echo "Download link: $link"
echo "Downloading $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform..."
rm -rf "$download_dir"
mkdir -p "$download_dir"
@ -517,55 +539,61 @@ function download_distro() {
# ensures required distro is in cache
function ensure_distro_cached() {
local platform=$1
local architecture=$2
local distro_info
local distro_link
if [[ -z $PULL ]]; then
if [[ -z $JAVA_VERSION_OVERRIDEN ]]; then
if [[ ! $(find_latest_cached $platform $LATEST_LTS) ]]; then
distro_info=$(fetch_distro_info $platform $LATEST_LTS)
if [[ ! $(find_latest_cached $platform $architecture $LATEST_LTS) ]]; then
distro_info=$(fetch_distro_info $platform $architecture $LATEST_LTS)
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $LATEST_LTS)
distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION)
download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link"
download_distro $platform $architecture $CONCRETE_JAVA_VERSION "$distro_link"
else
CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $LATEST_LTS)
CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $architecture $LATEST_LTS)
fi
else
if [[ ! $(find_latest_cached $platform $JAVA_VERSION) ]]; then
distro_info=$(fetch_distro_info $platform $JAVA_VERSION_BASE)
if [[ ! $(find_latest_cached $platform $architecture $JAVA_VERSION) ]]; then
distro_info=$(fetch_distro_info $platform $architecture $JAVA_VERSION_BASE)
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $JAVA_VERSION)
distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION)
download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link"
download_distro $platform $architecture $CONCRETE_JAVA_VERSION "$distro_link"
else
CONCRETE_JAVA_VERSION=$(find_latest_cached $platform $JAVA_VERSION)
CONCRETE_JAVA_VERSION=$(find_latest_cached $architecture $platform $JAVA_VERSION)
fi
fi
else
if [[ -z $JAVA_VERSION ]]; then
distro_info=$(fetch_distro_info $platform $LATEST_LTS)
distro_info=$(fetch_distro_info $platform $architecture $LATEST_LTS)
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $LATEST_LTS)
else
distro_info=$(fetch_distro_info $platform $JAVA_VERSION_BASE)
distro_info=$(fetch_distro_info $platform $architecture $JAVA_VERSION_BASE)
CONCRETE_JAVA_VERSION=$(find_latest_version "$distro_info" $JAVA_VERSION)
fi
if [[ ! $(find_latest_cached $platform $CONCRETE_JAVA_VERSION) ]]; then
if [[ ! $(find_latest_cached $platform $architecture $CONCRETE_JAVA_VERSION) ]]; then
distro_link=$(find_distro_link "$distro_info" $CONCRETE_JAVA_VERSION)
download_distro $platform $CONCRETE_JAVA_VERSION "$distro_link"
download_distro $platform $architecture $CONCRETE_JAVA_VERSION "$distro_link"
fi
fi
}
# actually ensure required distro is in cache
for target in ${TARGETS_TO_CACHE[@]}; do
ensure_distro_cached $target
ensure_distro_cached $target $X64
done
if [[ $THIS_MACHINE == $AARCH64 ]]; then
ensure_distro_cached $THIS_PLATFORM $AARCH64
fi
UNPACKED_SUBDIR="distro"
# ensures required distro uncompressed
function ensure_distro_unpacked() {
local platform=$1
local version=$2
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$version
local architecture=$2
local version=$3
local download_dir=$JAVA_DOWNLOAD_PATH/$platform/$architecture/$version
local unpacked_dir=$download_dir/$UNPACKED_SUBDIR
if [[ ! -e $download_dir/$MARKER_UNPACKED ]]; then
echo "Uncompressing $JVM_IMPL-$JAVA_DISTRO_TYPE-$version-$platform"
@ -616,10 +644,15 @@ function ensure_distro_unpacked() {
# actually ensure required distro uncompressed
for target in ${TARGETS[@]}; do
ensure_distro_unpacked $target $CONCRETE_JAVA_VERSION
ensure_distro_unpacked $target $X64 $CONCRETE_JAVA_VERSION
done
JDK_PATH=$JAVA_DOWNLOAD_PATH/$THIS_PLATFORM/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR
# actually ensure required distro for build is uncompressed when it is not x64
if [[ $THIS_MACHINE == $AARCH64 ]]; then
ensure_distro_unpacked $THIS_PLATFORM $AARCH64 $CONCRETE_JAVA_VERSION
fi
JDK_PATH=$JAVA_DOWNLOAD_PATH/$THIS_PLATFORM/$THIS_MACHINE/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR
JLINK=$JDK_PATH/bin/jlink
JDEPS=$JDK_PATH/bin/jdeps
@ -647,7 +680,8 @@ fi
# creates minimized runtime for the platform
function create_optimized_runtime() {
local platform=$1
local jmods=$JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/jmods
local machine=$2
local jmods=$JAVA_DOWNLOAD_PATH/$platform/$machine/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR/jmods
echo "Creating minimal runtime for $platform..."
"$JLINK" \
--no-header-files \
@ -655,13 +689,14 @@ function create_optimized_runtime() {
--strip-debug \
--module-path "$jmods" \
--add-modules $MODULES \
--output "$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR"
--output "$BUNDLES_PATH/$platform/$machine/$BUNDLED_DISTRO_SUBDIR"
fail_if $? "Failed to optimize runtime"
}
# creates warp bundle for the platform
function create_bundle() {
local platform=$1
local machine=$2
if [[ $SILENT ]] && [[ $platform == $WIN ]]; then
JAVA_EXEC=javaw
@ -674,7 +709,7 @@ function create_bundle() {
create_optimized_runtime $platform
;;
$DISTRO_TYPE_JRE)
mkdir -p "$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR"
mkdir -p "$BUNDLES_PATH/$platform/$machine/$BUNDLED_DISTRO_SUBDIR"
cp -r "$JAVA_DOWNLOAD_PATH/$platform/$CONCRETE_JAVA_VERSION/$UNPACKED_SUBDIR"/* \
"$BUNDLES_PATH/$platform/$BUNDLED_DISTRO_SUBDIR"
;;