Skip to content
Open
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
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ jobs:
default: ${{ matrix.default }}

- name: Install htslib dependencies
run: brew install bzip2 zlib xz curl-openssl
run: brew install bzip2 zlib xz curl

- name: Test
uses: actions-rs/cargo@v1.0.1
Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,30 @@ git clone --recurse-submodules ...

When updating the htslib submodule or modifying `wrapper.h`, the prebuilt binding files need to be regenerated.

The generated bindings do not depend on cargo features, so `--no-default-features` is used to skip building curl and OpenSSL. A dedicated target directory guarantees exactly one `bindings.rs` is found, and the `find` works with both the older `build/hts-sys-<hash>/out` and newer `build/hts-sys/<hash>/out` cargo layouts.

### macOS

```sh
cargo build --features bindgen
cp target/debug/build/hts-sys-*/out/bindings.rs osx_prebuilt_bindings.rs
CARGO_TARGET_DIR=target/bindgen-macos cargo build --no-default-features --features bindgen
cp "$(find target/bindgen-macos -path '*hts-sys*' -name bindings.rs)" osx_prebuilt_bindings.rs
```

### Linux

Generate these on Linux (or in Docker as below), never by copying the macOS bindings: the libc declarations and `va_list` differ between platforms.

```sh
docker run --rm --platform linux/amd64 \
-v "$(pwd)":/workspace -w /workspace rust:latest bash -c '
rustup component add rustfmt &&
apt-get update -qq &&
apt-get install -y -qq cmake zlib1g-dev libbz2-dev clang libc6-dev libssl-dev libcurl4-openssl-dev &&
cargo build --features bindgen &&
BINDINGS=$(find target/debug/build/hts-sys-*/out -name bindings.rs | head -1) &&
rustfmt "$BINDINGS" &&
cp "$BINDINGS" linux_prebuilt_bindings.rs
-v "$(pwd)":/workspace -w /workspace -e CARGO_TARGET_DIR=/tmp/target rust:latest bash -c '
set -euo pipefail
rustup component add rustfmt
apt-get update -qq
apt-get install -y -qq cmake clang libc6-dev
cargo build --no-default-features --features bindgen
mapfile -t files < <(find /tmp/target -path "*hts-sys*" -name bindings.rs)
[ "${#files[@]}" -eq 1 ] || { echo "expected one bindings.rs, found ${#files[@]}"; exit 1; }
rustfmt --edition 2021 "${files[0]}"
cp "${files[0]}" linux_prebuilt_bindings.rs
'
```
28 changes: 14 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ fn main() {
let mut config_lines = vec![
"/* Default config.h generated by build.rs */",
"#define HAVE_DRAND48 1",
// Without this, hts_prefetch() in hts_defs.h falls back to a volatile read.
"#define HAVE___BUILTIN_PREFETCH 1",
];

let use_bzip2 = env::var("CARGO_FEATURE_BZIP2").is_ok();
if use_bzip2 {
if let Ok(inc) = env::var("DEP_BZIP2_ROOT")
.map(PathBuf::from)
.map(|path| path.join("include"))
{
// bzip2-sys only exports an include dir when it builds bzip2 from source. When it links a
// system libbz2 found via pkg-config (e.g. on macOS) bzlib.h is on the system include path.
if let Ok(inc) = env::var("DEP_BZIP2_INCLUDE") {
cfg.include(inc);
lib_list += " -lbz2";
config_lines.push("#define HAVE_LIBBZ2 1");
}
lib_list += " -lbz2";
config_lines.push("#define HAVE_LIBBZ2 1");
}

let use_libdeflate = env::var("CARGO_FEATURE_LIBDEFLATE").is_ok();
Expand All @@ -139,14 +140,13 @@ fn main() {

let use_lzma = env::var("CARGO_FEATURE_LZMA").is_ok();
if use_lzma {
if let Ok(inc) = env::var("DEP_LZMA_INCLUDE").map(PathBuf::from) {
cfg.include(inc);
lib_list += " -llzma";
config_lines.push("#define HAVE_LIBBZ2 1");
config_lines.push("#ifndef __APPLE__");
config_lines.push("#define HAVE_LZMA_H 1");
config_lines.push("#endif");
}
// lzma-sys is built with its `static` feature, so it always ships lzma.h, including on
// macOS where htslib's own Makefile falls back to os/lzma_stub.h.
let inc = env::var("DEP_LZMA_INCLUDE").expect("lzma-sys did not export DEP_LZMA_INCLUDE");
cfg.include(inc);
lib_list += " -llzma";
config_lines.push("#define HAVE_LIBLZMA 1");
config_lines.push("#define HAVE_LZMA_H 1");
}

let use_curl = env::var("CARGO_FEATURE_CURL").is_ok();
Expand Down
2 changes: 1 addition & 1 deletion htslib
Submodule htslib updated 147 files
Loading
Loading