BrainiumLLC / cargo-mobile

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

Compiling external source with resulting executable #26

Open szsoftware opened 3 years ago

szsoftware commented 3 years ago

Is it possible to compile an external rust source with that toolchain? For instance tectonic typesetting and a resulting commandline programm instead of the jni lib mechanism. If yes, do you have an example?

Many thanks in advance.

francesca64 commented 3 years ago

Thanks for asking!

cargo-mobile ultimately compiles your Rust code using cargo build with a few target-specific options, so anything you'd normally do with cargo you can generally do here. So, to depend on crates, you'd just add them to your Cargo.toml like normal. Anything with more involved build steps via build.rs/etc. should "just work" as well.

However, if you're looking to create a command-line application, that's a different matter. The Android project we generate is setup to use NativeActivity, which definitely isn't what you'd want for a command-line app. I assume this is something you're trying to do in a rooted environment? If so, I imagine you could just build a fairly normal executable instead of needing an APK. cargo-mobile wouldn't really benefit you at all for that, since I'd assume you could easily just cargo build that directly.

szsoftware commented 2 years ago

Hi there and thank you very much for your detailed explanation.

After some time of abstinence related to this issue I'm working again on it.

Meanwhile I'm on an updated path to reach my goal: getting tectonic typesetting running on android. Actually I'm trying to use the tectonic crate/library directly without the need of doing it the shell/cli way as described here:

https://docs.rs/tectonic/latest/tectonic/

Thus, I have an updated question after some specific information about tectonic. Tectonic has the approach to not necessarily having a full ~4GB texlive distribution installed. Instead it downloads just these texlive parts, needed by the specific latex document.

In short: the cli binary, but also the crate/library "tectonic" need to download something. When I hear "download" and overthink it the android way, immediately "context" and "activity" and "permissions" come to my mind.

As far as I remember, when trying out another path of reaching the above mentioned goal, utilizing termux/tectonic binary, also NPE's within ndk-glue code and related to NativeActivity where the end of my road.

That's the reason why I'm encouraged to dive deeper into your framework now and try the best I can with my limited knowledge.

This former time and also now, my limitation is, not having a working rust-android(studio)-debugging toolchain.

Do have any hint's, tips and thoughts on all of that?

Thank you very much in advance!