Mac Arm64 Support & Example?
cjgratacos opened this issue ยท 6 comments
Thanks for the awesome tool.
I was wondering if it is possible to cross compile to aarch64-apple-darwin rust target (arm64 darwin) since this is using https://github.com/tpoechtrager/osxcross? If so can an example be given and update the read me with it? I know the Readme talks about it but it is not clear and it doesn't work.
Example of how I am trying to compile the project:
docker run --rm \
--volume "${PWD}/":/root/src:z \
--workdir /root/src \
joseluisq/rust-linux-darwin-builder:1.57.0 \
sh -c "rustup target add aarch64-apple-darwin && CC=oa64-clang CXX=oa64-clang++ LIBZ_SYS_STATIC=1 cargo build --release --target aarch64-apple-darwin"
The image is amd64
only. So it's not supported out-of-the-box from the Docker image standing point.
However yeah it's possible to cross compile to aarch64-apple-darwin
since we are using osxcross but this involves more setup to do.
So this issue should be a nice to have feature request.
What is the more work required? I started building aarch64 (but don't have an ARM64 Darwin laptop yet) with:
rustup target add aarch64-apple-darwin && \
added in to the Dockerfile. Then in my app's CI I can build the binary with:
cargo build --target aarch64-apple-darwin --release
and my cargo-config.toml
has this entry:
[target.aarch64-apple-darwin]
linker = "arm64e-apple-darwin21.1-clang"
ar = "arm64e-apple-darwin21.1-ar"
with all three of those tweaks, my CI builds go through, no error. The compiled aarch64 binary looks about the right size as the other artifacts. Your mileage may vary!
Yeah, that also was my impression at first glance. Like touching cargo config and adding the corresponding toolchain.
Honestly I didn't tried myself aarch64-apple-darwin
since I don't target it.
But as I said should work unless the reporter needs some specific things.
Sorry for the delay response, but the following works:
- adding the following to
./.cargo/config.toml
[target.aarch64-apple-darwin]
linker = "arm64e-apple-darwin21.1-clang"
ar = "arm64e-apple-darwin21.1-ar"
- running the following on the root of the project:
docker run --rm \
--volume "${PWD}/":/root/src:z \
--workdir /root/src \
joseluisq/rust-linux-darwin-builder:1.60.0 \
sh -c "rustup target add aarch64-apple-darwin && CC=oa64-clang CXX=oa64-clang++ LIBZ_SYS_STATIC=1 cargo build --release --target aarch64-apple-darwin"
Thanks to @xrl for the suggestion :)
Just wanted to publicly document some stupidity on my part. o64-clang
is for x86_64, and oa64-clang
is for aarch64. If you don't notice the "a", you will get many strange errors that do not appear to have anything to do with the C compiler. Here are a handful of the errors that I got that were all caused by using the wrong value for CC
/CXX
:
NEON intrinsics not available with the soft-float ABI. Please use -mfloat-abi=softfp or -mfloat-abi=hard
Attempting to add these flags would result in "ignored parameter" warnings, since the compiler you are using is wrong.ld: in .../target/aarch64-apple-darwin/release/deps/libring-0b5af5c61e1ef982.rlib(7effb53edfc7fa2d-mem.o), archive member '7effb53edfc7fa2d-mem.o' with length 3400 is not mach-o or llvm bitcode for architecture arm64
Yep, because it was bitcode for x86_64.linking with `cc` failed: exit status: 1
Rustc just uses the completely wrong linker (cc
) despite the correct linker being configured. Unsure why this happens, but it's caused by using the wrong compiler.