diff --git a/barretenberg/cpp/CMakePresets.json b/barretenberg/cpp/CMakePresets.json index 62b4f4851719..079ae573346d 100644 --- a/barretenberg/cpp/CMakePresets.json +++ b/barretenberg/cpp/CMakePresets.json @@ -488,7 +488,6 @@ }, "cacheVariables": { "CMAKE_SYSTEM_NAME": "Linux", - "TARGET_ARCH": "skylake", "AVM_TRANSPILER_LIB": "${sourceDir}/../../avm-transpiler/target/x86_64-apple-darwin/release/libavm_transpiler.a" } }, @@ -502,7 +501,6 @@ }, "cacheVariables": { "CMAKE_SYSTEM_NAME": "Linux", - "TARGET_ARCH": "generic", "AVM_TRANSPILER_LIB": "${sourceDir}/../../avm-transpiler/target/aarch64-unknown-linux-gnu/release/libavm_transpiler.a" } }, @@ -551,7 +549,6 @@ "cacheVariables": { "CMAKE_SYSTEM_NAME": "Windows", "CMAKE_SYSTEM_PROCESSOR": "x86_64", - "TARGET_ARCH": "skylake", "BB_LITE": "ON", "AVM_TRANSPILER_LIB": "" } diff --git a/barretenberg/cpp/cmake/arch.cmake b/barretenberg/cpp/cmake/arch.cmake index e1e7d0978fd7..c8158dfb8cc8 100644 --- a/barretenberg/cpp/cmake/arch.cmake +++ b/barretenberg/cpp/cmake/arch.cmake @@ -5,16 +5,9 @@ if(WASM) add_compile_options(-fno-exceptions -fno-slp-vectorize) endif() -# Auto-detect TARGET_ARCH on x86_64 if not explicitly set (native builds only). -# On ARM, we skip -march entirely — the zig wrappers use an explicit aarch64 target -# to produce generic ARM64 code without CPU-specific extensions (e.g. SVE). -# Skip auto-detection when cross-compiling — the toolchain (e.g. Zig -mcpu) handles -# architecture targeting, and injecting -march here conflicts with it. -if(NOT WASM AND NOT TARGET_ARCH AND NOT ARM AND NOT CMAKE_CROSSCOMPILING) - set(TARGET_ARCH "skylake") -endif() - -if(NOT WASM AND TARGET_ARCH) - message(STATUS "Target architecture: ${TARGET_ARCH}") - add_compile_options(-march=${TARGET_ARCH}) +# Target skylake on x86 for AVX2 etc. ARM is handled by the zig wrapper scripts +# which use explicit aarch64 targets to produce generic ARM64 code without +# CPU-specific extensions (e.g. SVE on Graviton) that would break on Apple Silicon. +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") + add_compile_options(-march=skylake) endif() diff --git a/barretenberg/cpp/scripts/zig-c++.sh b/barretenberg/cpp/scripts/zig-c++.sh index 1afa0f82f8fa..9ec2e6fb76c7 100755 --- a/barretenberg/cpp/scripts/zig-c++.sh +++ b/barretenberg/cpp/scripts/zig-c++.sh @@ -1,14 +1,15 @@ #!/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, 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. +# Use explicit architecture targets instead of 'native' to prevent zig from +# detecting host-specific CPU features (e.g. SVE on Graviton, AVX-512 on +# Sapphire Rapids) that would produce binaries incompatible with other machines. +# cmake's arch.cmake handles -march=skylake for x86; ARM gets baseline aarch64 (no SVE). 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 "$@" ;; + x86_64|amd64) exec zig c++ -target x86_64-linux-gnu.2.35 "$@" ;; + *) echo "Error: unsupported architecture '$(uname -m)'" >&2; exit 1 ;; esac else exec zig c++ "$@" diff --git a/barretenberg/cpp/scripts/zig-cc.sh b/barretenberg/cpp/scripts/zig-cc.sh index 34dd6263c6ce..0ab0c0913557 100755 --- a/barretenberg/cpp/scripts/zig-cc.sh +++ b/barretenberg/cpp/scripts/zig-cc.sh @@ -1,14 +1,15 @@ #!/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, 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. +# Use explicit architecture targets instead of 'native' to prevent zig from +# detecting host-specific CPU features (e.g. SVE on Graviton, AVX-512 on +# Sapphire Rapids) that would produce binaries incompatible with other machines. +# cmake's arch.cmake handles -march=skylake for x86; ARM gets baseline aarch64 (no SVE). 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 "$@" ;; + x86_64|amd64) exec zig cc -target x86_64-linux-gnu.2.35 "$@" ;; + *) echo "Error: unsupported architecture '$(uname -m)'" >&2; exit 1 ;; esac else exec zig cc "$@"