Skip to content

Commit 40b4b12

Browse files
Haroon-Khelsxa
andauthored
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 <[email protected]> * Update build-farm/platform-specific-configurations/mac.sh Co-authored-by: Stewart X Addison <[email protected]> * 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 <[email protected]>
1 parent c5a4237 commit 40b4b12

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ jobs:
135135
run: |
136136
rm -rf /Applications/Xcode.app
137137
ln -s /Applications/Xcode_11.7.app /Applications/Xcode.app
138+
ln -s /Applications/Xcode_11.7.app /Applications/Xcode-11.7.app
138139
139140
- name: Build macOS
140141
run: |

build-farm/make-adopt-build-farm.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if [ -z "$ARCHITECTURE" ]; then
3232
if [ "$ARCHITECTURE" = "powerpc" ]; then ARCHITECTURE=ppc64; fi # AIX
3333
if [ "$ARCHITECTURE" = "arm" ]; then ARCHITECTURE=aarch64; fi # mac/aarch64
3434
if [ "$ARCHITECTURE" = "armv7l" ]; then ARCHITECTURE=arm; fi # Linux/arm32
35-
echo ARCHITECTURE not defined - assuming $ARCHITECTURE
35+
echo ARCHITECTURE not defined - assuming "$ARCHITECTURE"
3636
export ARCHITECTURE
3737
fi
3838

@@ -132,6 +132,7 @@ CONFIGURE_ARGS_FOR_ANY_PLATFORM=""
132132
CONFIGURE_ARGS=${CONFIGURE_ARGS:-""}
133133
BUILD_ARGS=${BUILD_ARGS:-""}
134134
VARIANT_ARG=""
135+
MAC_ROSETTA_PREFIX=""
135136

136137
if [ -z "${JDK_BOOT_VERSION}" ]
137138
then
@@ -238,11 +239,11 @@ if [ "${JAVA_FEATURE_VERSION}" -lt 16 ]; then
238239
export BUILD_ARGS="${BUILD_ARGS} --create-jre-image"
239240
fi
240241

241-
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}"
242+
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}"
242243

243244
# Convert all speech marks in config args to make them safe to pass in.
244245
# These will be converted back into speech marks shortly before we use them, in build.sh.
245246
CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM//\"/temporary_speech_mark_placeholder}"
246247

247248
# shellcheck disable=SC2086
248-
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}"
249+
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}"

build-farm/platform-specific-configurations/mac.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,19 @@ source "$SCRIPT_DIR/../../sbin/common/constants.sh"
2222
export MACOSX_DEPLOYMENT_TARGET=10.9
2323
export BUILD_ARGS="${BUILD_ARGS}"
2424

25+
## JDK8 only: If, at this point in the build, the architecure of the machine is arm64 while the ARCHITECTURE variable
26+
## is x64 then we need to add the cross compilation option --openjdk-target=x86_64-apple-darwin
27+
MACHINEARCHITECTURE=$(uname -m)
28+
2529
if [ "${JAVA_TO_BUILD}" == "${JDK8_VERSION}" ]
2630
then
27-
XCODE_SWITCH_PATH="/Applications/Xcode.app"
31+
XCODE_SWITCH_PATH="/Applications/Xcode-11.7.app"
2832
export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --with-toolchain-type=clang"
33+
if [[ "${MACHINEARCHITECTURE}" == "arm64" ]] && [[ "${ARCHITECTURE}" == "x64" ]]; then
34+
export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --openjdk-target=x86_64-apple-darwin"
35+
export MAC_ROSETTA_PREFIX="arch -x86_64"
36+
export PATH=/opt/homebrew/bin:/usr/local/bin:$PATH
37+
fi
2938
if [ "${VARIANT}" == "${BUILD_VARIANT_OPENJ9}" ]; then
3039
export CONFIGURE_ARGS_FOR_ANY_PLATFORM="${CONFIGURE_ARGS_FOR_ANY_PLATFORM} --with-openssl=fetched --enable-openssl-bundling"
3140
export BUILD_ARGS="${BUILD_ARGS} --skip-freetype"

0 commit comments

Comments
 (0)