Skip to content

Commit

Permalink
fix: build for macOS (#431)
Browse files Browse the repository at this point in the history
* set host to macos-12

* set host to macos-13

* update hts-sys

* set macos-latest

* fix type

* fix internal insert size naming (isize vs isize_)

* fix type

* fix

* fix

* fix

* fmt

* fix

* fmt

* bump hts-sys

---------

Co-authored-by: Johannes Koester <[email protected]>
  • Loading branch information
FelixMoelder and johanneskoester authored May 10, 2024
1 parent f73ebc3 commit d869fdd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 51 deletions.
42 changes: 18 additions & 24 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,29 +125,28 @@ jobs:
strategy:
matrix:
target:
- intel-catalina
- intel-bigsur
- m1-bigsur
- intel-monterey
- intel-ventura
- silicon-sonoma
include:
- target: intel-catalina
os: macOS-10.15
- target: intel-monterey
os: macOS-12.0
toolchain_target: x86_64-apple-darwin
toolchain: stable
aux_args: ""
default: false
- target: intel-bigsur
os: macOS-11.0
aux_args: --target x86_64-apple-darwin
default: true
- target: intel-ventura
os: macOS-13.0
toolchain_target: x86_64-apple-darwin
toolchain: stable
aux_args: --target x86_64-apple-darwin
default: true
- target: silicon-sonoma
os: macOS-14.0
toolchain_target: aarch64-apple-darwin
toolchain: stable
aux_args: ""
default: false
# TODO enable again and try to find out why this fails
# - target: m1-bigsur
# os: macOS-11.0
# toolchain_target: aarch64-apple-darwin
# toolchain: nightly
# aux_args: --target aarch64-apple-darwin
# default: true

steps:
- name: Checkout repository
Expand All @@ -158,19 +157,14 @@ jobs:
- name: Install stable toolchain
uses: actions-rs/[email protected]
with:
toolchain: stable
toolchain: ${{ matrix.toolchain }}
target: ${{ matrix.toolchain_target }}
override: true
default: ${{ matrix.default }}

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

#- uses: actions-rs/[email protected]
# with:
# toolchain: ${{ matrix.toolchain }}
# target: ${{ matrix.toolchain_target }}
# #override: true
# default: ${{ matrix.default }}

- name: Test
uses: actions-rs/[email protected]
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bio-types = ">=0.9"
byteorder = "1.3"
custom_derive = "0.1"
derive-new = "0.5"
hts-sys = {version = "2.1.1", default-features = false}
hts-sys = {version = "2.1.4", default-features = false, features = ["bindgen"]}
ieee754 = "0.2"
lazy_static = "1.4"
libc = "0.2"
Expand Down
8 changes: 4 additions & 4 deletions src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ impl Writer {
);

(*rec).text = text as *mut c_char;
(*rec).l_text = l_text as u64;
(*rec).l_text = l_text;
rec
};

Expand Down Expand Up @@ -1392,9 +1392,9 @@ impl HeaderView {
header_string.len(),
);

let rec = htslib::sam_hdr_parse((l_text + 1) as u64, text as *const c_char);
let rec = htslib::sam_hdr_parse((l_text + 1), text as *const c_char);

Check warning on line 1395 in src/bam/mod.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (no-default-features)

unnecessary parentheses around function argument

Check warning on line 1395 in src/bam/mod.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (no-default-features)

unnecessary parentheses around function argument

Check warning on line 1395 in src/bam/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary parentheses around function argument

warning: unnecessary parentheses around function argument --> src/bam/mod.rs:1395:45 | 1395 | let rec = htslib::sam_hdr_parse((l_text + 1), text as *const c_char); | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 1395 - let rec = htslib::sam_hdr_parse((l_text + 1), text as *const c_char); 1395 + let rec = htslib::sam_hdr_parse(l_text + 1, text as *const c_char); |

Check warning on line 1395 in src/bam/mod.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (all-features)

unnecessary parentheses around function argument

Check warning on line 1395 in src/bam/mod.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (all-features)

unnecessary parentheses around function argument
(*rec).text = text as *mut c_char;
(*rec).l_text = l_text as u64;
(*rec).l_text = l_text;
rec
};

