Skip to content

Commit 0d3c2f2

Browse files
committed
Add instructions for compiling for older versions of Mac OS X and useful links for building universal binaries that run on x86-64 and Apple Silicon
1 parent f505f4b commit 0d3c2f2

File tree

2 files changed

+49
-4
lines changed

2 files changed

+49
-4
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ lto = "fat" # Optimize at link stage, removing dead code and reducing binary s
2424
# Performs "fat" LTO which attempts to perform optimizations across all
2525
# crates within the dependency graph.
2626
codegen-units = 1 # Reduce parallelism to allow maximum size reduction optimizations.
27+
28+
[target.x86_64-apple-darwin]
29+
rustflags=["-C", "link-arg=-mmacosx-version-min=10.7"]

README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,57 @@ A simple standalone webserver which you can upload and download files from.
5353
curl -X POST --data-binary @file_to_upload.txt http://localhost:8000/file_to_upload.txt
5454

5555

56-
# Statically-Linked Binary
56+
# Statically-Linked Linux Binary
5757

58-
The following commands build a statically-linked Linux binary without shared library dependencies. This can be useful for embedded systems or other applications where you do not want to rely on libgcc, libc, libpthread, and other dependencies which can break due to version changes. Note that performance may be lower than the dynamically-linked binaries described above.
58+
The following commands build a statically-linked Linux binary without shared library dependencies. This can be useful when distributing the binary to multiple different Linux distributions or to different versions of a Linux distribution, since libgcc, libc, libpthread, and other dependencies can break due to version changes.
5959

60-
1. Add musl toolchain
60+
```
61+
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found
62+
(required by ./uploadserver-x86_64-linux)
63+
```
64+
65+
Note that performance may be lower than the dynamically-linked binaries described above.
66+
67+
1. Add musl toolchain:
6168

6269
rustup target add x86_64-unknown-linux-musl
6370
sudo apt install musl-tools
6471

65-
2. Compile Linux binary using musl toolchain
72+
2. Compile Linux binary using the musl toolchain:
6673

6774
RUSTFLAGS='-C link-arg=-s' cargo build --release --target x86_64-unknown-linux-musl
75+
76+
# Compile for Old Versions of Mac OS X
77+
78+
1. Install the latest version of Xcode from the App Store, or an older XCode version from [Apple Developer Downloads](https://developer.apple.com/download/all/).
79+
80+
2. Switch to the specified Xcode version if necessary:
81+
82+
xcode-select --switch /Volumes/YOUR_VOLUME/Applications/Xcode.app
83+
84+
3. Configure the minimum supported OS X version (down to 10.7 Lion) in `Cargo.toml`:
85+
86+
87+
[target.x86_64-apple-darwin]
88+
rustflags=["-C", "link-arg=-mmacosx-version-min=10.7"]
89+
90+
4. Compile the binary:
91+
92+
MACOSX_DEPLOYMENT_TARGET=10.7 cargo build --target=x86_64-apple-darwin --release
93+
94+
95+
# TODO: Support ARM Apple Silicon (M1 processor family)
96+
Requires MacOS Catalina 10.15.4 (Intel-based Mac) or MacOS Big Sur 11 (Apple Silicon Mac) or later.
97+
98+
Xcode 12.2 and later is a requirement for building universal binaries. Earlier versions of Xcode don't contain the support needed to build and test universal versions of MacOS code.
99+
100+
- [Github: Cargo-Lipo](https://github.com/TimNN/cargo-lipo) can automatically create universal libraries (fat binaries supporting both Intel x86_64 processors and Apple Silicon) for iOS and Mac.
101+
- [Github: Homebrew MacOS Cross-Compilation Toolchains](https://github.com/messense/homebrew-macos-cross-toolchains)
102+
- [Stack Overflow: How do I cross compile a Rust application from macOS x86 to macOS Silicon?](https://stackoverflow.com/questions/66849112/how-do-i-cross-compile-a-rust-application-from-macos-x86-to-macos-silicon)
103+
104+
105+
# Further Info
106+
- [The Rust Book: Platform Support](https://doc.rust-lang.org/rustc/platform-support.html)
107+
- [Rust-Lang Users: Compile rust binary for older versions of Mac OSX](https://users.rust-lang.org/t/compile-rust-binary-for-older-versions-of-mac-osx/38695/6)
108+
- [William Saar's Blog: Shipping Linux binaries that don't break with Rust](https://saarw.github.io/dev/2020/06/18/shipping-linux-binaries-that-dont-break-with-rust.html)
109+
- [The World Aflame: Cross-compiling a simple Rust web app](https://www.andrew-thorburn.com/cross-compiling-a-simple-rust-web-app/)

0 commit comments

Comments
 (0)