mozilla / rust-android-gradle

Apache License 2.0
1.03k stars 67 forks source link

Native Android cross compilation, how to do? #101

Closed lattice0 closed 2 years ago

lattice0 commented 2 years ago

Sorry for asking here but I think it's appropriate. The tutorial for Rust cross compiling on Mozilla's website is old and doesn't work for newer SDKs. This repo is good for most stuff, but I need intellisense to work on VSCode, and for that I need native cross compiling to Android, without gradle, so rust-analyzer can call it periodically.

Is there a modern way to specify the NDK paths so it just works? Passing cargo build --target x86_64-linux-android fails because I need to specify the NDK clangs.

ncalexan commented 2 years ago

Sorry for asking here but I think it's appropriate.

Well, it's certainly not appropriate for rust-android-gradle, but it does reach me.

The tutorial for Rust cross compiling on Mozilla's website is old and doesn't work for newer SDKs. This repo is good for most stuff, but I need intellisense to work on VSCode, and for that I need native cross compiling to Android, without gradle, so rust-analyzer can call it periodically.

Is there a modern way to specify the NDK paths so it just works? Passing cargo build --target x86_64-linux-android fails because I need to specify the NDK clangs.

You'll need to duplicate what rust-android-gradle does to configure the build. You can do this by hard-coding paths in .cargo/config (as the blog post does) or you can set environment variables (as the plugin does; see also this Rust documentation).

I will point out that cargo ndk is essentially doing this configuration for you at the Cargo/Rust level. At some point in the future, we might choose to layer rust-android-gradle on top of cargo ndk, isolating the Gradle-specific bits away from the general "here's how you target Android with Rust" bits. See the discussion in #40 for more context.

However, this is all irrelevant to rust-android-gradle, so I'm going to close this.

lattice0 commented 2 years ago

Thank you for your help with something unrelated to this repo, your help was not in vain. I was able to do a PR to fix some issues with cargo ndk and I'm trying to make cargo check as well so it works with rust-analyzer. Some projects are android specific and won't compile without the NDK so rust-analyzer supporting cargo ndk check would be very nice.

ncalexan commented 2 years ago

Thank you for your help with something unrelated to this repo, your help was not in vain. I was able to do a PR to fix some issues with cargo ndk and I'm trying to make cargo check as well so it works with rust-analyzer. Some projects are android specific and won't compile without the NDK so rust-analyzer supporting cargo ndk check would be very nice.

Happy to help. I'd like to see this ecosystem continue to thrive :)