From 40b4b12753fe6179ab91c1d722ced8fc75d47687 Mon Sep 17 00:00:00 2001 From: Haroon Khel <34969545+Haroon-Khel@users.noreply.github.com> Date: Tue, 10 Oct 2023 21:51:06 +0800 Subject: [PATCH] Add code to cross compile x64 jdk8 on arm64 mac (#3492) * Add cross compile steps for x64 jdk8 on m1 macs * syntax error * syntax error * resolve linter error * add export * make link to xcode11.7 using - instead of _ * Update build-farm/platform-specific-configurations/mac.sh Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> * Update build-farm/platform-specific-configurations/mac.sh Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> * debug * wrong uname flag * add MAC_ROSETTA_PREFIX to the echo command * temp fix for xcode switch so I can run the tests with the build * add /opt/homebrew/bin to beginning of PATH jdk8 mac build * add /opt/homebrew/bin to beginning of PATH jdk8 mac build on arm machines * remove debug --------- Co-authored-by: Stewart X Addison <6487691+sxa@users.noreply.github.com> --- .github/workflows/build.yml | 1 + build-farm/make-adopt-build-farm.sh | 7 ++++--- build-farm/platform-specific-configurations/mac.sh | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b06351200..13cd50c9f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -135,6 +135,7 @@ jobs: run: | rm -rf /Applications/Xcode.app ln -s /Applications/Xcode_11.7.app /Applications/Xcode.app + ln -s /Applications/Xcode_11.7.app /Applications/Xcode-11.7.app - name: Build macOS run: | diff --git a/build-farm/make-adopt-build-farm.sh b/build-farm/make-adopt-build-farm.sh index 7170eab15..4d8f2e1a4 100755 --- a/build-farm/make-adopt-build-farm.sh +++ b/build-farm/make-adopt-build-farm.sh @@ -32,7 +32,7 @@ if [ -z "$ARCHITECTURE" ]; then if [ "$ARCHITECTURE" = "powerpc" ]; then ARCHITECTURE=ppc64; fi # AIX if [ "$ARCHITECTURE" = "arm" ]; then ARCHITECTURE=aarch64; fi # mac/aarch64 if [ "$ARCHITECTURE" = "armv7l" ]; then ARCHITECTURE=arm; fi # Linux/arm32 - echo ARCHITECTURE not defined - assuming $ARCHITECTURE + echo ARCHITECTURE not defined - assuming "$ARCHITECTURE" export ARCHITECTURE fi @@ -132,6 +132,7 @@ CONFIGURE_ARGS_FOR_ANY_PLATFORM="" CONFIGURE_ARGS=${CONFIGURE_ARGS:-""} BUILD_ARGS=${BUILD_ARGS:-""} VARIANT_ARG="" +MAC_ROSETTA_PREFIX="" if [ -z "${JDK_BOOT_VERSION}" ] then @@ -238,11 +239,11 @@ if [ "${JAVA_FEATURE_VERSION}" -lt 16 ]; then export BUILD_ARGS="${BUILD_ARGS} --create-jre-image" fi -echo "$PLATFORM_SCRIPT_DIR/../makejdk-any-platform.sh --clean-git-repo --jdk-boot-dir ${JDK_BOOT_DIR} --configure-args ${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --target-file-name ${FILENAME} ${TAG_OPTION} ${OPTIONS} ${BUILD_ARGS} ${VARIANT_ARG} ${JAVA_TO_BUILD}" +echo "$MAC_ROSETTA_PREFIX $PLATFORM_SCRIPT_DIR/../makejdk-any-platform.sh --clean-git-repo --jdk-boot-dir ${JDK_BOOT_DIR} --configure-args ${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --target-file-name ${FILENAME} ${TAG_OPTION} ${OPTIONS} ${BUILD_ARGS} ${VARIANT_ARG} ${JAVA_TO_BUILD}" # Convert all speech marks in config args to make them safe to pass in. # These will be converted back into speech marks shortly before we use them, in build.sh. CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM//\"/temporary_speech_mark_placeholder}" # shellcheck disable=SC2086 -bash -c "$PLATFORM_SCRIPT_DIR/../makejdk-any-platform.sh --clean-git-repo --jdk-boot-dir ${JDK_BOOT_DIR} --configure-args \"${CONFIGURE_ARGS_FOR_ANY_PLATFORM}\" --target-file-name ${FILENAME} ${TAG_OPTION} ${OPTIONS} ${BUILD_ARGS} ${VARIANT_ARG} ${JAVA_TO_BUILD}" +bash -c "$MAC_ROSETTA_PREFIX $PLATFORM_SCRIPT_DIR/../makejdk-any-platform.sh --clean-git-repo --jdk-boot-dir ${JDK_BOOT_DIR} --configure-args \"${CONFIGURE_ARGS_FOR_ANY_PLATFORM}\" --target-file-name ${FILENAME} ${TAG_OPTION} ${OPTIONS} ${BUILD_ARGS} ${VARIANT_ARG} ${JAVA_TO_BUILD}" \ No newline at end of file diff --git a/build-farm/platform-specific-configurations/mac.sh b/build-farm/platform-specific-configurations/mac.sh index 94a7bab40..c519f8a5f 100755 --- a/build-farm/platform-specific-configurations/mac.sh +++ b/build-farm/platform-specific-configurations/mac.sh @@ -22,10 +22,19 @@ source "$SCRIPT_DIR/../../sbin/common/constants.sh" export MACOSX_DEPLOYMENT_TARGET=10.9 export BUILD_ARGS="${BUILD_ARGS}" +## JDK8 only: If, at this point in the build, the architecure of the machine is arm64 while the ARCHITECTURE variable +## is x64 then we need to add the cross compilation option --openjdk-target=x86_64-apple-darwin +MACHINEARCHITECTURE=$(uname -m) + if [ "${JAVA_TO_BUILD}" == "${JDK8_VERSION}" ] then - XCODE_SWITCH_PATH="/Applications/Xcode.app" + XCODE_SWITCH_PATH="/Applications/Xcode-11.7.app" export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --with-toolchain-type=clang" + if [[ "${MACHINEARCHITECTURE}" == "arm64" ]] && [[ "${ARCHITECTURE}" == "x64" ]]; then + export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --openjdk-target=x86_64-apple-darwin" + export MAC_ROSETTA_PREFIX="arch -x86_64" + export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH + fi if [ "${VARIANT}" == "${BUILD_VARIANT_OPENJ9}" ]; then export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --with-openssl=fetched --enable-openssl-bundling" export BUILD_ARGS="${BUILD_ARGS} --skip-freetype"