BrainiumLLC / cargo-mobile

Rust on mobile made easy!
Apache License 2.0
1.24k stars 52 forks source link

fix: should work for m1 #81

Closed jkelleyrtp closed 3 months ago

jkelleyrtp commented 2 years ago

This adjusts some targets to get cargo-mobile working on macOS with Apple Silicon.

NOTE: Currently, the changes here only work for m1. I have not made any adjustments to adopt both platforms. I plan to get that working sometime in the future, so this PR is just mainly to provide others looking for M1 support a fork to install from.

ArthurKValladares commented 2 years ago

Thanks for taking this on! This has been a long standing issue that we have been blocked internally on by simply not having access to Apple Silicon machines on the engineering team.

const-volatile commented 2 years ago

I think there might be still some more changes required to fully work on M1. Even using this branch I'm getting the following error during linking:

ld: warning: directory not found for option '-L/Users/user/Xcode projects/rust-test/target/aarch64-apple-ios-sim/debug'
ld: library not found for -lrust_test
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The reason seems to be that in the build for the library, the wrong architecture triple is used (aarch64-apple-ios instead of aarch64-apple-ios-sim): [2022-04-28T16:16:12Z INFO bossy] running command "cargo build --package rust-test --manifest-path /Users/user/Xcode projects/rust-test/Cargo.toml --target aarch64-apple-ios --color auto" and waiting for exit

Hence there is no "target/aarch64-apple-ios-sim" directory getting generated (but only "target/aarch64-apple-ios"). To fix this "src/apple/target.rs" might need to be modified to add the target with the triple "aarch64-apple-ios-sim" as well.

jkelleyrtp commented 2 years ago

@const-volatile

I've been manually building the sim target, so yeah I think there's a missing target. To work around it locally:

cargo build --target aarch64-apple-ios-sim