Skip to content

Commit

Permalink
Directly include the wrapper header in crate instead of rewriting it …
Browse files Browse the repository at this point in the history
…on every build. Fixes #24. (#25)
  • Loading branch information
yongqli authored Feb 12, 2024
1 parent a0be3b0 commit 9a60095
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
14 changes: 4 additions & 10 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
use std::env;
use std::fs::write;
use std::path::{Path, PathBuf};

fn generate_bindings<'a>(include_paths: impl Iterator<Item = &'a Path>) {
// First, we write a trivial wrapper header so that the HiGHS headers can be discovered from
// the include path.
let mut wrapper_path = PathBuf::from(env::var("OUT_DIR").unwrap());
wrapper_path.push("highs.h");
write(&wrapper_path, "#include <interfaces/highs_c_api.h>").unwrap();

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let builder = include_paths.fold(bindgen::Builder::default(), |builder, path| {
builder.clang_arg(format!("-I{}", path.to_string_lossy()))
});
let c_bindings = builder
// The input header we would like to generate
// bindings for.
.header(wrapper_path.to_string_lossy())
// The input header we would like to generate bindings for.
// This is a trivial wrapper header so that the HiGHS headers
// can be discovered from the include path.
.header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
Expand Down
1 change: 1 addition & 0 deletions wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include <interfaces/highs_c_api.h>

0 comments on commit 9a60095

Please sign in to comment.