From 15990d52b63adbca0fda5b917d8eadeea65a1c34 Mon Sep 17 00:00:00 2001 From: jb-alvarado Date: Thu, 24 Mar 2022 14:49:42 +0100 Subject: [PATCH] add cross compile support for macOS --- .cargo/config | 7 +++++++ docs/developer.md | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 .cargo/config diff --git a/.cargo/config b/.cargo/config new file mode 100644 index 00000000..4391721d --- /dev/null +++ b/.cargo/config @@ -0,0 +1,7 @@ +[target.x86_64-apple-darwin] +linker = "x86_64-apple-darwin20.4-clang" +ar = "x86_64-apple-darwin20.4-ar" + +[target.aarch64-apple-darwin] +linker = "aarch64-apple-darwin20.4-clang" +ar = "aarch64-apple-darwin20.4-ar" diff --git a/docs/developer.md b/docs/developer.md index 81960d5b..a6e6bded 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -28,3 +28,29 @@ Running `cargo build` ends up in a binary which depend on **libc.so**. But you c Compile with: `cargo build --release --target=x86_64-unknown-linux-musl`. This release should run on any Linux distro. + +### Compile from Linux for macOS + +Add toolchain: + +```Bash +# for arm64 +rustup target add aarch64-apple-darwin + +# for x86_64 +rustup target add x86_64-apple-darwin +``` + +Follow this guide: [rust-cross-compile-linux-to-macos](https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html) + +Or setup [osxcross](https://github.com/tpoechtrager/osxcross) correctly. + +Add **osxcross/target/bin** to your **PATH** and run cargo with: + +```Bash +# for arm64 +CC="aarch64-apple-darwin20.4-clang -arch arm64e" cargo build --release --target=aarch64-apple-darwin + +# for x86_64 +CC="o64-clang" cargo build --release --target=x86_64-apple-darwin +```