Matthias Andreas Benkard | 0858646 | 2020-06-28 22:42:43 +0200 | [diff] [blame] | 1 | use std::env; |
| 2 | use std::path::PathBuf; |
| 3 | |
| 4 | fn main() { |
| 5 | // Generate C header bindings. |
Matthias Andreas Benkard | bf33146 | 2020-06-28 22:46:43 +0200 | [diff] [blame^] | 6 | println!("cargo:rerun-if-changed=bindings.h"); |
Matthias Andreas Benkard | 0858646 | 2020-06-28 22:42:43 +0200 | [diff] [blame] | 7 | |
| 8 | let bindings = bindgen::Builder::default() |
| 9 | .header("bindings.h") |
| 10 | .parse_callbacks(Box::new(bindgen::CargoCallbacks)) |
| 11 | .generate() |
| 12 | .expect("Unable to generate C bindings"); |
| 13 | |
| 14 | let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); |
| 15 | bindings |
| 16 | .write_to_file(out_path.join("bindings.rs")) |
| 17 | .expect("Unable to write bindings.rs"); |
| 18 | |
| 19 | // Compile C code. |
| 20 | cc::Build::new() |
| 21 | .file("c/swap.c") |
| 22 | .flag("-std=c17") |
| 23 | .compile("swap"); |
| 24 | } |