IssueRaiser

Support for macOS Universal/fat binaries

macOS (and iOS) has a concept of [universal binaries](https://en.wikipedia.org/wiki/Universal_binary) which contain code for multiple CPU architectures in the same file. Apple is migrating from x86_64 to aarch64 CPUs, so for the next few years it will be important for macOS developers to build "fat" binaries (executables and cdylibs). Apple's Xcode has very helpful default behavior for this: when building in release mode, it automatically builds for both x86_64 and aarch64 together. In the debug mode, like Cargo, Xcode builds only the current native architecture. Could `cargo --release` on macOS hosts automatically build both `x86_64-apple-darwin` and `aarch64-apple-darwin`, and merge them into a single executable? Merging requires running `lipo -create -output universalbinary intelbinary armbinary`. I think it support for universal binaries should be built-in in Cargo: 1. For the next 3-5 years it will be a necessary operation for every macOS release build. 2. Cargo lacks support for general-purpose post-linking steps (#545). That issue has been in limbo for years, but arm64 (M1) Macs have already shipped, and support for Universal binaries is needed right now. 3. Even if Cargo did have post-build steps, it would be chore to re-add the same necessary step to every project. 4. There's a huge value in `cargo build --release` working for projects out of the box. Without building Universal binaries this becomes half-built, and insufficient for macOS developers.

Posted by kornelski on Nov 20, 2020, 9:55 PM

Tags

Related issues

Raise real-world problems, find people facing the same issue, and discuss solutions.3,000 issues0 comments

support (Other)

Support for macOS Universal/fat binaries

kornelskiNov 20, 2020, 9:55 PM

macOS (and iOS) has a concept of [universal binaries](https://en.wikipedia.org/wiki/Universal_binary) which contain code for multiple CPU architectures in the same file. Apple is migrating from x86_64 to aarch64 CPUs, so for the next few years it will be important for macOS developers to build "fat" binaries (executables and cdylibs). Apple's Xcode has very helpful default behavior for this: when building in release mode, it automatically builds for both x86_64 and aarch64 together. In the debug mode, like Cargo, Xcode builds only the current native architecture. Could `cargo --release` on macOS hosts automatically build both `x86_64-apple-darwin` and `aarch64-apple-darwin`, and merge them into a single executable? Merging requires running `lipo -create -output universalbinary intelbinary armbinary`. I think it support for universal binaries should be built-in in Cargo: 1. For the next 3-5 years it will be a necessary operation for every macOS release build. 2. Cargo lacks support for general-purpose post-linking steps (#545). That issue has been in limbo for years, but arm64 (M1) Macs have already shipped, and support for Universal binaries is needed right now. 3. Even if Cargo did have post-build steps, it would be chore to re-add the same necessary step to every project. 4. There's a huge value in `cargo build --release` working for projects out of the box. Without building Universal binaries this becomes half-built, and insufficient for macOS developers.

Comments (0)

No comments yet. Start the discussion.

Comment on this issue