Skip to content

Commit

Permalink
Always specify architecture for x86_64 / aarch64 Darwin (#527)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shepmaster authored Jul 8, 2020
1 parent a999812 commit c9a3544
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,16 @@ impl Build {
cmd.args.push("-m64".into());
}

if target.contains("darwin") {
if target.contains("x86_64") {
cmd.args.push("-arch".into());
cmd.args.push("x86_64".into());
} else if target.contains("aarch64") {
cmd.args.push("-arch".into());
cmd.args.push("arm64".into());
}
}

if self.static_flag.is_none() {
let features = self
.getenv("CARGO_CFG_TARGET_FEATURE")
Expand Down

0 comments on commit c9a3544

Please sign in to comment.