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

Android #90

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/build-test-rust-minimap2-sys.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,24 @@ jobs:
run: cargo test
- name: Run minimap2-sys simde tests
run: cargo test --features simde


test-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Rust Cross
run: rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
- run: cargo install cross --git https://github.com/cross-rs/cross
- run: cd minimap2-sys
- name: Run minimap2-sys tests on Android aarch64
run: cross test --target aarch64-linux-android
- name: Run minimap2-sys tests on Android armv7
run: cross test --target armv7-linux-androideabi
- name: Run minimap2-sys tests on Android i686
run: cross test --target i686-linux-android
- name: Run minimap2-sys tests on Android x86_64
run: cross test --target x86_64-linux-android

test-macos-13:
runs-on: macos-13
steps:
Expand Down
41 changes: 36 additions & 5 deletions minimap2-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

// Configure for minimap2
fn configure(mut cc: &mut cc::Build) {
Expand Down Expand Up @@ -137,10 +137,11 @@ fn compile() {

if !env::var("TARGET").unwrap().contains("android") {
println!("cargo:rustc-link-lib=pthread");
cc.flag("-lpthread");
}

if !env::var("TARGET").unwrap().contains("android") {
cc.flag("-lpthread");
if env::var("CARGO_CFG_TARGET_OS").unwrap() == "android" {
android();
}

cc.flag("-lm");
Expand All @@ -158,16 +159,17 @@ fn compile() {
#[cfg(feature = "static")]
cc.static_flag(true);

println!("cargo:rustc-cfg=link_libz");
// println!("cargo:rustc-cfg=link_libz");

if let Some(include) = std::env::var_os("DEP_Z_INCLUDE") {
cc.include(include);
cc.include(include.clone());
// Use env DEP_Z_ROOT to find the library
if let Some(lib) = std::env::var_os("DEP_Z_ROOT") {
let lib = lib.to_str().unwrap();
println!("cargo:rustc-link-search=native={}", lib);
println!("cargo:rustc-link-lib=static=z");
}

}

if let Ok(lib) = pkg_config::find_library("zlib") {
Expand Down Expand Up @@ -220,6 +222,35 @@ fn gen_bindings() {
#[cfg(not(feature = "bindgen"))]
fn gen_bindings() {}

fn android() {
println!("cargo:rustc-link-lib=z");

// If we are running via cross
if let Ok(sysroot) = env::var("CROSS_SYSROOT") {
let path = PathBuf::from(sysroot).join("usr/lib");
let path = path.join(&env::var("TARGET").unwrap());
println!("cargo:rustc-link-search=native={}", path.display());
let path = path.join("libz.so");
println!("cargo:rustc-link-search=native={}", path.display());
println!("cargo:rustc-link-lib=static=z");


}

if let Ok(output_path) = env::var("CARGO_NDK_OUTPUT_PATH") {
let sysroot_libs_path =
PathBuf::from(env::var_os("CARGO_NDK_SYSROOT_LIBS_PATH").unwrap());
let lib_path = sysroot_libs_path.join("libz.so");
std::fs::copy(
lib_path,
Path::new(&output_path)
.join(&env::var("CARGO_NDK_ANDROID_TARGET").unwrap())
.join("libz.so"),
)
.unwrap();
}
}

fn main() {
compile();
gen_bindings();
Expand Down
2 changes: 1 addition & 1 deletion src/htslib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ impl Aligner {
mm_ffi::mm_map(
self.idx.unwrap() as *const mm_ffi::mm_idx_t,
query.inner.l_seq,
query.inner.seq as *const i8,
query.inner.seq as *const libc::c_char,
&mut n_regs,
buf.borrow_mut().buf,
&map_opt,
Expand Down
Loading