Skip to content

Commit c9a3544

Browse files
authored
Always specify architecture for x86_64 / aarch64 Darwin (#527)
This has a few benefits. The first is that it's not required to specify `CFLAGS_aarch64_apple_darwin='-arch arm64'` when cross-compiling from x86_64 to aarch64 (or `-arch x86_64` the other way around). Another is that the `cc` frontend performs some snooping of the process hierarchy — if any parent is running in the Rosetta emulation layer, it will default to targeting x86_64. This means that running `cc` on a Developer Transition Kit is likely to suddenly and magically revert to x86_64 if any piece of the chain is emulated (`rustc`, `cargo`, `rustup`, the shell, even the terminal emulator!). It's likely that the `-m64` option is superfluous with these new options, but I don't see any harm in it either.
1 parent a999812 commit c9a3544

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,16 @@ impl Build {
14651465
cmd.args.push("-m64".into());
14661466
}
14671467

1468+
if target.contains("darwin") {
1469+
if target.contains("x86_64") {
1470+
cmd.args.push("-arch".into());
1471+
cmd.args.push("x86_64".into());
1472+
} else if target.contains("aarch64") {
1473+
cmd.args.push("-arch".into());
1474+
cmd.args.push("arm64".into());
1475+
}
1476+
}
1477+
14681478
if self.static_flag.is_none() {
14691479
let features = self
14701480
.getenv("CARGO_CFG_TARGET_FEATURE")

0 commit comments

Comments
 (0)