rust-mobile / rust-android-examples

Various standalone Rust Android examples
112 stars 21 forks source link

na-mainloop: Drop unneeded `cargo-apk` setup and add `xbuild` docs #9

Open MarijnS95 opened 1 year ago

MarijnS95 commented 1 year ago

Without configuration cargo-apk uses the default rust.<package> namespace, instead of the hardcoded com.foo.bar. Similarly xbuild can build and run this project out of the box, no extra configuration (nor installation / dependencies!) required.

Draft because it seems we have a lot more projects to clean up, and maybe even guides to deduplicate...

rib commented 1 year ago

Yeah this sounds probably ok if they can Just Work(tm) - maybe the gradle builds could be configured with the same application Id that cargo apk / xbuild will come up with by default. Does xbuild have the same default as cargo apk here?

Btw, it would be kinda interesting to know if it would be possible to have xbuild also work with the agdk examples at some point, and those would need some kind of config for knowing to fetch the game-activity dependency.

MarijnS95 commented 1 year ago

Does xbuild have the same default as cargo apk here?

Afaik they're different.

MarijnS95 commented 1 year ago

Btw, it would be kinda interesting to know if it would be possible to have xbuild also work with the agdk examples at some point, and those would need some kind of config for knowing to fetch the game-activity dependency.

xbuild has gradle support, but I've never toyed with it. Would be lovely if you could!

MarijnS95 commented 1 year ago

cargo-apk uses rust(.example).<package name>: https://github.com/rust-mobile/cargo-apk/blob/0f47f04442d7667ce021a27404f4d57dd25aa549/cargo-apk/src/apk.rs#L164-L169

xbuild uses com.example.<package name>: https://github.com/MarijnS95/xbuild/blob/84ad909a32d694ebae17ad3a4f2d223a29fcc561/xbuild/src/config.rs#L90-L92

rib commented 1 year ago

xbuild has gradle support, but I've never toyed with it. Would be lovely if you could!

I don't really know where to start with configuring xbuild without looking at the implementation atm, the README doesn't show any examples and I haven't seen it reference any example projects. Can you maybe link to some open source example with an xbuild config to get a starting point for knowing what's configurable?

MarijnS95 commented 1 year ago

Maybe @dvc94ch has a link. Afaik it's "as simple as" setting gradle: true under android: in manifest.yaml, at least that's what's being done for the template.

Supposedly it creates a bunch of files in the source dir for you, at least if mod.rs is believed:

https://github.com/rust-mobile/xbuild/tree/master/xbuild/src/gradle

MarijnS95 commented 1 year ago

Well this is awkward. The Ubuntu VM probably has a weird/old clang/LLVM setup as I cannot repro this issue locally, though xbuild itself uses a very similar CI setup to do build-testing.

MarijnS95 commented 1 year ago

I just ran into this myself while trying to teach xbuild to support env vars with spaces.

xbuild sets CARGO_TARGET_<triple>_RUSTFLAGS, and that probably gets skipped/ignored because the CI script already sets RUSTFLAGS, hence it's using the wrong compiler flags.

Its precedence is not documented at https://doc.rust-lang.org/cargo/reference/config.html#buildrustflags, but it probably falls at position 3. (after RUSTFLAGS which is at 2.) as it is supposed to provide a value for target.<triple>.rustflags.