From 90b8139c6ed741a30e394599e2430b246030cca9 Mon Sep 17 00:00:00 2001 From: Erin Swenson-Healey Date: Tue, 24 Jul 2018 09:39:29 -0700 Subject: [PATCH] Automatically generate C header from Rust API (#97) * generate C header file on build using cbindgen * add newlines --- .gitignore | 1 + Cargo.toml | 4 +++- build.rs | 18 ++++++++++++++++++ cbindgen.toml | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 build.rs create mode 100644 cbindgen.toml diff --git a/.gitignore b/.gitignore index d61c9287..5e337146 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ **/*.rs.bk Cargo.lock .criterion +**/libproofs.h diff --git a/Cargo.toml b/Cargo.toml index 8973d3a0..3bb8f66a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,8 @@ criterion = "0.2.3" tempfile = "3" proptest = "0.7" +[build-dependencies] +cbindgen = "0.6.0" [[bench]] name = "pedersen" @@ -47,4 +49,4 @@ harness = false [[bench]] name = "drgraph" -harness = false \ No newline at end of file +harness = false diff --git a/build.rs b/build.rs new file mode 100644 index 00000000..bfbb1832 --- /dev/null +++ b/build.rs @@ -0,0 +1,18 @@ +extern crate cbindgen; + +const VERSION: &'static str = env!("CARGO_PKG_VERSION"); + +fn main() { + let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + + let cfg = cbindgen::Config::from_root_or_default(std::path::Path::new(&crate_dir)); + + cbindgen::Builder::new() + .with_config(cfg) + .with_crate(crate_dir) + .with_header(format!("/* libproofs Header Version {} */", VERSION)) + .with_language(cbindgen::Language::C) + .generate() + .expect("Unable to generate bindings") + .write_to_file("libproofs.h"); +} diff --git a/cbindgen.toml b/cbindgen.toml new file mode 100644 index 00000000..42026e67 --- /dev/null +++ b/cbindgen.toml @@ -0,0 +1,3 @@ +[export] +# A list of symbols to not include in the generated bindings +exclude = ["MerkleTree"]