Skip to content

Commit

Permalink
add build.rs file
Browse files Browse the repository at this point in the history
  • Loading branch information
tanishqjasoria committed Aug 15, 2024
1 parent ee3121b commit b43e617
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions bindings/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
31 changes: 31 additions & 0 deletions bindings/c/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::env;
use std::path::PathBuf;

/// The directory where the generated header file will be written.
const DIR_FOR_HEADER: &str = "build";

fn main() {
// linker flags
// Link libm on Unix-like systems (needed due to use of num_cpus crate)
#[cfg(not(target_os = "windows"))]
println!("cargo:rustc-link-lib=m");

println!("cargo:rerun-if-changed=src/");
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let package_name = env::var("CARGO_PKG_NAME").unwrap();

let path_to_crate_dir = PathBuf::from(&crate_dir);

let output_file = PathBuf::from(&path_to_crate_dir)
.join(DIR_FOR_HEADER)
.join(format!("{}.h", package_name))
.display()
.to_string();

cbindgen::Builder::new()
.with_crate(crate_dir)
.with_language(cbindgen::Language::C)
.generate()
.unwrap()
.write_to_file(output_file);
}

0 comments on commit b43e617

Please sign in to comment.