-
Notifications
You must be signed in to change notification settings - Fork 109
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
Possible to work with cargo binaries? #113
Comments
@swiftcoder I don't think so because Android expects shared libraries ( I have however seen |
An Android application is always a Java application. How cargo-apk works is it enables the native activity which forwards all Java events to the ndk glue. So that the rust application can be used it needs to be loaded as a cdylib from the Java VM. The reason we don't have any Java code in this repo is because the default native activity works well, and replacing it with our own Java would not yield any benefit. |
Yes, I understand the technical limitation. However the end result is that it is quite inconvenient to work with android binaries in a normal rust workflow. I'm going to end up scattering dozens of empty lib.rs/main.rs around to keep both In an ideal world we would be able to augment |
The original cargo-apk did that. It was very complex and unmaintainable. This is the sacrifice that was made to have a clean and hackable codebase that has had many contributors contribute features and improvements. |
Maybe cargo-mobile can help take care of the boilerplate? @francesca64 |
Fyi I think the real problem is this rust-lang/cargo#4881 |
That's definitely an issue I've run into in the past, but I'm not sure to what extent it intersects with this issue. If I have a pretty standard single-crate rust project like so:
Then I haven't been deep inside cargo - is there any way for us to get at the anonymous crates for each binary, rather than relying on the singular library crate? |
So main.rs is an entry point for desktop, you don't need that for mobile. So you should be able to use The problem with the examples is that we can't select a crate type depending on the target. If we could you could use |
Indeed, but I want it on mobile. Main.rs contains program logic (and relies on dependencies) that aren't relevant to the library crate. |
I'll reiterate some downsides imo of the approach you're suggesting for reference and discussion:
If someone comes up with a good solution I might change my mind, this is just my opinion at the moment. |
You can always make a separate crate that references your library crate, and has: ...
autobins = true # The default
[lib]
path = "src/main.rs"
crate-type = ["cdylib"] Other than that I think this issue covered all the reasoning and can be closed? Android native applications are libraries loaded by Android instead of executables and there's nothing we should hack in to change or hide that IMO - unless it's trivial. |
So, cargo-mobile can indeed help you generate boilerplate for pretending your lib.rs is a regular main.rs, and wrapping it as a binary on desktop platforms. I'm not sure if that's exactly what you want, and it also sounds like you want to actually have some separate logic in your main.rs, that you wouldn't want to have in your library crate at all? It also can't currently help with your examples problem, though it's not necessarily out of scope. |
Is it possible for ndk_glue::main to operate on binary targets? At the moment I'm having to make fake library targets for each of my binaries and example binaries, in order to get ndk_glue::main to generate the appropriate shim.
The text was updated successfully, but these errors were encountered: