rust-mobile / android-rs-glue

Glue between Rust and Android
Apache License 2.0
904 stars 109 forks source link

crash before reaching my main #245

Closed kollapsderwellenfunktion closed 4 years ago

kollapsderwellenfunktion commented 5 years ago

i'm trying to compile a simple imgui app with cargo-apk. after successfully working through some linking issues(__dso_handle etc.), and manually setting uses_cpp_standard_library to true, i finally got the apk to run but it crashes immediately.

-04 19:11:56.776 9852 9865 D RustAndroidGlueStdouterr: Entering android_main 09-04 19:11:56.776 9852 9865 D RustAndroidGlueStdouterr: Creating application thread 09-04 19:11:56.778 9852 9866 D RustAndroidGlueStdouterr: thread '' panicked at 'assertion failed: (*self.data.get()).is_none()', src/libstd/sync/mpsc/oneshot.rs:90:13

before reaching my main. so i could not set RUST_BACKTRACE.....

i set android_version, target_sdk_version and min_sdk_version to 24.

i use the version from git, it uses android-glue 0.2.3. i'm using android 7.0, perhaps this is the issue.

philip-alldredge commented 5 years ago

This is likely the same issue as #239. The solution is to use the version of android_glue on master and not the one on crates.io. The released version is not compatible with the master version of cargo-apk.

I'd the interested in knowing the cause of needing to manually setting uses_cpp_standard_library to true and your other linker issues. Can you provide any additional details or causes? I'd like for such things to work out of the box.

kollapsderwellenfunktion commented 5 years ago

it now crashes on the vulkan side, so this issue seems to be solved for me, after using android-glue current ;)

i tried to reproduce my linking errors(undefined reference to __dso_handle, can not not reposition ... use -FPIC), but after cleaning everything, they have gone away.

as for the uses_cpp_standard_library issue, i have honestly no understanding, how cargo-apk should even know when to include libc++_shared.

when i include a rustflags = ["-C", "link-arg=-lc++"] in .cargo/config, the parameters get passed to rustc, but i still have no libstdc++_shared included.

i tried to add a .cpp_link_stdlib("c++") to the build.rs of the imgui-sys crate - still does not work.

so i simply set uses_cpp_standard_library to true, which does work.

philip-alldredge commented 5 years ago

@kollapsderwellenfunktion usage of C++ can be specified using -l and c++ as to separate arguments. Please note, that it is not a link argument in this case. While it may detect it if it is specified as a linker argument, it's not the intended use and may not work reliably.

rustflags = ["-l", "-c++"] should work as you intend.

We should probably support other forms:

As far as why this isn't being done automatically, it is because of a problem in the detection algorithm. It only detects it if it is being linked as part of the final rustc command. Obviously, this isn't the case. We should probably just check the final shared library generated and then bundle it in that case.

@mb64 if you can assign this to me, I can take a look at fixing this in the hopefully not too distance future.

kollapsderwellenfunktion commented 5 years ago

i can confirm with rustflags = ["-l", "c++"] everything works out the box :)

thank you for your efforts.

philip-alldredge commented 4 years ago

@kollapsderwellenfunktion Would you mind trying to build your application with the branch at: https://github.com/philip-alldredge/android-rs-glue/tree/245_improve_cpp_standard_lib_detection without using the custom rustflags? This new version should detect the usage of the libc++ shared library and copy the file without needing to specify it in rustflags.