Skip to content

fix: skip -march auto-detection for cross-compile targets#21632

Open
AztecBot wants to merge 1 commit intomerge-train/spartanfrom
claudebox/fix-m3-devcontainer-ci
Open

fix: skip -march auto-detection for cross-compile targets#21632
AztecBot wants to merge 1 commit intomerge-train/spartanfrom
claudebox/fix-m3-devcontainer-ci

Conversation

@AztecBot
Copy link
Collaborator

@AztecBot AztecBot commented Mar 16, 2026

Summary

PR #21611 added -march auto-detection in arch.cmake, but it ran for cross-compile targets too. This caused:

  • arm64-android: -march=skylake (x86 arch passed to aarch64 zig)
  • arm64-macos: -march=generic stripping AES/crypto features needed by libdeflate

Fix

Single-line guard: skip -march auto-detection when CMAKE_CROSSCOMPILING is set. Cross-compile presets already handle CPU selection via zig's -target/-mcpu flags, and presets that need -march (like arm64-linux) already set TARGET_ARCH explicitly.

@AztecBot AztecBot added the claudebox Owned by claudebox. it can push to this PR. label Mar 16, 2026
@ludamad ludamad added the ci-full Run all master checks. label Mar 16, 2026
@AztecBot AztecBot changed the title fix: skip -march for ARM cross-compile targets fix: skip -march auto-detection for cross-compile targets Mar 16, 2026
@AztecBot AztecBot force-pushed the claudebox/fix-m3-devcontainer-ci branch from af1a653 to 3d05392 Compare March 16, 2026 21:00
@AztecBot AztecBot force-pushed the claudebox/fix-m3-devcontainer-ci branch from 3d05392 to ab4f752 Compare March 16, 2026 21:11
@ludamad ludamad marked this pull request as ready for review March 16, 2026 21:18
@ludamad ludamad enabled auto-merge (squash) March 16, 2026 21:18
@ludamad ludamad removed the claudebox Owned by claudebox. it can push to this PR. label Mar 16, 2026
@AztecBot
Copy link
Collaborator Author

Flakey Tests

🤖 says: This CI run detected 1 tests that failed, but were tolerated due to a .test_patterns.yml entry.

\033FLAKED\033 (8;;http://ci.aztec-labs.com/cc3972e02297d815�cc3972e02297d8158;;�):  yarn-project/end-to-end/scripts/run_test.sh simple src/e2e_p2p/reqresp/reqresp.test.ts (236s) (code: 0) group:e2e-p2p-epoch-flakes

ludamad pushed a commit that referenced this pull request Mar 17, 2026
# fix: ARM64 devcontainer builds — skip `-march` on ARM and use explicit
zig aarch64 target

## Summary

Fixes SIGILL (Illegal Instruction) crashes and build failures on ARM64
Mac (M3/Apple Silicon) devcontainers caused by incorrect `-march`
handling introduced in #21611.

## Problem

PR #21611 originally fixed ARM64 devcontainer builds by using explicit
`aarch64-linux-gnu.2.35` zig targets. During the merge, that approach
was replaced with cmake-based auto-detection that sets
`TARGET_ARCH=generic` on ARM and passes `-march=generic` to the
compiler. This caused two distinct failures:

### 1. SIGILL crashes (`Illegal instruction`)

The zig compiler wrappers still used `-target native-linux-gnu.2.35`,
which auto-detects the host CPU. On CI (AWS Graviton with SVE
extensions), this produces binaries containing SVE instructions. These
cached binaries are then downloaded on Apple Silicon devcontainers
(ARM64 without SVE), causing SIGILL when executed — e.g.
`honk_solidity_key_gen` crashing during `barretenberg/sol` bootstrap.

The `-march=generic` flag was supposed to override this, but
`-march=generic` is **not a valid value on aarch64**. It's an x86
concept. LLVM/zig silently ignored it, so the native CPU detection still
produced SVE instructions.

### 2. Build failures (`unknown CPU: 'armv8'`)

Even attempting `-march=armv8-a` (a valid GCC/Clang aarch64 value) fails
because zig uses its own CPU naming scheme (e.g. `generic`,
`cortex_a72`, `apple_m3`), not GCC-style architecture strings. Zig
interprets `-march=armv8-a` as CPU name `armv8`, which doesn't exist →
`error: unknown CPU: 'armv8'`.

**Bottom line:** The `-march` cmake approach fundamentally doesn't work
with zig on ARM. Zig has its own architecture targeting via `-target`,
which is the correct mechanism.

## What this PR changes

### 1. `arch.cmake` — Skip `-march` auto-detection on ARM

Removed the ARM branch from the auto-detection. On x86_64, we still
auto-detect `TARGET_ARCH=skylake`. On ARM, we don't set `TARGET_ARCH` at
all, so no `-march` flag is passed — the zig wrappers handle
architecture targeting instead.

### 2. `zig-cc.sh` / `zig-c++.sh` — Explicit aarch64 target on ARM Linux

Restored the original fix from #21611 that was dropped during merge. On
ARM64 Linux, the wrappers now use `-target aarch64-linux-gnu.2.35`
instead of `-target native-linux-gnu.2.35`. This produces generic ARM64
code without CPU-specific extensions (SVE, etc.), ensuring cached
binaries work on all ARM64 machines — Graviton, Apple Silicon, Ampere,
etc.

x86_64 behavior is unchanged (still uses `-target native`).

## Context: what happened after #21611

After #21611 merged with the cmake auto-detection approach, it triggered
a cascade of follow-up PRs trying to fix the fallout:

| PR | Status | Issue |
|----|--------|-------|
| #21621 | Merged | Introduced the auto-detect approach (replaced zig
wrapper fix with cmake `-march`) |
| #21356 | Merged | Added `NOT CMAKE_CROSSCOMPILING` guard for
cross-compile failures |
| #21637 | Open | Attempting to fix cross-compiles + restore
`native_build_dir` |
| #21660 | Open | Attempting to fix cross-compile targets |
| #21632 | Open | Attempting to fix cross-compile targets |
| #21662 | Open | Adding `CMAKE_SYSTEM_PROCESSOR` to ARM64 cross-compile
presets |
| #21653 | Open | Attempting to skip auto-detection when cross-compiling
|
| #21655 | Open | Attempting to skip auto-detection for
cross-compilation targets |

This PR supersedes the still-open PRs above by addressing the root
cause: `-march` via cmake doesn't work with zig on ARM. The zig
`-target` mechanism is the correct approach.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run all master checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants