Wrong Architecture Objects Mixed in Self-Built Compiler on Apple Silicon Hosts
Core Problem
When using a self-built compiler on an Apple Silicon host to build a x86_64-unknown-none static library, mach-o-arm64 objects get mixed into the output. This issue arises due to a recent change in Rust's compiler configuration.
Solution & Analysis
To solve this problem, we need to update our config.toml file to include the following lines:
[llvm]
targets = "AArch64;X86"
[build]
target = [
"aarch64-apple-darwin",
"x86_64-unknown-none",
]
[rust]
llvm-tools = true
lld = true
[mach-o]
target-architecture = "arm64"
foo.rs file:
We also need to update our build command to include the following flag:
With these changes, we should be able to build a x86_64-unknown-none static library on an Apple Silicon host without any mach-o-arm64 objects getting mixed in.
Conclusion
By updating our config.toml file and adding the necessary lines to our code, we can solve the issue of wrong architecture objects being mixed in self-built compiler outputs on Apple Silicon hosts.