From 8f1c6d9908e2fdde2eae6057b727400b41fd6d18 Mon Sep 17 00:00:00 2001 From: AztecBot Date: Tue, 17 Mar 2026 11:02:05 +0000 Subject: [PATCH] fix: skip -march auto-detection for cross-compilation presets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The arch.cmake auto-detection (added in #21611) defaults TARGET_ARCH to 'skylake' when ARM is not detected. For cross-compilation presets like arm64-ios, arm64-android, and arm64-ios-sim, CMAKE_SYSTEM_PROCESSOR is not set, so ARM detection fails and -march=skylake gets injected into aarch64 builds — causing zig to error with 'unknown CPU: skylake'. For arm64-macos, ARM is detected but -march=generic overrides zig's -mcpu=apple_a14, causing libdeflate build failures (missing AES target feature). Fix: gate auto-detection on NOT CMAKE_CROSSCOMPILING. Cross-compile toolchains (Zig) handle architecture targeting via their own flags. Presets that explicitly set TARGET_ARCH (amd64-linux, arm64-linux) are unaffected. Also restores native_build_dir variable that was dropped in the build infrastructure refactor. --- barretenberg/cpp/bootstrap.sh | 1 + barretenberg/cpp/cmake/arch.cmake | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/bootstrap.sh b/barretenberg/cpp/bootstrap.sh index 7a38e0bd4f80..3c533971fed9 100755 --- a/barretenberg/cpp/bootstrap.sh +++ b/barretenberg/cpp/bootstrap.sh @@ -7,6 +7,7 @@ else export native_preset=${NATIVE_PRESET:-clang20-no-avm} fi export hash=$(hash_str $(../../avm-transpiler/bootstrap.sh hash) $(cache_content_hash .rebuild_patterns)) +export native_build_dir=$(scripts/preset-build-dir $native_preset) # Injects version number into a given bb binary. # Means we don't actually need to rebuild bb to release a new version if code hasn't changed. diff --git a/barretenberg/cpp/cmake/arch.cmake b/barretenberg/cpp/cmake/arch.cmake index fe6488cbce3f..ed185b1fa970 100644 --- a/barretenberg/cpp/cmake/arch.cmake +++ b/barretenberg/cpp/cmake/arch.cmake @@ -5,11 +5,13 @@ if(WASM) add_compile_options(-fno-exceptions -fno-slp-vectorize) endif() -# Auto-detect TARGET_ARCH if not explicitly set. +# 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. -if(NOT WASM AND NOT TARGET_ARCH) +# 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()