Allow running Cargo binaries directly#77
Conversation
Using linker hacks.
|
Actually, I tested, even the If it is though, then we can maybe even do some trickery in |
|
Another option is something I discussed with @daxpedda years ago, which is that newer versions of Android seems to allow loading libraries with the executable bit set (though IIRC you may have to configure some manifest option or smth). |
|
In That still resulted in some warning I have yet to resolve, but might be a viable alternative to telling the linker to produce a shared library from an executable which may in some extreme cases clash with (user-set?) compilation flags. |
|
Would the following work? [lib]
crate-type = ["cdylib"]
path = "./main.rs"(I haven't managed to make it work yet) |
|
@nicoburns that approach would "break" existing crates consisting of a library and one or more binaries, and also isn't applicable to example targets. Over the years I've tried all these methods and while explicitly setting |
I strongly dislike the extra
*_android.rsexample files that we need insoftbuffer. These are required because we have to tell Cargo to generate acdylibwithcrate-type = ["cdylib"]for each example that runs on Android.Instead of that, we can pass
-Clink-arg=-shared -Clink-arg=-no-pietorustc, together with#![no_main], which tricks the linker into thinking that thebin/ executable target is actually a dynamic library.This means that all a user of
winithas to do is:Which, to be fair, is still a mouthful, but it's better, and it could be reduced with macros. Have a look at this branch for trying it out in
softbuffer.Opened as a draft to show you that it's possible. I haven't polished it yet, but I'd like to know if a hack like this is something you'd be interested in before proceeding.