Skip to content

Commit

Permalink
Create build.yml (tanghaibao#1)
Browse files Browse the repository at this point in the history
* Create build.yml

Set up Github Actions

* Update build.yml

* Use explicit bindgen version

* Add ignored_macros

* use the smaller callback
  • Loading branch information
tanghaibao authored May 10, 2022
1 parent cdbf4bd commit ae6fa70
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion wfa2-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
31 changes: 30 additions & 1 deletion wfa2-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>);

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",
Expand Down Expand Up @@ -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");

Expand All @@ -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.
Expand Down

0 comments on commit ae6fa70

Please sign in to comment.