diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index f6f633de60e0..e8c92f1a1165 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -19,7 +19,6 @@ }, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "TARGET_ARCH": "skylake", "ENABLE_PIC": "ON" } }, diff --git a/barretenberg/cpp/cmake/arch.cmake b/barretenberg/cpp/cmake/arch.cmake index 71b6dbb599ff..fe6488cbce3f 100644 --- a/barretenberg/cpp/cmake/arch.cmake +++ b/barretenberg/cpp/cmake/arch.cmake @@ -5,7 +5,19 @@ if(WASM) add_compile_options(-fno-exceptions -fno-slp-vectorize) endif() -if(NOT WASM AND NOT ARM AND TARGET_ARCH) +# Auto-detect TARGET_ARCH if not explicitly set. +# Use 'skylake' on x86_64 (matches our cross-compile presets) and 'generic' on ARM +# to avoid emitting CPU-specific instructions (e.g. SVE on Graviton) that break on +# other ARM machines like Apple Silicon. +if(NOT WASM AND NOT TARGET_ARCH) + if(ARM) + set(TARGET_ARCH "generic") + else() + set(TARGET_ARCH "skylake") + endif() +endif() + +if(NOT WASM AND TARGET_ARCH) message(STATUS "Target architecture: ${TARGET_ARCH}") add_compile_options(-march=${TARGET_ARCH}) endif() diff --git a/barretenberg/cpp/scripts/zig-c++.sh b/barretenberg/cpp/scripts/zig-c++.sh index 419fd69b833d..dc7e822e03a4 100755 --- a/barretenberg/cpp/scripts/zig-c++.sh +++ b/barretenberg/cpp/scripts/zig-c++.sh @@ -1,15 +1,10 @@ #!/bin/bash # Wrapper for zig c++ that pins glibc 2.35 on Linux (Ubuntu 22.04+ compat) # and uses native target on macOS. -# On ARM64 Linux, we use an explicit aarch64 target instead of 'native' to produce -# generic ARM64 code. This prevents CPU-specific instructions (e.g. SVE on Graviton) -# from being emitted, ensuring binaries work across all ARM64 machines including -# Apple Silicon in devcontainers. +# Note: arch.cmake handles -march selection (skylake on x86, generic on ARM) +# which overrides zig's native CPU detection, preventing CPU-specific instructions. if [[ "$(uname -s)" == "Linux" ]]; then - case "$(uname -m)" in - aarch64|arm64) exec zig c++ -target aarch64-linux-gnu.2.35 "$@" ;; - *) exec zig c++ -target native-linux-gnu.2.35 "$@" ;; - esac + exec zig c++ -target native-linux-gnu.2.35 "$@" else exec zig c++ "$@" fi diff --git a/barretenberg/cpp/scripts/zig-cc.sh b/barretenberg/cpp/scripts/zig-cc.sh index 0bbbaaf4b330..bc39365b6c09 100755 --- a/barretenberg/cpp/scripts/zig-cc.sh +++ b/barretenberg/cpp/scripts/zig-cc.sh @@ -1,15 +1,10 @@ #!/bin/bash # Wrapper for zig cc that pins glibc 2.35 on Linux (Ubuntu 22.04+ compat) # and uses native target on macOS. -# On ARM64 Linux, we use an explicit aarch64 target instead of 'native' to produce -# generic ARM64 code. This prevents CPU-specific instructions (e.g. SVE on Graviton) -# from being emitted, ensuring binaries work across all ARM64 machines including -# Apple Silicon in devcontainers. +# Note: arch.cmake handles -march selection (skylake on x86, generic on ARM) +# which overrides zig's native CPU detection, preventing CPU-specific instructions. if [[ "$(uname -s)" == "Linux" ]]; then - case "$(uname -m)" in - aarch64|arm64) exec zig cc -target aarch64-linux-gnu.2.35 "$@" ;; - *) exec zig cc -target native-linux-gnu.2.35 "$@" ;; - esac + exec zig cc -target native-linux-gnu.2.35 "$@" else exec zig cc "$@" fi