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

Update to htslib 1.10.2 (without musl) #192

Merged
merged 2 commits into from
Mar 17, 2020
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
12 changes: 12 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[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"
20 changes: 15 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ jobs:
override: true
components: clippy

- name: Install system dependencies
run: |
sudo apt-get install --yes zlib1g-dev libbz2-dev musl musl-dev musl-tools

- name: Lint with clippy
uses: actions-rs/clippy-check@v1
with:
Expand All @@ -67,7 +63,7 @@ jobs:

- name: Install system dependencies
run: |
sudo apt-get install --yes zlib1g-dev libbz2-dev musl musl-dev musl-tools
sudo apt-get install --yes zlib1g-dev libbz2-dev musl musl-dev musl-tools clang libc6-dev

- name: Run cargo-tarpaulin
uses: actions-rs/tarpaulin@v0.1
Expand All @@ -79,3 +75,17 @@ jobs:
with:
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode/
.idea
*~
target
Cargo.lock
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "htslib"]
path = hts-sys/htslib
url = https://github.com/rust-bio/htslib.git
url = https://github.com/samtools/htslib.git
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ snafu = ">= 0.5.0, <= 0.6.0"
hts-sys = { version = "^1.9", path = "hts-sys", default-features = false }

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

[dev-dependencies]
Expand Down
4 changes: 4 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[target.x86_64-unknown-linux-musl]
image = "brainstorm/rust_musl_docker:stable-latest-libcurl"
[target.x86_64-unknown-linux-gnu]
image = "brainstorm/cross-x86_64-unknown-linux-gnu:libcurl-openssl"
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ If you only want to use the library, there is no need to clone the repository. G

## Requirements

To compile this crate you need the development headers of zlib, bzip2 and xz.
To compile this crate you need 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
```

On OSX, this will take a significant amount of time due to musl cross compiling toolchain:

```shell
$ brew install FiloSottile/musl-cross/musl-cross
$ brew install bzip2 zlib xz curl-openssl
```

## Usage

Expand Down
8 changes: 8 additions & 0 deletions docker/Dockerfile.gnu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM rustembedded/cross:x86_64-unknown-linux-gnu

ENV LIBCLANG_PATH /usr/lib/x86_64-linux-gnu
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
7 changes: 7 additions & 0 deletions docker/Dockerfile.musl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM rustembedded/cross:x86_64-unknown-linux-musl

ENV PKG_CONFIG_ALLOW_CROSS 1
ENV OPENSSL_LIB_DIR /usr/lib/x86_64-linux-gnu
ENV OPENSSL_INCLUDE_DIR /usr/include/openssl
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
17 changes: 17 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# cross rustembedded containers

Allows to compile (rust-)htslib in a variety of environments and architectures via [rustembedded cross](https://github.com/rust-embedded/cross).

## Quickstart

```shell
$ cd docker
$ docker build -t brainstorm/cross-x86_64-unknown-linux-musl:libcurl-openssl . -f Dockerfile.musl
$ 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:

```shell
$ cross build --target x86_64-unknown-linux-musl
```
10 changes: 7 additions & 3 deletions hts-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description = "This library provides HTSlib bindings."
readme = "README.md"
keywords = ["htslib", "bam", "bioinformatics", "pileup", "sequencing"]
license = "MIT"
repository = "https://github.com/rust-bio/rust-htslib.git"
repository = "https://github.com/samtools/htslib.git"
documentation = "https://docs.rs/rust-htslib"
edition = "2018"

Expand All @@ -21,14 +21,18 @@ 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 }

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

[build-dependencies]
fs-utils = "1.1"
bindgen = { version = "0.52.0", default-features = false, features = ["runtime"] }
bindgen = { version = "0.53.1", default-features = false, features = ["runtime"] }
cc = "1.0"
glob = "0.3.0"
16 changes: 11 additions & 5 deletions hts-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use std::fs;
use std::path::PathBuf;
use std::process::Command;

fn sed_htslib_makefile(out: &PathBuf, patterns: &Vec<&str>, feature: &str) {
fn sed_htslib_makefile(out: &PathBuf, patterns: &[&str], feature: &str) {
for pattern in patterns {
if Command::new("sed")
if !Command::new("sed")
.current_dir(out.join("htslib"))
.arg("-i")
.arg("-e")
Expand All @@ -24,7 +24,6 @@ fn sed_htslib_makefile(out: &PathBuf, patterns: &Vec<&str>, feature: &str) {
.status()
.unwrap()
.success()
!= true
{
panic!("failed to strip {} support", feature);
}
Expand Down Expand Up @@ -63,10 +62,18 @@ fn main() {
cfg.include(inc);
}

let use_curl = env::var("CARGO_FEATURE_CURL").is_ok();
if !use_curl {
let curl_patterns = vec!["s/ -lcurl//", "/#define HAVE_LIBCURL/d"];
sed_htslib_makefile(&out, &curl_patterns, "curl");
} else if let Ok(inc) = env::var("DEP_CURL_INCLUDE").map(PathBuf::from) {
cfg.include(inc);
}

let tool = cfg.get_compiler();
let (cc_path, cflags_env) = (tool.path(), tool.cflags_env());
let cc_cflags = cflags_env.to_string_lossy().replace("-O0", "");
if Command::new("make")
if !Command::new("make")
.current_dir(out.join("htslib"))
.arg(format!("CC={}", cc_path.display()))
.arg(format!("CFLAGS={}", cc_cflags))
Expand All @@ -75,7 +82,6 @@ fn main() {
.status()
.unwrap()
.success()
!= true
{
panic!("failed to build htslib");
}
Expand Down
2 changes: 1 addition & 1 deletion hts-sys/htslib
Submodule htslib updated 200 files
2 changes: 2 additions & 0 deletions hts-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ extern crate libz_sys;
extern crate bzip2_sys;
#[cfg(feature = "lzma")]
extern crate lzma_sys;
#[cfg(feature = "curl")]
extern crate curl_sys;

// include on-the-fly generated bindings
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
4 changes: 2 additions & 2 deletions src/bam/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl RecordBuffer {
let to_remove = self
.inner
.iter()
.take_while(|rec| rec.pos() < window_start as i32)
.take_while(|rec| rec.pos() < window_start as i64)
.count();
for _ in 0..to_remove {
self.inner.pop_front();
Expand All @@ -111,7 +111,7 @@ impl RecordBuffer {
record.cache_cigar();
}

if pos >= end as i32 {
if pos >= end as i64 {
self.overflow = Some(record);
break;
} else {
Expand Down
Loading