Allo native builds on Mac OS M1 / Apple Silicon

- Update GMP to a version that supports arm64 darwin
- Patch spidermonkey 78 to build and run on arm64 darwin
- Choose the correct architecture dynamically in build scripts
- Include python workaround that fixes python related errors on
spidermonkey build

Based on a patch by: kumikumi
Based on a patch by: Langbart
Fixes #6474

Differential Revision: https://code.wildfiregames.com/D4607
This was SVN commit r26881.
This commit is contained in:
wraitii
2022-05-15 06:45:53 +00:00
parent 364894287d
commit 08e7efc76a
4 changed files with 57 additions and 41 deletions
+26 -26
View File
@@ -61,7 +61,7 @@ elseif not os.istarget("windows") then
end end
end end
-- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM) -- detect CPU architecture (simplistic)
arch = "x86" arch = "x86"
macos_arch = "x86_64" macos_arch = "x86_64"
if _OPTIONS["android"] then if _OPTIONS["android"] then
@@ -71,33 +71,33 @@ elseif os.istarget("windows") then
arch = "amd64" arch = "amd64"
end end
else else
arch = os.getenv("HOSTTYPE") os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
-- Force x86_64 on Mac OS for now, as Spidermonkey 78 isn't Apple Silicon compatible. local f = io.open(".gccmachine.tmp", "r")
local machine = f:read("*line")
f:close()
-- Special handling on mac os where xcode needs special flags.
if os.istarget("macosx") then if os.istarget("macosx") then
arch = "amd64" if string.find(machine, "arm64") then
macos_arch = "x86_64"
elseif arch == "x86_64" or arch == "amd64" then
arch = "amd64"
else
os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
local f = io.open(".gccmachine.tmp", "r")
local machine = f:read("*line")
f:close()
if string.find(machine, "x86_64") == 1 or string.find(machine, "amd64") == 1 then
arch = "amd64"
elseif string.find(machine, "i.86") == 1 then
arch = "x86"
elseif string.find(machine, "arm") == 1 then
arch = "arm"
elseif string.find(machine, "aarch64") == 1 then
arch = "aarch64" arch = "aarch64"
elseif string.find(machine, "e2k") == 1 then macos_arch = "arm64"
arch = "e2k"
elseif string.find(machine, "ppc64") == 1 or string.find(machine, "powerpc64") == 1 then
arch = "ppc64"
else else
print("WARNING: Cannot determine architecture from GCC, assuming x86") arch = "amd64"
macos_arch = "x86_64"
end end
elseif string.find(machine, "x86_64") == 1 or string.find(machine, "amd64") == 1 then
arch = "amd64"
elseif string.find(machine, "i.86") == 1 then
arch = "x86"
elseif string.find(machine, "arm") == 1 then
arch = "arm"
elseif string.find(machine, "aarch64") == 1 then
arch = "aarch64"
elseif string.find(machine, "e2k") == 1 then
arch = "e2k"
elseif string.find(machine, "ppc64") == 1 or string.find(machine, "powerpc64") == 1 then
arch = "ppc64"
else
print("WARNING: Cannot determine architecture from GCC, assuming x86")
end end
end end
@@ -327,8 +327,8 @@ function project_set_build_flags()
links { "gcov" } links { "gcov" }
end end
-- MacOS 10.12 only supports processors with SSE 4.1, so enable that. -- MacOS 10.12 only supports intel processors with SSE 4.1, so enable that.
if os.istarget("macosx") then if os.istarget("macosx") and arch == "amd64" then
buildoptions { "-msse4.1" } buildoptions { "-msse4.1" }
end end
+27 -11
View File
@@ -36,14 +36,14 @@ FREETYPE_VERSION="freetype-2.10.4"
OGG_VERSION="libogg-1.3.3" OGG_VERSION="libogg-1.3.3"
VORBIS_VERSION="libvorbis-1.3.7" VORBIS_VERSION="libvorbis-1.3.7"
# gloox requires GnuTLS, GnuTLS requires Nettle and GMP # gloox requires GnuTLS, GnuTLS requires Nettle and GMP
GMP_VERSION="gmp-6.2.0" GMP_VERSION="gmp-6.2.1"
NETTLE_VERSION="nettle-3.6" NETTLE_VERSION="nettle-3.6"
# NOTE: remember to also update LIB_URL below when changing version # NOTE: remember to also update LIB_URL below when changing version
GLOOX_VERSION="gloox-1.0.24" GLOOX_VERSION="gloox-1.0.24"
GNUTLS_VERSION="gnutls-3.6.15" GNUTLS_VERSION="gnutls-3.6.15"
# OS X only includes part of ICU, and only the dylib # OS X only includes part of ICU, and only the dylib
# NOTE: remember to also update LIB_URL below when changing version # NOTE: remember to also update LIB_URL below when changing version
ICU_VERSION="icu4c-67_1" ICU_VERSION="icu4c-69_1"
ENET_VERSION="enet-1.3.17" ENET_VERSION="enet-1.3.17"
MINIUPNPC_VERSION="miniupnpc-2.2.2" MINIUPNPC_VERSION="miniupnpc-2.2.2"
SODIUM_VERSION="libsodium-1.0.18" SODIUM_VERSION="libsodium-1.0.18"
@@ -61,6 +61,7 @@ FMT_VERSION="7.1.3"
export CC=${CC:="clang"} CXX=${CXX:="clang++"} export CC=${CC:="clang"} CXX=${CXX:="clang++"}
export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.12"} export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.12"}
export ARCH=${ARCH:=""}
# The various libs offer inconsistent configure options, some allow # The various libs offer inconsistent configure options, some allow
# setting sysroot and OS X-specific options, others don't. Adding to # setting sysroot and OS X-specific options, others don't. Adding to
@@ -83,7 +84,7 @@ if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
fi fi
CFLAGS="$CFLAGS $C_FLAGS -fvisibility=hidden" CFLAGS="$CFLAGS $C_FLAGS -fvisibility=hidden"
CXXFLAGS="$CXXFLAGS $C_FLAGS -stdlib=libc++ -std=c++17 -msse4.1" CXXFLAGS="$CXXFLAGS $C_FLAGS -stdlib=libc++ -std=c++17"
OBJCFLAGS="$OBJCFLAGS $C_FLAGS" OBJCFLAGS="$OBJCFLAGS $C_FLAGS"
OBJCXXFLAGS="$OBJCXXFLAGS $C_FLAGS" OBJCXXFLAGS="$OBJCXXFLAGS $C_FLAGS"
@@ -94,16 +95,31 @@ ARCHLESS_CFLAGS=$CFLAGS
ARCHLESS_CXXFLAGS=$CXXFLAGS ARCHLESS_CXXFLAGS=$CXXFLAGS
ARCHLESS_LDFLAGS="$LDFLAGS -stdlib=libc++" ARCHLESS_LDFLAGS="$LDFLAGS -stdlib=libc++"
CFLAGS="$CFLAGS -arch x86_64" # If ARCH isn't set, select either x86_64 or arm64
CXXFLAGS="$CXXFLAGS -arch x86_64" if [ -z "${ARCH}" ]; then
if [ "`uname -m`" == "arm64" ]; then
ARCH="arm64"
# Some libs want this passed to configure for cross compilation.
HOST_PLATFORM="--host=aarch64-apple-darwin"
else
CXXFLAGS="$CXXFLAGS -msse4.1"
ARCH="x86_64"
# Some libs want this passed to configure for cross compilation.
HOST_PLATFORM="--host=x86_64-apple-darwin"
fi
fi
LDFLAGS="$LDFLAGS -arch x86_64" echo "ARCHITECTURE BREAKDOWN"
echo $ARCH
echo $HOST_PLATFORM
# Some libs want this passed to configure for cross compilation. CFLAGS="$CFLAGS -arch $ARCH"
HOST_PLATFORM="--host=x86_64-apple-darwin" CXXFLAGS="$CXXFLAGS -arch $ARCH"
LDFLAGS="$LDFLAGS -arch $ARCH"
# CMake doesn't seem to pick up on architecture with CFLAGS only # CMake doesn't seem to pick up on architecture with CFLAGS only
CMAKE_FLAGS="-DCMAKE_OSX_ARCHITECTURES=x86_64" CMAKE_FLAGS="-DCMAKE_OSX_ARCHITECTURES=$ARCH"
JOBS=${JOBS:="-j2"} JOBS=${JOBS:="-j2"}
@@ -830,7 +846,7 @@ echo -e "Building ICU..."
LIB_VERSION="${ICU_VERSION}" LIB_VERSION="${ICU_VERSION}"
LIB_ARCHIVE="$LIB_VERSION-src.tgz" LIB_ARCHIVE="$LIB_VERSION-src.tgz"
LIB_DIRECTORY="icu" LIB_DIRECTORY="icu"
LIB_URL="https://github.com/unicode-org/icu/releases/download/release-67-1/" LIB_URL="https://github.com/unicode-org/icu/releases/download/release-69-1/"
mkdir -p icu mkdir -p icu
pushd icu > /dev/null pushd icu > /dev/null
@@ -1039,7 +1055,7 @@ then
fi fi
# Use the regular build script for SM. # Use the regular build script for SM.
JOBS="$JOBS" ZLIB_DIR="$ZLIB_DIR" ./build.sh || die "Error building spidermonkey" JOBS="$JOBS" ZLIB_DIR="$ZLIB_DIR" ARCH="$ARCH" ./build.sh || die "Error building spidermonkey"
popd > /dev/null popd > /dev/null
+3 -2
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2021 Wildfire Games. /* Copyright (C) 2022 Wildfire Games.
* This file is part of 0 A.D. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@@ -83,8 +83,9 @@ void ColorActivateFastImpl()
ConvertRGBColorTo4ub = ConvertRGBColorTo4ubSSE; ConvertRGBColorTo4ub = ConvertRGBColorTo4ubSSE;
return; return;
} }
#endif #elif defined(ARCH_X86_64)
debug_printf("No SSE available. Slow fallback routines will be used.\n"); debug_printf("No SSE available. Slow fallback routines will be used.\n");
#endif
} }
/** /**
+1 -2
View File
@@ -2,8 +2,7 @@
# Build the Pyrogenesis executable, used to create the bundle and run the archiver. # Build the Pyrogenesis executable, used to create the bundle and run the archiver.
# TODO: is there anything to do for ARM support? export ARCH=${ARCH:=$(uname -m)}
export ARCH=${ARCH:="x86_64"}
# Set mimimum required OS X version, SDK location and tools # Set mimimum required OS X version, SDK location and tools
# Old SDKs can be found at https://github.com/phracker/MacOSX-SDKs # Old SDKs can be found at https://github.com/phracker/MacOSX-SDKs