Index: ps/trunk/build/premake/premake5.lua =================================================================== --- ps/trunk/build/premake/premake5.lua +++ ps/trunk/build/premake/premake5.lua @@ -61,7 +61,7 @@ end end --- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM) +-- detect CPU architecture (simplistic) arch = "x86" macos_arch = "x86_64" if _OPTIONS["android"] then @@ -71,33 +71,33 @@ arch = "amd64" end else - arch = os.getenv("HOSTTYPE") - -- Force x86_64 on Mac OS for now, as Spidermonkey 78 isn't Apple Silicon compatible. + os.execute(cc .. " -dumpmachine > .gccmachine.tmp") + 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 - arch = "amd64" - 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 + if string.find(machine, "arm64") 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" + macos_arch = "arm64" else - print("WARNING: Cannot determine architecture from GCC, assuming x86") + arch = "amd64" + macos_arch = "x86_64" 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 @@ -327,8 +327,8 @@ links { "gcov" } end - -- MacOS 10.12 only supports processors with SSE 4.1, so enable that. - if os.istarget("macosx") then + -- MacOS 10.12 only supports intel processors with SSE 4.1, so enable that. + if os.istarget("macosx") and arch == "amd64" then buildoptions { "-msse4.1" } end Index: ps/trunk/libraries/osx/build-osx-libs.sh =================================================================== --- ps/trunk/libraries/osx/build-osx-libs.sh +++ ps/trunk/libraries/osx/build-osx-libs.sh @@ -36,14 +36,14 @@ OGG_VERSION="libogg-1.3.3" VORBIS_VERSION="libvorbis-1.3.7" # 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" # NOTE: remember to also update LIB_URL below when changing version GLOOX_VERSION="gloox-1.0.24" GNUTLS_VERSION="gnutls-3.6.15" # OS X only includes part of ICU, and only the dylib # 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" MINIUPNPC_VERSION="miniupnpc-2.2.2" SODIUM_VERSION="libsodium-1.0.18" @@ -61,6 +61,7 @@ export CC=${CC:="clang"} CXX=${CXX:="clang++"} export MIN_OSX_VERSION=${MIN_OSX_VERSION:="10.12"} +export ARCH=${ARCH:=""} # The various libs offer inconsistent configure options, some allow # setting sysroot and OS X-specific options, others don't. Adding to @@ -83,7 +84,7 @@ fi 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" OBJCXXFLAGS="$OBJCXXFLAGS $C_FLAGS" @@ -94,16 +95,31 @@ ARCHLESS_CXXFLAGS=$CXXFLAGS ARCHLESS_LDFLAGS="$LDFLAGS -stdlib=libc++" -CFLAGS="$CFLAGS -arch x86_64" -CXXFLAGS="$CXXFLAGS -arch x86_64" +# If ARCH isn't set, select either x86_64 or arm64 +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 + +echo "ARCHITECTURE BREAKDOWN" +echo $ARCH +echo $HOST_PLATFORM -LDFLAGS="$LDFLAGS -arch x86_64" +CFLAGS="$CFLAGS -arch $ARCH" +CXXFLAGS="$CXXFLAGS -arch $ARCH" -# Some libs want this passed to configure for cross compilation. -HOST_PLATFORM="--host=x86_64-apple-darwin" +LDFLAGS="$LDFLAGS -arch $ARCH" # 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"} @@ -830,7 +846,7 @@ LIB_VERSION="${ICU_VERSION}" LIB_ARCHIVE="$LIB_VERSION-src.tgz" 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 pushd icu > /dev/null @@ -1039,7 +1055,7 @@ fi # 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 Index: ps/trunk/libraries/source/nvtt/src/src/nvcore/Debug.cpp =================================================================== --- ps/trunk/libraries/source/nvtt/src/src/nvcore/Debug.cpp +++ ps/trunk/libraries/source/nvtt/src/src/nvcore/Debug.cpp @@ -607,6 +607,9 @@ # elif NV_CPU_ARM ucontext_t * ucp = (ucontext_t *)secret; return (void *) ucp->uc_mcontext->__ss.__pc; +# elif NV_CPU_AARCH64 + ucontext_t * ucp = (ucontext_t *)secret; + return (void *) ucp->uc_mcontext->__ss.__pc; # else # error "Unknown CPU" # endif Index: ps/trunk/libraries/source/spidermonkey/FixMacBuild.diff =================================================================== --- ps/trunk/libraries/source/spidermonkey/FixMacBuild.diff +++ ps/trunk/libraries/source/spidermonkey/FixMacBuild.diff @@ -32,4 +32,65 @@ - 'https://github.com/phracker/MacOSX-SDKs' % (version, sdk_max_version)) return sdk - set_config('MACOS_SDK_DIR', macos_sdk) \ No newline at end of file + set_config('MACOS_SDK_DIR', macos_sdk) +--- a/build/moz.configure/init.configure ++++ b/build/moz.configure/init.configure +@@ -375,9 +375,6 @@ + sys.exit(subprocess.call([python] + sys.argv)) + + # We are now in the virtualenv +- if not distutils.sysconfig.get_python_lib(): +- die('Could not determine python site packages directory') +- + str_version = '.'.join(str(v) for v in version) + + return namespace( +--- a/js/src/jit/arm64/vixl/MozCpu-vixl.cpp ++++ b/js/src/jit/arm64/vixl/MozCpu-vixl.cpp +@@ -69,7 +69,7 @@ void CPU::SetUp() { + + + uint32_t CPU::GetCacheType() { +-#if defined(__aarch64__) && !defined(_MSC_VER) ++#if defined(__aarch64__) && (defined(__linux__) || defined(__android__)) + uint64_t cache_type_register; + // Copy the content of the cache type register to a core register. + __asm__ __volatile__ ("mrs %[ctr], ctr_el0" // NOLINT +--- a/js/src/wasm/WasmSignalHandlers.cpp ++++ b/js/src/wasm/WasmSignalHandlers.cpp +@@ -226,6 +226,10 @@ using mozilla::DebugOnly; + # define R13_sig(p) ((p)->thread.__sp) + # define R14_sig(p) ((p)->thread.__lr) + # define R15_sig(p) ((p)->thread.__pc) ++# define EPC_sig(p) ((p)->thread.__pc) ++# define RFP_sig(p) ((p)->thread.__fp) ++# define R31_sig(p) ((p)->thread.__sp) ++# define RLR_sig(p) ((p)->thread.__lr) + #else + # error "Don't know how to read/write to the thread state via the mcontext_t." + #endif +@@ -351,6 +355,12 @@ struct macos_arm_context { + arm_neon_state_t float_; + }; + # define CONTEXT macos_arm_context ++# elif defined(__aarch64__) ++struct macos_aarch64_context { ++ arm_thread_state64_t thread; ++ arm_neon_state64_t float_; ++}; ++# define CONTEXT macos_aarch64_context + # else + # error Unsupported architecture + # endif +@@ -816,6 +826,11 @@ static bool HandleMachException(const ExceptionRequest& request) { + unsigned int float_state_count = ARM_NEON_STATE_COUNT; + int thread_state = ARM_THREAD_STATE; + int float_state = ARM_NEON_STATE; ++# elif defined(__aarch64__) ++ unsigned int thread_state_count = ARM_THREAD_STATE64_COUNT; ++ unsigned int float_state_count = ARM_NEON_STATE64_COUNT; ++ int thread_state = ARM_THREAD_STATE64; ++ int float_state = ARM_NEON_STATE64; + # else + # error Unsupported architecture + # endif Index: ps/trunk/libraries/source/spidermonkey/build.sh =================================================================== --- ps/trunk/libraries/source/spidermonkey/build.sh +++ ps/trunk/libraries/source/spidermonkey/build.sh @@ -49,8 +49,15 @@ if [ "`uname -s`" = "Darwin" ] then - # Explicitly target x86_64. - CONF_OPTS="${CONF_OPTS} --target=x86_64-apple-darwin" + ARCH=${ARCH:=""} + if [ -z "${ARCH}" ]; then + if [ "`uname -m`" == "arm64" ]; then + ARCH="aarch64" + else + ARCH="x86_64" + fi + fi + CONF_OPTS="${CONF_OPTS} --target=$ARCH-apple-darwin" # Link to custom-built zlib export PKG_CONFIG_PATH="=${ZLIB_DIR}:${PKG_CONFIG_PATH}" Index: ps/trunk/source/graphics/Color.cpp =================================================================== --- ps/trunk/source/graphics/Color.cpp +++ ps/trunk/source/graphics/Color.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -83,8 +83,9 @@ ConvertRGBColorTo4ub = ConvertRGBColorTo4ubSSE; return; } -#endif +#elif defined(ARCH_X86_64) debug_printf("No SSE available. Slow fallback routines will be used.\n"); +#endif } /** Index: ps/trunk/source/tools/dist/build-osx-executable.sh =================================================================== --- ps/trunk/source/tools/dist/build-osx-executable.sh +++ ps/trunk/source/tools/dist/build-osx-executable.sh @@ -2,8 +2,7 @@ # 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:="x86_64"} +export ARCH=${ARCH:=$(uname -m)} # Set mimimum required OS X version, SDK location and tools # Old SDKs can be found at https://github.com/phracker/MacOSX-SDKs