Expand Down Expand Up @@ -1580,7 +1580,7 @@ CCCCCCCCCCCCCCCCCCC"[..],
assert_eq!(c1.inner().core.l_qname, b1.inner().core.l_qname);
assert_eq!(c1.inner().core.n_cigar, b1.inner().core.n_cigar);
assert_eq!(c1.inner().core.l_qseq, b1.inner().core.l_qseq);
assert_eq!(c1.inner().core.isize, b1.inner().core.isize);
assert_eq!(c1.inner().core.isize_, b1.inner().core.isize_);
//... except m_data
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/bam/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl Record {

let mut sam_string = htslib::kstring_t {
s: sam_copy.as_ptr() as *mut c_char,
l: sam_copy.len() as u64,
m: sam_copy.len() as u64,
l: sam_copy.len(),
m: sam_copy.len(),
};

let succ = unsafe {
Expand Down Expand Up @@ -286,12 +286,12 @@ impl Record {

/// Get insert size.
pub fn insert_size(&self) -> i64 {
self.inner().core.isize
self.inner().core.isize_
}

/// Set insert size.
pub fn set_insert_size(&mut self, insert_size: i64) {
self.inner_mut().core.isize = insert_size;
self.inner_mut().core.isize_ = insert_size;
}

fn qname_capacity(&self) -> usize {
Expand Down
10 changes: 5 additions & 5 deletions src/bam/record_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl Serialize for Record {
state.serialize_field("seq_len", &core.l_qseq)?;
state.serialize_field("mtid", &core.mtid)?;
state.serialize_field("mpos", &core.mpos)?;
state.serialize_field("isize", &core.isize)?;
state.serialize_field("isize", &core.isize_)?;
state.serialize_field("data", Bytes::new(self.data()))?;
state.end()
}
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<'de> Deserialize<'de> for Record {
let mpos = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
let isize = seq
let isize_ = seq
.next_element()?
.ok_or_else(|| de::Error::invalid_length(0, &self))?;
let data = seq
Expand All @@ -159,7 +159,7 @@ impl<'de> Deserialize<'de> for Record {
m.l_qseq = seq_len;
m.mtid = mtid;
m.mpos = mpos;
m.isize = isize;
m.isize_ = isize_;
}

rec.set_data(&data);
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'de> Deserialize<'de> for Record {
let seq_len = seq_len.ok_or_else(|| de::Error::missing_field("seq_len"))?;
let mtid = mtid.ok_or_else(|| de::Error::missing_field("mtid"))?;
let mpos = mpos.ok_or_else(|| de::Error::missing_field("mpos"))?;
let isize = isize.ok_or_else(|| de::Error::missing_field("isize"))?;
let isize_ = isize.ok_or_else(|| de::Error::missing_field("isize"))?;
let data = data
.ok_or_else(|| de::Error::missing_field("data"))?
.into_vec();
Expand All @@ -289,7 +289,7 @@ impl<'de> Deserialize<'de> for Record {
m.l_qseq = seq_len;
m.mtid = mtid;
m.mpos = mpos;
m.isize = isize;
m.isize_ = isize_;
}

rec.set_data(&data);
Expand Down
2 changes: 1 addition & 1 deletion src/bcf/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ impl Record {
}

pub fn remove_alleles(&mut self, remove: &[bool]) -> Result<()> {
let rm_set = unsafe { htslib::kbs_init(remove.len() as u64) };
let rm_set = unsafe { htslib::kbs_init(remove.len()) };

for (i, &r) in remove.iter().enumerate() {
if r {
Expand Down
15 changes: 3 additions & 12 deletions src/bgzf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,7 @@ impl Reader {
impl std::io::Read for Reader {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
let nbytes = unsafe {
htslib::bgzf_read(
self.inner,
buf.as_mut_ptr() as *mut libc::c_void,
buf.len() as u64,
)
htslib::bgzf_read(self.inner, buf.as_mut_ptr() as *mut libc::c_void, buf.len())
};
if nbytes < 0 {
Err(std::io::Error::new(
Expand Down Expand Up @@ -257,13 +253,8 @@ impl Writer {

impl std::io::Write for Writer {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let nbytes = unsafe {
htslib::bgzf_write(
self.inner,
buf.as_ptr() as *mut libc::c_void,
buf.len() as u64,
)
};
let nbytes =
unsafe { htslib::bgzf_write(self.inner, buf.as_ptr() as *mut libc::c_void, buf.len()) };
if nbytes < 0 {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
Expand Down

0 comments on commit d869fdd

Please sign in to comment.