jguhlin / minimap2-rs

Rust bindings to minimap2 library
Other
60 stars 13 forks source link

Trying a musl build #6

Closed wdecoster closed 1 year ago

wdecoster commented 1 year ago

Hi,

For my project that uses minimap2 I am trying to make musl binaries (cargo build --release --target=x86_64-unknown-linux-musl) to support older hardware too. I don't know if the solution to the error below is obvious, but do you have any suggestions?

   Compiling minimap2-sys v0.1.6
error: failed to run custom build command for `minimap2-sys v0.1.6`

Caused by:
  process didn't exit successfully: `/home/wdecoster/wsl-repos/nanofiltrs/target/release/build/minimap2-sys-486e5a878d273372/build-script-build` (exit status: 101)
  --- stdout
  "/home/wdecoster/wsl-repos/nanofiltrs/target/x86_64-unknown-linux-musl/release/build/minimap2-sys-d37dc23034f6f450/out"
  cargo:rerun-if-changed=minimap2/*.c
  cargo:rerun-if-env-changed=ZLIB_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_x86_64_unknown_linux_musl
  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_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-musl
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_musl
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: pkg-config has not been configured to support cross-compilation.

  Install a sysroot for the target platform and configure it via
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
  cross-compiling wrapper for pkg-config and set it via
  PKG_CONFIG environment variable.', /home/wdecoster/.cargo/registry/src/github.com-1ecc6299db9ec823/minimap2-sys-0.1.6/build.rs:18:49
jguhlin commented 1 year ago

Definitely a conundrum.

For your immediate problem, you need PKG_CONFIG_ALLOW_CROSS=1, but then it gives a zlib error (zlib is not part of musl's default libraries).

I've added it through cargo and the build.rs script, so this command gets further:

PKG_CONFIG_ALLOW_CROSS=1 cargo build --release --target=x86_64-un
known-linux-musl

But now we have a weird error,

cargo:warning=In file included from /usr/include/assert.h:35,
  cargo:warning=                 from minimap2/align.c:1:
  cargo:warning=/usr/include/features.h:461:12: fatal error: sys/cdefs.h: No such file or directory
  cargo:warning=  461 | #  include <sys/cdefs.h>
  cargo:warning=      |            ^~~~~~~~~~~~~
  cargo:warning=compilation terminated.
  exit status: 1

It's weird because musl-gcc should overwrite -I /usr/include to point to musl's version of the header, which would not have that error. And musl-gcc is being used:

running: "musl-gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64" "-static" "-I" "/usr/include" "-I" "min
imap2" "-DHAVE_KALLOC" "-O2" "-lm" "-lpthread" "-o" "/mnt/c/Development/minimap2-rs/minimap2-sys/target/x86_64-unknown-lin
ux-musl/release/build/minimap2-sys-563afacb72323465/out/minimap2/align.o" "-c" "minimap2/align.c"

If you could pull from GitHub and try running that commands in the minimap2-sys directory and let me know what you get, that could help (I'm on wsl2 b/c at home today, which adds an extra layer of configuration problems).

jguhlin commented 1 year ago

Wondering if this container would work for you?

https://github.com/messense/rust-musl-cross#prebuilt-images

You download the container and create an alias, then run this:

rust-musl-builder cargo build --release

It worked on my WSL2. If you can build minimap2-sys with it, I'll push the changes for the main crate to work (it needs that libz stuff I added still)