Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions barretenberg/cpp/CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
},
Expand All @@ -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"
}
},
Expand Down Expand Up @@ -551,7 +549,6 @@
"cacheVariables": {
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_SYSTEM_PROCESSOR": "x86_64",
"TARGET_ARCH": "skylake",
"BB_LITE": "ON",
"AVM_TRANSPILER_LIB": ""
}
Expand Down
17 changes: 5 additions & 12 deletions barretenberg/cpp/cmake/arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 6 additions & 5 deletions barretenberg/cpp/scripts/zig-c++.sh
Original file line number Diff line number Diff line change
@@ -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++ "$@"
Expand Down
11 changes: 6 additions & 5 deletions barretenberg/cpp/scripts/zig-cc.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Expand Down
Loading