diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index bf1e7f8eef..e187f5a150 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -25,6 +25,10 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|arm64|ARM64|aarch64|AARCH64") # Windows ARM64: use /clang: prefix for clang-cl, skip for MSVC cl.exe subprojects # These flags are only understood by clang-cl, not MSVC cl.exe register_compiler_flags(/clang:-march=armv8-a+crc /clang:-mtune=ampere1) + elseif(ENABLE_BASELINE) + # Baseline ARM64: target ARMv8-A without optional extensions for older CPUs like Cortex-A53 + # See https://github.com/oven-sh/bun/issues/26544 + register_compiler_flags(-march=armv8-a -mtune=cortex-a53) else() register_compiler_flags(-march=armv8-a+crc -mtune=ampere1) endif() diff --git a/cmake/Options.cmake b/cmake/Options.cmake index 47e8e55457..8e8a32b7be 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -99,6 +99,9 @@ endif() if(ARCH STREQUAL "x64") optionx(ENABLE_BASELINE BOOL "If baseline features should be used for older CPUs (e.g. disables AVX, AVX2)" DEFAULT OFF) +elseif(ARCH STREQUAL "aarch64" AND LINUX) + # ARM64 baseline only supported on Linux; macOS always uses apple_m1, Windows ARM64 doesn't support baseline yet + optionx(ENABLE_BASELINE BOOL "If baseline features should be used for older ARM64 CPUs (e.g. Cortex-A53)" DEFAULT OFF) endif() # Disabling logs by default for tests yields faster builds diff --git a/cmake/targets/BuildBun.cmake b/cmake/targets/BuildBun.cmake index 64536cc26b..ed440f1a96 100644 --- a/cmake/targets/BuildBun.cmake +++ b/cmake/targets/BuildBun.cmake @@ -683,6 +683,10 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm|ARM|arm64|ARM64|aarch64|AARCH64") # Windows ARM64: use a specific CPU with NEON support # Zig running under x64 emulation would detect wrong CPU with "native" set(ZIG_CPU "cortex_a76") + elseif(ENABLE_BASELINE) + # Baseline ARM64: target Cortex-A35 for older CPUs like Cortex-A53 + # See https://github.com/oven-sh/bun/issues/26544 + set(ZIG_CPU "cortex_a35") else() set(ZIG_CPU "native") endif() diff --git a/cmake/toolchains/linux-aarch64-baseline.cmake b/cmake/toolchains/linux-aarch64-baseline.cmake new file mode 100644 index 0000000000..b9027a6519 --- /dev/null +++ b/cmake/toolchains/linux-aarch64-baseline.cmake @@ -0,0 +1,7 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(ENABLE_BASELINE ON) +set(ABI gnu) + +set(CMAKE_C_COMPILER_WORKS ON) +set(CMAKE_CXX_COMPILER_WORKS ON) diff --git a/cmake/toolchains/linux-aarch64-musl-baseline.cmake b/cmake/toolchains/linux-aarch64-musl-baseline.cmake new file mode 100644 index 0000000000..5d0e89dbd1 --- /dev/null +++ b/cmake/toolchains/linux-aarch64-musl-baseline.cmake @@ -0,0 +1,7 @@ +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch64) +set(ENABLE_BASELINE ON) +set(ABI musl) + +set(CMAKE_C_COMPILER_WORKS ON) +set(CMAKE_CXX_COMPILER_WORKS ON)