Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac Arm64 Support & Example? #7

Closed
cjgratacos opened this issue Dec 21, 2021 · 6 comments
Closed

Mac Arm64 Support & Example? #7

cjgratacos opened this issue Dec 21, 2021 · 6 comments
Labels
arm64 darwin enhancement New feature or request help wanted Extra attention is needed

Comments

@cjgratacos
Copy link

cjgratacos commented Dec 21, 2021

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"
@cjgratacos cjgratacos changed the title Mac Arm64 Suppor & Example? Mac Arm64 Support & Example? Dec 21, 2021
@joseluisq joseluisq added enhancement New feature or request help wanted Extra attention is needed labels Dec 21, 2021
@joseluisq
Copy link
Owner

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.

@xrl
Copy link

xrl commented Dec 21, 2021

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!

@joseluisq
Copy link
Owner

joseluisq commented Dec 21, 2021

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.

@cjgratacos
Copy link
Author

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 :)

@joseluisq
Copy link
Owner

Released on v1.65.0

@CGamesPlay
Copy link

CGamesPlay commented Nov 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm64 darwin enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants