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

Musl support for htslib 1.10.2 #193

Merged
merged 66 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
0bb745d
Add alternative strategy (local dependencies install) to get musl sup…
brainstorm Mar 18, 2020
a563f5c
Tweaking toolchain further for rust-htslib-musl and its dependencies
brainstorm Mar 18, 2020
17550f5
Circumvent Makefile openssl bug in https://github.com/openssl/openssl…
brainstorm Mar 19, 2020
3a33b5d
Add newly docker baked image with the whole toolchain built staticall…
brainstorm Mar 19, 2020
4f0cbc3
Bypass unneeded CI steps for now to focus on musl
brainstorm Mar 19, 2020
865e3d1
Tell openssl-sys crate where is our custom musl-openssl cross compile…
brainstorm Mar 19, 2020
23b89a8
It is possible that https://github.com/rust-bio/rust-htslib/pull/193/…
brainstorm Mar 19, 2020
3a3c591
Revert linting/formatting steps, those are done (and needed) anyway f…
brainstorm Mar 19, 2020
511a432
Nasty hack with ld, tell musl that its own includes are available via…
brainstorm Mar 19, 2020
9d68756
LDFLAGS and CPPFLAGS need to be passed to hts-sys, plus need to be su…
brainstorm Mar 20, 2020
da356ee
Be a bit more careful with env variables when clippy is running
brainstorm Mar 21, 2020
8d8513b
A bit more classy to pass clippy?
brainstorm Mar 21, 2020
cb60f01
Temporarily try to bypass formatting/linting again, not helping focus…
brainstorm Mar 21, 2020
b90dd51
Passing clang_arg() to bindgen to compile the wrapper with -I/usr/loc…
brainstorm Mar 21, 2020
2da44bb
Hardcoded include path works for both musl and GNU bindgen building, …
brainstorm Mar 21, 2020
f7c108f
Re-enabling formatting and linting Github action phases after green b…
brainstorm Mar 21, 2020
85a9ef4
hfile_s3.o is only included on libhts.a when ./configure is run previ…
brainstorm Mar 26, 2020
a1d7bdf
Make sure we are in htslib directory, otherwise configure.ac and .in …
brainstorm Mar 26, 2020
a738213
Fix up redundant imports according to clippy, switch to alpine linux …
brainstorm Mar 26, 2020
4e66846
Explicitly cross-compile passing the right ./configure --host flag, t…
brainstorm Mar 26, 2020
7c7e283
LDFLAGS was being pointed to CPPFLAGS, copy&paste hell. Also make car…
brainstorm Mar 30, 2020
fe0e8a0
More clippy
brainstorm Mar 30, 2020
ed55bb0
Puzzled as of why this clippy error was not detected locally... also …
brainstorm Mar 30, 2020
b79981f
CPPFLAGS as an argument to make is causing trouble on Linux but not o…
brainstorm Mar 30, 2020
03d9df4
This include does not affect any build and it is crucial for MUSL ones
brainstorm Mar 30, 2020
bb677c8
Back to non-alpine container, not sure why cargo is not being found
brainstorm Mar 30, 2020
038b87b
Disabling --no-default-features building for now, clang-sys not neede…
brainstorm Mar 30, 2020
0ac157b
Merge branch 'master' into musl_support
brainstorm Mar 31, 2020
3604828
Merge branch 'master' into musl_support
johanneskoester Apr 3, 2020
7ac7254
Following @pmarks advice on libz-sys, bump up both libc anb libz-sys …
brainstorm Apr 6, 2020
3c8433a
Enable no-default-features back
brainstorm Apr 6, 2020
c326301
Merge branch 'musl_support' of github.com:brainstorm/rust-htslib into…
brainstorm Apr 6, 2020
92f99ff
Make clippy happy with libz
brainstorm Apr 7, 2020
fed68ab
libz-sys should not be optional, thanks @pmarks
brainstorm Apr 7, 2020
0dcc3e4
Merge branch 'master' of https://github.com/rust-bio/rust-htslib into…
brainstorm Apr 28, 2020
a03c9cb
Merge branch 'master' of https://github.com/rust-bio/rust-htslib into…
Apr 28, 2020
dd21663
Cleaning up flags, trying to have libz as static to avoid //usr/lib64…
brainstorm May 12, 2020
1718236
Merge branch 'musl_support' of https://github.com/brainstorm/rust-hts…
brainstorm May 12, 2020
3241e87
Figured out next steps: need to incorporate static compilation featur…
brainstorm May 12, 2020
4ecf569
Merge branch 'master' of https://github.com/rust-bio/rust-htslib into…
brainstorm May 14, 2020
d8d1c5a
Add missing static flag to lzma-sys, getting rid of the need to expor…
brainstorm May 14, 2020
52ef911
Remove openssl-sys crate in favor of curl-sys, which already includes…
brainstorm May 14, 2020
c767e0e
Temporarily comment out sed modifications against htslib's makefile, …
brainstorm May 14, 2020
c88c068
Semver + suffix on curl is not needed
brainstorm May 15, 2020
7e6ca8d
make -B, that flag was the current culprit on static compilation, biz…
brainstorm May 15, 2020
1ba12f3
Make extra sure that -fPIC flag is passed during all compile phases
brainstorm May 15, 2020
6e587a6
Passing println(cargo:rustc-link-lib=static=hts), works, finally :)
brainstorm May 15, 2020
bd2215a
Cleanup cflgags_patterns mess
brainstorm May 15, 2020
d79bc04
Works locally, migrating to docker/cross builds, MUSL has regressions…
brainstorm May 18, 2020
886ab3e
Cleanup build.rs
brainstorm May 18, 2020
58ff70e
Add clux/muslrust Dockerfile example, as referred on https://users.ru…
brainstorm May 19, 2020
37aee9b
Revert .github workflow minor changes because 'remote rejected] musl_…
brainstorm May 19, 2020
2f2d91e
Adding rust workflow from master...
brainstorm May 19, 2020
ceac6a9
Remove GitHub actions workflows for now since they are blocking my pr…
brainstorm May 19, 2020
37628ef
Thanks @wezm for feedback on MUSL dockerfiles and https://github.com/…
brainstorm May 20, 2020
3cafee8
Finally compiles MUSL, passing CFLAGS=-I/usr/local/musl/include and u…
brainstorm May 21, 2020
b0fa198
Reintroducing the GitHub actions workflow... will I be able to push i…
brainstorm May 21, 2020
f1e3540
Nope, pushes are still blocked by '[remote rejected] musl_support -> …
brainstorm May 21, 2020
da93870
Cleanup and update README with the required cross commands. Also clea…
brainstorm May 22, 2020
82d103e
Merge branch 'master' into musl_support
brainstorm Jun 2, 2020
be58c12
Merge branch 'master' into musl_support
brainstorm Jun 2, 2020
d987c12
Add back github workflow, now that I am a project collab/admin
brainstorm Jun 2, 2020
5656e4a
Make sure MUSL builds find zlib.h et al
brainstorm Jun 2, 2020
b32524b
Sans quotes and let others concatenate CFLAGS
brainstorm Jun 2, 2020
48a329f
Remove clux rust container references and stray -j40 make flag
brainstorm Jun 2, 2020
ff6df84
Merge branch 'master' into musl_support
brainstorm Jun 2, 2020
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
12 changes: 1 addition & 11 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
[target.x86_64-apple-darwin]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]

[target.x86_64-unknown-linux-musl]
rustflags = [
"-C", "link-arg=-undefined",
"-C", "link-arg=dynamic_lookup",
]
linker = "x86_64-linux-musl-gcc"
linker = "x86_64-linux-musl-gcc"
31 changes: 18 additions & 13 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,21 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./lcov.info

# - name: Test musl build without default features
# uses: actions-rs/cargo@v1
# with:
# use-cross: true
# command: build
# args: --target x86_64-unknown-linux-musl --no-default-features
#
# - name: Test musl build with all features
# uses: actions-rs/cargo@v1
# with:
# use-cross: true
# command: build
# args: --target x86_64-unknown-linux-musl --all-features
- name: Test musl build without default features
env:
CFLAGS: -I/usr/local/musl/include
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target x86_64-unknown-linux-musl --no-default-features

- name: Test musl build with all features
env:
CFLAGS: -I/usr/local/musl/include
uses: actions-rs/cargo@v1
with:
use-cross: true
command: build
args: --target x86_64-unknown-linux-musl --all-features

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tag-message = "Version {{version}} of Rust-HTSlib."

[dependencies]
libc = "0.2"
itertools = "0.8"
itertools = "0.9.0"
newtype_derive = "0.1"
custom_derive = "0.1"
url = "2.1"
Expand All @@ -29,16 +29,17 @@ linear-map = "1.2"
serde_base = { version = "^1", optional = true, package = "serde" }
serde_bytes = { version = "0.11", optional = true }
bio-types = ">=0.6"
snafu = ">= 0.5.0, <= 0.6.0"
snafu = "0.6.8"
hts-sys = { version = "^1.10", path = "hts-sys", default-features = false }

[features]
default = ["bzip2", "lzma", "curl"]
bzip2 = ["hts-sys/bzip2"]
lzma = ["hts-sys/lzma"]
curl = ["hts-sys/curl"]
openssl = ["hts-sys/openssl"]
#openssl = ["hts-sys/openssl"]
serde = ["serde_base", "serde_bytes"]
static = []

[dev-dependencies]
tempdir = "0.3"
Expand Down
10 changes: 9 additions & 1 deletion Cross.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
[build.env]
passthrough = [
"RUST_DEBUG",
"RUST_BACKTRACE",
"CFLAGS"
]


[target.x86_64-unknown-linux-musl]
image = "brainstorm/rust_musl_docker:stable-latest-libcurl"
image = "brainstorm/cross-x86_64-unknown-linux-musl:latest"
[target.x86_64-unknown-linux-gnu]
image = "brainstorm/cross-x86_64-unknown-linux-gnu:libcurl-openssl"
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,30 @@ This library provides HTSlib bindings and a high level Rust API for reading and

To clone this repository, issue

```
git clone --recursive https://github.com/rust-bio/rust-htslib.git
```shell
$ git clone --recursive https://github.com/rust-bio/rust-htslib.git
```

ensuring that the HTSlib submodule is fetched, too.
If you only want to use the library, there is no need to clone the repository. Go on to the **Usage** section in this case.

## Requirements

To compile this crate you need the development headers of zlib, bzip2 and xz. For instance, in Debian systems one needs the following dependencies:
To compile this crate you need docker and cross:

```shell
$ cargo install cross
$ cross build # will build with GNU toolchain
```

If you want to run rust-htslib code on AWS lambda, you'll need to statically compile it with MUSL as follows:

```shell
$ export CFLAGS="-I/usr/local/musl/include"
$ cross build --target x86_64-unknown-linux-musl # will build with MUSL toolchain
```

Alternatively, you can also install it locally by installing the development headers of zlib, bzip2 and xz. For instance, in Debian systems one needs the following dependencies:

```shell
$ sudo apt-get install zlib1g-dev libbz2-dev liblzma-dev clang pkg-config
Expand Down
11 changes: 6 additions & 5 deletions docker/Dockerfile.gnu
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM rustembedded/cross:x86_64-unknown-linux-gnu

ENV LIBCLANG_PATH /usr/lib/x86_64-linux-gnu
#ENV LIBCLANG_PATH /usr/lib/x86_64-linux-musl
ENV LIBCLANG_PATH /usr/lib/llvm-10/lib
ENV LLVM_CONFIG_PATH /usr/bin
RUN apt-get update && \
apt-get install -y libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev clang-8 && \
ln -sf /usr/bin/llvm-config-8 /usr/bin/llvm-config && \
ln -sf /usr/lib/x86_64-linux-gnu/libclang-8.so.1 /usr/lib/x86_64-linux-gnu/libclang.so.1
RUN apt-get update
RUN apt-get install -y wget gnupg lsb-release software-properties-common apt-transport-https ca-certificates # Otherwise LLVM bump below fails
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
RUN apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev # htslib deps
120 changes: 117 additions & 3 deletions docker/Dockerfile.musl
Original file line number Diff line number Diff line change
@@ -1,7 +1,121 @@
FROM rustembedded/cross:x86_64-unknown-linux-musl

ENV MUSL_CROSS_MAKE_VERSION 0.9.9
ENV PKG_CONFIG_ALLOW_CROSS 1
ENV OPENSSL_LIB_DIR /usr/lib/x86_64-linux-gnu
ENV OPENSSL_INCLUDE_DIR /usr/include/openssl
ENV LZMA_VERSION 5.2.5
ENV ZLIB_VERSION 1.2.11
ENV OPENSSL_VERSION 1_1_1g
ENV CURL_VERSION 7.70.0

ENV LIBCLANG_PATH /usr/lib/llvm-10/lib
ENV LLVM_CONFIG_PATH /usr/bin


# The default includes and packages from the Ubuntu distro that cross uses will generate all sorts of linux-headers related include errors, see:
# https://github.com/rust-bio/rust-htslib/pull/184#commitcomment-37496651
# Those are the packages installed, hopefully someone will find a good way to use the distro ones instead of compiling everything under /usr/local :/
# apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev musl musl-dev musl-tools linux-libc-dev linux-headers-4.15.0-20-generic

# Install basics to locally compile htslib dependencies
RUN apt-get update && \
apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev musl musl-dev musl-tools linux-libc-dev linux-headers-4.15.0-20-generic
apt-get install -y build-essential autoconf automake autotools-dev git wget

# Otherwise LLVM bump below fails
RUN apt-get install -y wget gnupg lsb-release software-properties-common apt-transport-https ca-certificates

# Autodetect and fetch latest LLVM repos for the current distro, avoids LLVM warnings and other issues, might generate slower builds for now though, see:
# https://www.phoronix.com/scan.php?page=news_item&px=Rust-Hurt-On-LLVM-10
RUN bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
#RUN apt-get install -y libssl-dev libcurl4-openssl-dev zlib1g-dev libbz2-dev liblzma-dev musl musl-dev musl-tools # htslib deps

# Remove pre-installed musl, to avoid cross-musl-make interference
RUN apt-get remove -y musl

# For now we'll have to go nuts and not only build musl-1.2.0 from scratch but all the other libs too...
# Updated musl-cross toolchain that does not fail on OpenSSL: https://github.com/openssl/openssl/issues/7207
WORKDIR /root
RUN wget https://github.com/richfelker/musl-cross-make/archive/v$MUSL_CROSS_MAKE_VERSION.tar.gz \
&& tar xvfz v$MUSL_CROSS_MAKE_VERSION.tar.gz
WORKDIR /root/musl-cross-make-$MUSL_CROSS_MAKE_VERSION
COPY config-musl-cross-make.mak config.mak
RUN make -j40 install

# Now we assume we have a properly configured musl-cross...
ENV PATH "/usr/local/musl/bin:$PATH"
ENV CFLAGS "-fPIC"
ENV CROSS_COMPILE x86_64-linux-musl-
ENV CC ${CROSS_COMPILE}cc
ENV AR ${CROSS_COMPILE}ar
ENV RANLIB ${CROSS_COMPILE}ranlib
ENV CXX ${CROSS_COMPILE}g++
ENV CPPFLAGS "-I/usr/local/musl/include -I/usr/local/include"
ENV LDFLAGS "-L/usr/local/musl/lib -L/usr/local/lib"

# .. and carry on with the htslib deps
RUN wget https://www.zlib.net/zlib-$ZLIB_VERSION.tar.gz \
&& tar xvfz zlib-$ZLIB_VERSION.tar.gz \
&& cd zlib-$ZLIB_VERSION \
&& ./configure --static --prefix=/usr/local/musl \
&& make -j40 install
WORKDIR /root
RUN git clone git://sourceware.org/git/bzip2 \
&& cd bzip2 \
#&& make -j40 CC=$CC AR=$AR RANLIB=$RANLIB CFLAGS=$CFLAGS bzip2 \
&& make PREFIX=/usr/local/musl -j40 bzip2 \
&& make -j40 install
WORKDIR /root
RUN wget https://tukaani.org/xz/xz-$LZMA_VERSION.tar.bz2 \
&& tar xvfj xz-$LZMA_VERSION.tar.bz2 \
&& cd xz-$LZMA_VERSION \
&& ./configure --prefix=/usr/local/musl --enable-static --disable-shared --host x86_64-unknown-linux-musl \
&& make -j40 install
WORKDIR /root

# A few gems from: https://wiki.openssl.org/index.php/Compilation_and_Installation
# "OpenSSL has been around a long time, and it carries around a lot of cruft"
# "SSLv2 is completely broken, and you should disable it during configuration"
# "You should specify both --prefix and --openssldir to ensure make install works as expected."
#
# And also this:
# https://github.com/openssl/openssl/issues/11362
#
# And having to redefine AR,CC & RANLIB because otherwise, this:
#
# make[1]: x86_64-linux-musl-x86_64-linux-musl-ar: Command not found
RUN wget https://github.com/openssl/openssl/archive/OpenSSL_$OPENSSL_VERSION.tar.gz \
&& tar xvfz OpenSSL_$OPENSSL_VERSION.tar.gz && cd openssl-OpenSSL_$OPENSSL_VERSION \
&& ./Configure --prefix=/usr/local/musl --openssldir=/usr/local/musl \
--with-zlib-lib=/usr/local/lib/zlib-$ZLIB_VERSION linux-x86_64 \
no-shared no-dso no-gost no-engine no-ssl2 no-srp no-srtp no-tests zlib \
no-weak-ssl-ciphers \
&& make AR=x86_64-linux-musl-ar \
CC=x86_64-linux-musl-cc \
-j40 \
&& make RANLIB=x86_64-linux-musl-ranlib -j40 install

