diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..8ca9946 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,24 @@ +name: Rust + +on: + push: + branches: [main] + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository and submodules + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose diff --git a/wfa2-sys/Cargo.toml b/wfa2-sys/Cargo.toml index 2a48e09..4403098 100644 --- a/wfa2-sys/Cargo.toml +++ b/wfa2-sys/Cargo.toml @@ -7,6 +7,6 @@ build = "build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [build-dependencies] -bindgen = "*" +bindgen = "0.53.3" cc = "*" fs-utils = "*" \ No newline at end of file diff --git a/wfa2-sys/build.rs b/wfa2-sys/build.rs index 810067b..277fdf1 100644 --- a/wfa2-sys/build.rs +++ b/wfa2-sys/build.rs @@ -3,9 +3,23 @@ extern crate cc; use fs_utils::copy::copy_directory; +use std::collections::HashSet; use std::env; use std::path::PathBuf; +#[derive(Debug)] +struct IgnoreMacros(HashSet); + +impl bindgen::callbacks::ParseCallbacks for IgnoreMacros { + fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior { + if self.0.contains(name) { + bindgen::callbacks::MacroParsingBehavior::Ignore + } else { + bindgen::callbacks::MacroParsingBehavior::Default + } + } +} + // these need to be kept in sync with the WFA2 Makefile const FILES: &[&str] = &[ "utils/string_padded.c", @@ -68,6 +82,19 @@ fn main() { cfg.file(&c_file); println!("cargo:rerun-if-changed={}", wfa2.join(c_file).display()); } + let ignored_macros = IgnoreMacros( + vec![ + "FP_INFINITE".into(), + "FP_NAN".into(), + "FP_NORMAL".into(), + "FP_SUBNORMAL".into(), + "FP_ZERO".into(), + "IPPORT_RESERVED".into(), + ] + .into_iter() + .collect(), + ); + cfg.include(out_wfa2); cfg.compile("wfa2"); @@ -78,10 +105,12 @@ fn main() { // The input header we would like to generate // bindings for. .header("wrapper.h") + .parse_callbacks(Box::new(ignored_macros)) + .rustfmt_bindings(true) .clang_arg("-IWFA2-lib") // Tell cargo to invalidate the built crate whenever any of the // included header files changed. - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + // .parse_callbacks(Box::new(bindgen::CargoCallbacks)) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure.