Skip to content
Merged
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
15 changes: 5 additions & 10 deletions barretenberg/cpp/cmake/arch.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,13 @@ if(WASM)
add_compile_options(-fno-exceptions -fno-slp-vectorize)
endif()

# Auto-detect TARGET_ARCH if not explicitly set (native builds only).
# 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.
# 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 CMAKE_CROSSCOMPILING)
if(ARM)
set(TARGET_ARCH "generic")
else()
set(TARGET_ARCH "skylake")
endif()
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)
Expand Down
11 changes: 8 additions & 3 deletions barretenberg/cpp/scripts/zig-c++.sh
Original file line number Diff line number Diff line change
@@ -1,10 +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.
# Note: arch.cmake handles -march selection (skylake on x86, generic on ARM)
# which overrides zig's native CPU detection, preventing CPU-specific instructions.
# 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.
if [[ "$(uname -s)" == "Linux" ]]; then
exec zig c++ -target native-linux-gnu.2.35 "$@"
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
else
exec zig c++ "$@"
fi
11 changes: 8 additions & 3 deletions barretenberg/cpp/scripts/zig-cc.sh
Original file line number Diff line number Diff line change
@@ -1,10 +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.
# Note: arch.cmake handles -march selection (skylake on x86, generic on ARM)
# which overrides zig's native CPU detection, preventing CPU-specific instructions.
# 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.
if [[ "$(uname -s)" == "Linux" ]]; then
exec zig cc -target native-linux-gnu.2.35 "$@"
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
else
exec zig cc "$@"
fi
Loading