From a9a23950ab72a2ab49dbef7d4470c6e09bd4feea Mon Sep 17 00:00:00 2001 From: Adam Farley Date: Tue, 30 Jan 2024 04:36:55 +0000 Subject: [PATCH] Temporarily patch architecture confusion when cross-compiling on mac (#3619) Currently, when we build an x64 mac build on an arm64 machine, we put arm64 all over the place by mistake. This change is to partially compensate for that mistake until such time as we can implement a comprehensive separation of build architecture and target architecture in our build scripts. Signed-off-by: Adam Farley --- sbin/build.sh | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/sbin/build.sh b/sbin/build.sh index 37387edeb..467514b3c 100755 --- a/sbin/build.sh +++ b/sbin/build.sh @@ -875,7 +875,16 @@ generateSBoM() { # Below add property to metadata # Add OS full version (Kernel is covered in the first field) addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS version" "${BUILD_CONFIG[OS_FULL_VERSION]^}" - addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + # TODO: Replace this "if" with its predecessor (commented out below) once + # OS_ARCHITECTURE has been replaced by the new target architecture variable. + # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, + # and that confuses things when cross-compiling an x64 mac build on arm mac. + # addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "x86_64" + else + addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}" + fi # Set default SBOM formulation addSBOMFormulation "${javaHome}" "${classpath}" "${sbomJson}" "CycloneDX" @@ -1354,6 +1363,16 @@ cleanAndMoveArchiveFiles() { if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "x86_64" ]; then osArch="amd64" fi + + # TODO: Remove the "if" below once OS_ARCHITECTURE has been replaced. + # This is because OS_ARCHITECTURE is currently the build arch, not the target arch, + # and that confuses things when cross-compiling an x64 mac build on arm mac. + if [ "${BUILD_CONFIG[OS_ARCHITECTURE]}" = "arm64" ]; then + if [[ "${BUILD_CONFIG[TARGET_FILE_NAME]}" =~ .*_x64_.* ]]; then + osArch="amd64" + fi + fi + pushd ${staticLibsImagePath} case "${BUILD_CONFIG[OS_KERNEL_NAME]}" in *cygwin*) @@ -1361,7 +1380,7 @@ cleanAndMoveArchiveFiles() { staticLibsDir="lib/static/windows-${osArch}" ;; darwin) - # on MacOSX the layout is: Contents/Home/lib/static/darwin-amd64/ + # On MacOSX the layout is: Contents/Home/lib/static/darwin-[target architecture]/ staticLibsDir="Contents/Home/lib/static/darwin-${osArch}" ;; linux)