Created by: XiaoPengYouCode
Root cause
On macOS, DCR defaulted builds to x86_64-apple-darwin even when the host binary was running on Apple Silicon (aarch64-apple-darwin). The build path injected --target=<triple> only into clang compile flags, while the link command did not receive the same target flag.
That produced an x86_64 object file, then invoked clang/ld with the host default arm64 linker settings. The linker ignored the x86_64 object and reported _main as undefined for arm64.
Fix
- Add a shared
default_target_triple()helper that usesstd::env::consts::ARCHfor host defaults, including macOS. - Reuse that helper in
build,run, andcleanso they agree on the same default target directory. - Add a shared clang target flag helper and apply
--target=<triple>to both compile flags and link flags. - Add unit coverage for host default target generation and clang target flag insertion.
Verification
cargo fmt --all --checkcargo check --all-targets --all-featurescargo test utils::build::tests -- --test-threads=1- Built local DCR with
cargo build - Verified a minimal C project on Apple Silicon with:
target/debug/dcr run --force --verbose- default target printed as
aarch64-apple-darwin - compile command included
--target=aarch64-apple-darwin - link command included
--target=aarch64-apple-darwin - binary ran and printed
Hello World!
Notes
On this macOS machine, cargo clippy --all-targets --all-features -- -D warnings is currently blocked by pre-existing macOS-only clippy::needless_return diagnostics in src/platform/mod.rs.
Full cargo test is also blocked locally by pre-existing collect_sources_* tests that compare /var/... temp paths against /private/var/... resolved paths on macOS. The new utils::build tests pass.