WORKDIR /root
RUN wget https://curl.haxx.se/download/curl-$CURL_VERSION.tar.gz \
&& tar xvfz curl-$CURL_VERSION.tar.gz && cd curl-$CURL_VERSION \
&& ./configure --prefix=/usr/local/musl --host x86_64-linux-musl \
--with-ssl=/usr/local/musl --with-zlib=/usr/local/musl --enable-static \
--disable-dict --disable-file --disable-ftp --disable-gopher --disable-imap \
--disable-pop3 --disable-rtsp --disable-smb --disable-smtp --disable-telnet \
--disable-tftp --disable-ntlm --disable-ldap \
&& make -j40 install

# To cater Rust's openssl-sys needs...
#ENV OPENSSL_DIR /usr/local/openssl
ENV OPENSSL_DIR /usr/local/musl

# Hack to force ld stick to musl on the hts-sys/build.rs side, otherwise:
# = note: /usr/bin/ld: /target/debug/deps/liblibloading-689161fea10b6234.rlib(global_static.o): unable to initialize decompress status for section .debug_info
RUN rm /usr/bin/ld && ln -sf /usr/local/musl/bin/x86_64-linux-musl-ld /usr/bin/ld

# Prepare rustup and toolchain locally for easy manual intervention in this container
#RUN wget https://static.rust-lang.org/rustup/dist/x86_64-unknown-linux-gnu/rustup-init \
# && chmod +x rustup-init \
# && ./rustup-init -y \
# && . $HOME/.cargo/env \
# && rustup target add x86_64-unknown-linux-musl

CMD ["bash"]
2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ $ docker build -t brainstorm/cross-x86_64-unknown-linux-musl:libcurl-openssl . -
$ docker build -t brainstorm/cross-x86_64-unknown-linux-gnu:libcurl-openssl . -f Dockerfile.gnu
```

Then to build and test rust-htslib with the above containers, proceed as you would with `cargo`, using `cross` instead, i.e:
Then, to build and test rust-htslib with the above containers, proceed as you would with `cargo`, using `cross` instead, i.e:

```shell
$ cross build --target x86_64-unknown-linux-musl
Expand Down
4 changes: 4 additions & 0 deletions docker/config-musl-cross-make.mak
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
TARGET = x86_64-linux-musl
OUTPUT = /usr/local/musl
GCC_VER = 9.2.0
BINUTILS_VER = 2.33.1
20 changes: 10 additions & 10 deletions hts-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ pre-release-commit-message = "release version {{version}}"
tag-message = "Version {{version}} of Rust-HTSlib."

[dependencies]
libc = "0.2"
libz-sys = "1.0"
bzip2-sys = { version = "0.1", optional = true }
lzma-sys = { version = "0.1", optional = true }
curl-sys = { version = "0.4.26", optional = true }
openssl-sys = { version = "0.9.54", optional = true }
libz-sys = { version = "1.0.25", features = ["static"] }
# https://github.com/alexcrichton/bzip2-rs/issues/56
bzip2-sys = { version = "0.1.8", optional = true }
lzma-sys = { version = "0.1.16", optional = true, features = ["static"] }
curl-sys = { version = "0.4.31", optional = true, features = ["static-curl", "static-ssl"] }

[features]
default = ["bzip2", "lzma", "curl"]
default = ["bzip2", "lzma"]
bzip2 = ["bzip2-sys"]
lzma = ["lzma-sys"]
openssl = ["openssl-sys"]
#openssl = ["openssl-sys"]
curl = ["curl-sys"]
static = []

[build-dependencies]
fs-utils = "1.1"
bindgen = { version = "0.53.1", default-features = false, features = ["runtime"] }
bindgen = { version = "0.53.2", default-features = false, features = ["runtime"] }
cc = "1.0"
glob = "0.3.0"
glob = "0.3.0"
Loading