jguhlin / minimap2-rs

Rust bindings to minimap2 library
Other
51 stars 11 forks source link

Compiling for aarch64? #49

Closed wdecoster closed 5 months ago

wdecoster commented 5 months ago

Hi,

Someone is asking for an aarch64 version of chopper (https://github.com/wdecoster/chopper/issues/22). It is the first time I have to compile something for that system, so bear with me :) I am running this on a WSL Ubuntu.

For chopper, cargo build --target aarch64-unknown-linux-gnu results in

warning: aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-msse2’

error: failed to run custom build command for `minimap2-sys v0.1.15+minimap2.2.26`

(let me know if the entire error is of interest)

I noticed you have some feature to select for aarch64 (or at least, I think that is what it means), so I tried for a clone of the minimap2-rs repo: cargo build --target aarch64-unknown-linux-gnu --features sse2only However, this result in the error below. Do you have an idea on how to fix this?

   Compiling minimap2-sys v0.1.16+minimap2.2.26
The following warnings were emitted during compilation:

warning: aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-sse4.1’

error: failed to run custom build command for `minimap2-sys v0.1.16+minimap2.2.26`

Caused by:
  process didn't exit successfully: `/home/wdecoster/wsl-repos/minimap2-rs/target/debug/build/minimap2-sys-81b1bf1b67e72476/build-script-build` (exit status: 1)
  --- stdout
  aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-link-lib=m
  cargo:rustc-link-lib=pthread
  cargo:rerun-if-changed=minimap2/*.c
  cargo:rerun-if-env-changed=ZLIB_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_unknown_linux_gnu
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  TARGET = Some("aarch64-unknown-linux-gnu")
  HOST = Some("x86_64-unknown-linux-gnu")
  cargo:rerun-if-env-changed=CC_aarch64-unknown-linux-gnu
  CC_aarch64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CC_aarch64_unknown_linux_gnu
  CC_aarch64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CC
  TARGET_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  RUSTC_LINKER = None
  cargo:rerun-if-env-changed=CROSS_COMPILE
  CROSS_COMPILE = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  cargo:rerun-if-env-changed=CFLAGS_aarch64-unknown-linux-gnu
  CFLAGS_aarch64-unknown-linux-gnu = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_unknown_linux_gnu
  CFLAGS_aarch64_unknown_linux_gnu = None
  cargo:rerun-if-env-changed=TARGET_CFLAGS
  TARGET_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  running: "aarch64-linux-gnu-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-I" "minimap2" "-I" "minimap2/" "-I" "minimap2/sse2neon/" "-I" "/home/wdecoster/wsl-repos/minimap2-rs/target/aarch64-unknown-linux-gnu/debug/build/libz-sys-e9163c495f1107f6/out/include" "-Wc++-compat" "-DKSW_SSE2_ONLY" "-mno-sse4.1" "-DKSW_SSE2_ONLY" "-D_FILE_OFFSET_BITS=64" "-fsigned-char" "-Isse2neon" "-D__SSE2__" "-DHAVE_KALLOC" "-lm" "-lpthread" "-o" "/home/wdecoster/wsl-repos/minimap2-rs/target/aarch64-unknown-linux-gnu/debug/build/minimap2-sys-7f36ee3d7b468824/out/minimap2/sdust.o" "-c" "minimap2/sdust.c"
  cargo:warning=aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-sse4.1’

  exit status: 1

  --- stderr

  error occurred: Command "aarch64-linux-gnu-gcc" "-O2" "-ffunction-sections" "-fdata-sections" "-fPIC" "-gdwarf-4" "-fno-omit-frame-pointer" "-I" "minimap2" "-I" "minimap2/" "-I" "minimap2/sse2neon/" "-I" "/home/wdecoster/wsl-repos/minimap2-rs/target/aarch64-unknown-linux-gnu/debug/build/libz-sys-e9163c495f1107f6/out/include" "-Wc++-compat" "-DKSW_SSE2_ONLY" "-mno-sse4.1" "-DKSW_SSE2_ONLY" "-D_FILE_OFFSET_BITS=64" "-fsigned-char" "-Isse2neon" "-D__SSE2__" "-DHAVE_KALLOC" "-lm" "-lpthread" "-o" "/home/wdecoster/wsl-repos/minimap2-rs/target/aarch64-unknown-linux-gnu/debug/build/minimap2-sys-7f36ee3d7b468824/out/minimap2/sdust.o" "-c" "minimap2/sdust.c" with args "aarch64-linux-gnu-gcc" did not execute successfully (status code exit status: 1).
ImagoXV commented 5 months ago

I've been trying to compile it directly on my aarch64 with

cargo build --target aarch64-unknown-linux-gnu

However, my errors are different from yours : No sign of problematic -mno-sse4.1

However, it looks more like a generic function definition error somehow :

Here is the log

rror[E0277]: the trait bound `*const u8: From<Preset>` is not satisfied
   --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:429:24
    |
429 |             mm_set_opt(preset.into(), &mut idxopt, &mut mapopt)
    |                        ^^^^^^ ---- required by a bound introduced by this call
    |                        |
    |                        the trait `From<Preset>` is not implemented for `*const u8`
    |
    = help: the following other types implement trait `From<T>`:
              <*const i8 as From<Preset>>
              <f32 as From<i16>>
              <f32 as From<i8>>
              <f32 as From<u16>>
              <f32 as From<u8>>
              <f64 as From<f32>>
              <f64 as From<i16>>
              <f64 as From<i32>>
            and 68 others
    = note: required for `Preset` to implement `Into<*const u8>`

error[E0308]: arguments to this function are incorrect
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:665:13
     |
665  |             mm_idx_str(
     |             ^^^^^^^^^^
     |
note: expected `u8`, found `i8`
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:671:17
     |
671  |                 seqs.as_ptr() as *mut *const i8,
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: expected raw pointer `*mut *const u8`
                found raw pointer `*mut *const i8`
note: expected `u8`, found `i8`
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:672:17
     |
672  |                 ids.as_ptr() as *mut *const i8,
     |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = note: expected raw pointer `*mut *const u8`
                found raw pointer `*mut *const i8`
note: function defined here
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-sys-0.1.15+minimap2.2.26/src/bindings.rs:8188:12
     |
8188 |     pub fn mm_idx_str(
     |            ^^^^^^^^^^

error[E0308]: mismatched types
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:751:21
     |
748  |                 mm_map(
     |                 ------ arguments to this function are incorrect
...
751  |                     seq.as_ptr() as *const i8,
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
     |
     = note: expected raw pointer `*const u8`
                found raw pointer `*const i8`
note: function defined here
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-sys-0.1.15+minimap2.2.26/src/bindings.rs:8227:12
     |
8227 |     pub fn mm_map(
     |            ^^^^^^

error[E0308]: mismatched types
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:861:37
     |
855  | ...                   let _cs_len = mm_gen_cs(
     |                                     --------- arguments to this function are incorrect
...
861  | ...                       seq.as_ptr() as *const i8,
     |                           ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
     |
     = note: expected raw pointer `*const u8`
                found raw pointer `*const i8`
note: function defined here
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-sys-0.1.15+minimap2.2.26/src/bindings.rs:8270:12
     |
8270 |     pub fn mm_gen_cs(
     |            ^^^^^^^^^

error[E0308]: mismatched types
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-0.1.15+minimap2.2.26/src/lib.rs:880:37
     |
874  | ...                   let _md_len = mm_gen_MD(
     |                                     --------- arguments to this function are incorrect
...
880  | ...                       seq.as_ptr() as *const i8,
     |                           ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found `i8`
     |
     = note: expected raw pointer `*const u8`
                found raw pointer `*const i8`
note: function defined here
    --> /home/minit/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-sys-0.1.15+minimap2.2.26/src/bindings.rs:8281:12
     |
8281 |     pub fn mm_gen_MD(
     |            ^^^^^^^^^

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `minimap2` due to 5 previous errors
warning: build failed, waiting for other jobs to finish...

Somehow, for me, the problem lies in a raw pointer to a constant u8 that is found as an integer.

I don't know more at the moment

ImagoXV commented 5 months ago

I did it

I compiled it directly on the aarch64 machine. I updated rustc and everything that needed to be, that worked up smoothly

./chopper --help
Filtering and trimming of fastq files. Reads on stdin and writes to stdout.

Usage: chopper [OPTIONS]

Options:
  -q, --quality <MINQUAL>      Sets a minimum Phred average quality score [default: 0]
      --maxqual <MAXQUAL>      Sets a maximum Phred average quality score [default: 1000]
  -l, --minlength <MINLENGTH>  Sets a minimum read length [default: 1]
      --maxlength <MAXLENGTH>  Sets a maximum read length [default: 2147483647]
      --headcrop <HEADCROP>    Trim N nucleotides from the start of a read [default: 0]
      --tailcrop <TAILCROP>    Trim N nucleotides from the end of a read [default: 0]
  -t, --threads <THREADS>      Use N parallel threads [default: 4]
  -c, --contam <CONTAM>        Filter contaminants against a fasta
      --inverse                Output the opposite of the normal results
  -h, --help                   Print help
  -V, --version                Print version
chopper_aarch64/target/aarch64-unknown-linux-gnu/debug$ file chopper
chopper: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=7e53baa258c7d121b13ff02d9d244a2661c4f9ff, with debug_info, not stripped
jguhlin commented 5 months ago

@wdecoster @ImagoXV

Glad you solved it. I haven't been able to get cross-compilation to work, but someone got it to compile directly on the machine just fine. The issue is minimap2 itself will compile on the host machine, regardless of the target, and then linking won't work.

If you found anything that would be helpful here, let me know and I'll implement!