Skip to content

Commit

Permalink
Automatically generate C header from Rust API (zcash#97)
Browse files Browse the repository at this point in the history
* generate C header file on build using cbindgen

* add newlines
  • Loading branch information
laser authored Jul 24, 2018
1 parent c0edb08 commit 90b8139
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
**/*.rs.bk
Cargo.lock
.criterion
**/libproofs.h
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ criterion = "0.2.3"
tempfile = "3"
proptest = "0.7"

[build-dependencies]
cbindgen = "0.6.0"

[[bench]]
name = "pedersen"
harness = false

[[bench]]
name = "drgraph"
harness = false
harness = false
18 changes: 18 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
3 changes: 3 additions & 0 deletions cbindgen.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[export]
# A list of symbols to not include in the generated bindings
exclude = ["MerkleTree"]

0 comments on commit 90b8139

Please sign in to comment.