-
Notifications
You must be signed in to change notification settings - Fork 15
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
Cross-compile to Android does not work #4
Comments
Could you submit the stacktrace that you get when trying to compile using cmake? I'm not sure I understand your point about using zeromq's build system. What would be the advantage of using your method vs. statically cross-compiling |
I am building a library for Android that uses zeromq. We have built some scripts that somewhat automate the process but currently we are stuck with NDK r16 To simplify the process I would like that these other libraries are build using cargo. This seems to work for openssl (feature vendored) and for sodiumoxide but not for zmq.
Regarding the
There is no libzmq.a nor a libzmq.so |
Understood. Can you run |
The first naive try does not find the compiler.
and cmake suggest the 'wrong' compiler. Current Android clang compilers have the Android-API in their name.
|
From what I understand cmake is running a test to check if the supplied compilers are working. But since you are cross compiling you can't actually run an executable on host. From what I understand the solution would be to disable these tests. We can do so by passing |
I think the linker is failing because it is not finding some file like e.g. crtend_android.o |
I added the ability to pass abitrary cmake definitions in this WIP PR #5. I'm passing CMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY. Please run edit: Nevermind I forgot to |
Please see attached file for the output. No change, I think. |
No change indeed. Sorry I can't help much. This seems to be an issue related to the cmake configuration and I don't have any experience using cmake in a cross-compiling context. |
Then maybe use my PR which doesn't use cmake but configure && make? |
I don't really think it makes sense to merge that PR considering it doesn't have any proper linking logic (which is why it doesn't compile in the first place). The purpose of this crate is to be able to use Does that make sense? |
I agree on the purpose of this crate. It should be integrated in libzmq-rs and rust-zmq behind a feature flag 'vendored' I think it a good idea to follow the example of the openssl source crate openssl-src Which calls openssl's I think the PR brings this crate forward. Regarding reliability, I think that ./Configure is THE way to build openssl from source. |
Yes I don't disagree with using configure and make, I'm more worried about the linking procedure. As you can see in the crate that you link, making it work for multiple arch seems like a real headache. The reason openssl is not build using cmake is because there is no support for it (i.e. no `CMakeLists.txt anywhere in the project). I can't really merge the PR as is since it as no linking logic currently. But I saw that it is now a WIP. |
I can compile for Android using cmake without any problem. These are the full steps: Download and unzip Android NDK. Now run:
So the key to this is to use |
Works for me too. Thanks for checking this out. I thought that make-standalone-toolchain.sh was deprecated by Google/Android. |
I manage to build it without standalone toolchain. Create
Now you can build with:
Of-course we can avoid all the above by improving cmake-rs. |
There is an issue for that here: rust-lang/cmake-rs#80 |
I could not get this crate to work for
cargo build --target=aarch64-linux-android
Even if I tell cargo which compilers to use. The following does not work:
ANDROID_API=28 PATH=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH CC=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang CXX=$NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android28-clang++ cargo build --target=aarch64-linux-android
The value for $NDK is set using
I suggest to use zeromq's own build system in this crate, that is basically
cd vendor && ./autogen.sh && HOST_TAG=linux-x86_64 NDK=$HOME/Android/Sdk/ndk-bundle LIBZMQ_SYS_STATIC=1 PATH=$NDK/toolchains/llvm/prebuilt/HOST_TAG/bin:$PATH CC=$NDK/toolchains/llvm/prebuilt/$HOST_TAG/bin/aarch64-linux-android28-clang CXX=$NDK/toolchains/llvm/prebuilt/$HOST_TAG/bin/aarch64-linux-android28-clang++ ./configure --target= --host=x86_64-linux-gnu --enable-static --disable-shared --prefix=/usr/local/aarch64-linux-android && make
If you are not on Linux you have to use the correct HOST_TAG for your system.
Just see what is there after installing Android Studio.
I wouldn't mind you get cmake do the job but a PR doing this with ./configure is #3
The text was updated successfully, but these errors were encountered: