How to Build Universal macOS Binaries with Rust

Compile Rust for x86_64 and aarch64 separately, then merge them using lipo to create a universal macOS binary.

Build universal macOS binaries by compiling for both x86_64 and aarch64 targets, then merging them with lipo. First, install the Apple Silicon target if you are on an Intel Mac, then compile your binary for both architectures and combine them into a single executable.

rustup target add x86_64-apple-darwin aarch64-apple-darwin
cargo build --target x86_64-apple-darwin --release
cargo build --target aarch64-apple-darwin --release
lipo -create -output target/universal/release/my_binary target/x86_64-apple-darwin/release/my_binary target/aarch64-apple-darwin/release/my_binary

Note: Replace my_binary with your actual crate name.