-
Notifications
You must be signed in to change notification settings - Fork 13
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 compiling to linux android #66
Comments
Works with cross build --target aarch64-linux-android Initial work on #66
@jianshu93 I've created an android branch, can you try to compile it and run tests? minimap2-sys compiles just fine, but the main crate is complaining about missing libz.so, but I believe it is in the NDK (I'm just using cross to compile). Let me know how you get on. |
Hi @jguhlin, I just tested, it was successful. Maybe we need some code cleaning for the new Rust v1.82? I attached the building and test: warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument] warning: warning: warning: warning: warning: warning: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: unused variable: warning: value assigned to warning: variable does not need to be mutable warning: unused variable: warning: unused variable: warning: running 23 tests test result: ok. 23 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.19s Doc-tests minimap2 running 23 tests test result: ok. 23 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.42s Thanks so much! let me know how I can use it when adding to crate.io (e.g., a feature?) Thanks, Jianshu |
Hi @jguhlin, Check this for compiling with easy: https://github.com/BrainiumLLC/cargo-mobile I still manually setup android studio toolchain path but this may be more convenient. Thanks, Jianshu |
@jianshu93 For now use the branch. Later it won't need a feature (probably). I don't want to merge this until I can get the tests to run using cross. |
Hi @jguhlin, I forget to mention, you also need to configure the cargo configure file under ~/.cargo/config.toml: [target.aarch64-linux-android] Tell the linker to use android studio provided clang. Not sure how this can be integrated. |
Also, the test module, binary is for android, we cannot run the binary to test right. I ran cargo test --target aarch64-linux-android, it told me that the binary cannot be executed: Caused by: Thanks, Jianshu |
I've opened up a discussion on cross here: cross-rs/cross#1537 For not being able to run the binary, is it the same architecture? aarch64 and the machine you are running on? That's probably the error you are receiving. You could run qemu-aarch64 to emulate aarch64. I'm using these commands to test:
The first two work, the rest do not. Hopefully someone will have some insight and we can merge into the main branch It looks like cross does come with the NDK, so it should compile and run, but is having an issue finding the correct zlib. |
I am having an aarch64 macOS, not sure we can simulate a aarch64-Linux-android. I'm not succesful running the cross test: Jianshus-MBP-2:minimap2-rs-android jianshuzhao$ cross test --target aarch64-linux-android
Jianshu |
@jianshu93 Haven't had any luck figuring out a workaround with cross, but I've merged this branch into main for now. If it does work when you deploy it let me know and I'll make a note of it. |
Hi @jguhlin,
I am not sure whether this is interesting to others but I want to report here. I was trying to import and compile many Rust software packages to Linux-based android device so that we can run them on phones for a mobile bioinformatic era (CPU for phones are now quite powerful, like SnapDragon 3 generation). For pure Rust based packages, I have no problems for example, my GSearch crate, sourmash crate, rust-mDBG crate and many others. However, when I was trying to compiling minimap2-rs, there are tons of problems:
install android studio first and deploy it for rust in .bash_profile like this:
android compiling and ld library
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER="/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang"
export CXX_aarch64_linux_android="/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang++"
export CC_aarch64_linux_android="/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang"
export AR_aarch64_linux_android="/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/llvm-ar"
$ rustup target add aarch64-linux-android
$ cargo build --target aarch64-linux-android --release
error: linking with
/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang
failed: exit status: 1|
= note: LC_ALL="C" PATH="/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/jianshuzhao/Github/SPAdes-4.0.0-Darwin/bin:/Users/jianshuzhao/.cargo/bin:/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:/Users/jianshuzhao/perl5/bin:/usr/local/bin:/opt/homebrew/bin:/Users/jianshuzhao/bin:/opt/homebrew/opt/bzip2/bin:/Users/jianshuzhao/Github/mummer-4.0.0beta5/bin:/Users/jianshuzhao/go/bin:/Users/jianshuzhao/Github/hmmer-3.4/bin:/opt/homebrew/opt/llvm/bin:/opt/homebrew/opt/openjdk/bin:/opt/homebrew/Cellar/coreutils/9.1/bin:/opt/homebrew/opt/ruby/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/Library/TeX/texbin:/usr/local/go/bin" VSLANG="1033" "/Users/jianshuzhao/Library/Android/sdk/ndk/27.0.12077973/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android35-clang" "-Wl,--version-script=/var/folders/mr/8qybn91j5fgdbrcdmq7ckftw0000gn/T/rustcOO9CIw/list" "-Wl,--no-undefined-version" "/var/folders/mr/8qybn91j5fgdbrcdmq7ckftw0000gn/T/rustcOO9CIw/symbols.o" "/Users/jianshuzhao/Github/minimap2-rs-test/target/aarch64-linux-android/release/deps/minimap2_sys-48223b1ce1d5498d.minimap2_sys.49addbfa3dae579b-cgu.0.rcgu.o" "/Users/jianshuzhao/Github/minimap2-rs-test/target/aarch64-linux-android/release/deps/minimap2_sys-48223b1ce1d5498d.035gy82oxncw2556qjxih17mk.rcgu.o" "-Wl,--as-needed" "-Wl,-Bdynamic" "-lm" "-lpthread" "-Wl,-Bstatic" "-llibminimap" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libstd-e8850eccf2f3dd32.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libpanic_unwind-a094c6be714bf5e8.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libobject-bd105c046d7d3f4a.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libmemchr-b65977fbd4d13b26.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libaddr2line-c59b235c1428dacb.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libgimli-4dc541cf9acc0f28.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/librustc_demangle-fcbcb6953c2582a4.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libstd_detect-a5c6c9bf9652d1e7.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libhashbrown-402a49b850a42e97.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_alloc-19962e45d6dd8556.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libminiz_oxide-778d7232beb22b27.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libadler-ce6b56ec013571c3.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libunwind-7757d29c205c9e38.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libcfg_if-439f5a2fb94b85f2.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/liblibc-cbc1d2077079a2d7.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/liballoc-cbbe8b3cfeaabbd2.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/librustc_std_workspace_core-d80ded003c259869.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libcore-556f2758be89c720.rlib" "/Users/jianshuzhao/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-bb1d92eb991222e1.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/Users/jianshuzhao/Github/minimap2-rs-test/target/aarch64-linux-android/release/build/minimap2-sys-47359202de654a64/out" "-o" "/Users/jianshuzhao/Github/minimap2-rs-test/target/aarch64-linux-android/release/deps/libminimap2_sys-48223b1ce1d5498d.so" "-Wl,--gc-sections" "-shared" "-Wl,-soname=libminimap2_sys-48223b1ce1d5498d.so" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-debug" "-nodefaultlibs"
= note: ld.lld: error: unable to find library -lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The following warnings were emitted during compilation:
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
warning: minimap2-sys@0.1.19+minimap2.2.28: clang: warning: -lpthread: 'linker' input unused [-Wunused-command-line-argument]
I can see that android clang does not support -lpthread, which is only for linux. However the android libc (bionic) does support many pthread functions: In Android, all pthread functionality is directly available through the Bionic libc without requiring explicit linking. This means that while you can use pthread functions like pthread_create or pthread_mutex_init, you don't add -lpthread to your linker flags.
I am wondering whther it is possible to add a conditional compiling for android devices so that -phthread is not used but it is actually functioning.
I also want to hear how @lh3 thinks, #63 (comment)_
Thanks,
Jianshu
The text was updated successfully, but these errors were encountered: