Skip to content
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

Eliminate libc++_shared.so dependency on Android? #17

Open
gavv opened this issue Jun 4, 2020 · 4 comments
Open

Eliminate libc++_shared.so dependency on Android? #17

gavv opened this issue Jun 4, 2020 · 4 comments
Labels
android Android-related tasks build system Build scripts good first issue Good for newcomers help wanted Contributions are welcome

Comments

@gavv
Copy link
Member

gavv commented Jun 4, 2020

On Android, if AAR or APK has native libraries depending on libc++_shared.so (C++ STL from Clang), they should ship a copy of the library.

This, theoretically, may lead to problems if the user wants to use more than one native library and they depend on different versions of libc++_shared.so. It seems that the official recommendation is not use more than one native library.

In our case, both libroc.so and libroc_jni.so depend on libc++_shared.so. Here are the dependencies of libroc.so:

$ aarch64-linux-android-readelf -d ./libroc.so | grep NEEDED
 0x0000000000000001 (NEEDED)             Shared library: [libc++_shared.so]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so]

Here, libc++_shared.so is the only library needed to be shipped. Other libraries, AFAIK, are guaranteed to be available on every Android system.

But actually, I think we could get rid of the dependency on libc++_shared.so:

  • For libroc.so, we can link it statically into libroc.so or maybe even don't use it on Android at all (Roc does not use much of STL).

  • For libroc_jni.so, we can actually don't use C++. It seems that most files can be just renamed from .cpp to .c. It seems that the only C++ feature we're using is std::mutex. We can replace it with pthread_mutex for now (and add non-unix implementation later when needed), or maybe we can somehow move synchronization from C++ side to Java side.

    Port JNI bindings from C++ to C #55

@MatteoArella Thoughts?

@gavv gavv added enhancement New feature or request support and removed enhancement New feature or request labels Jun 4, 2020
@MatteoArella
Copy link
Member

Yes I agree with that problem on libc++_shared.so.
We could link it statically into libroc.so and remove that dependency on libroc_jni.so;
regarding synchronization we can use directly pthread_mutex in my opinion.

@MatteoArella
Copy link
Member

For android library we can remove STL dependency with -DANDROID_STL=none arguments on android gradle plugin;
regarding libroc.so can we set LDFLAGS=-static-libstdc++ before compiling with scons or do you have a different approach?

@gavv
Copy link
Member Author

gavv commented Jun 27, 2020

regarding libroc.so can we set LDFLAGS=-static-libstdc++ before compiling with scons or do you have a different approach?

I didn't try it yet. If LDFLAGS will work well, let's start with it. Later we can add a scons option to enable static-libstdc++ or disable libstdc++ at all.

IIRC Android docs claim that static-libstdc++ is dangerous (i.e. is not guaranteed to work in all cases), so we should carefully test it.

@gavv gavv added enhancement New feature or request hacktoberfest help wanted Contributions are welcome and removed support labels Sep 28, 2020
@gavv gavv removed hacktoberfest help wanted Contributions are welcome labels Dec 4, 2020
@gavv gavv added the help wanted Contributions are welcome label Dec 7, 2022
@gavv gavv added build system Build scripts good first issue Good for newcomers and removed enhancement New feature or request labels Apr 6, 2023
@gavv
Copy link
Member Author

gavv commented Apr 6, 2023

For libroc_jni.so, we can actually don't use C++. It seems that most files can be just renamed from .cpp to .c. It seems that the only C++ feature we're using is std::mutex. We can replace it with pthread_mutex for now (and add non-unix implementation later when needed), or maybe we can somehow move synchronization from C++ side to Java side.

The quoted part part is done in #55.

The remaining part for this issue is to adjust build script for Android to build libroc with static libc++, as suggested in #17 (comment)

The build script to be modified is here: https://github.com/roc-streaming/roc-java/blob/main/scripts/android/build_roc.sh

@gavv gavv added the android Android-related tasks label May 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Android-related tasks build system Build scripts good first issue Good for newcomers help wanted Contributions are welcome
Projects
None yet
Development

No branches or pull requests

2 participants