Skip to content

Commit

Permalink
Merge pull request #21 from michaelkirk/mkirk/optional-cbindgen
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei authored Apr 21, 2022
2 parents a3248c7 + b96b417 commit 12f0e5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ num-traits = "0.2.8"
thiserror = "1.0.4"

[build-dependencies]
cbindgen = "0.22.0"
cbindgen = { version = "0.22.0", default-features=false, optional = true}

[dev-dependencies]
criterion = "0.3.0"

[features]
headers = []
headers = ["cbindgen"]

[lib]
name = "polylabel"
Expand Down
17 changes: 6 additions & 11 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
extern crate cbindgen;

use std::env;
#[cfg(feature = "cbindgen")]
fn main() {
use std::env;

fn write_headers() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let config = cbindgen::Config::from_file("cbindgen.toml").unwrap();

let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::generate_with_config(&crate_dir, config)
.expect("Unable to generate bindings")
.write_to_file("include/header.h");
}

fn main() {
let headers_enabled = env::var_os("CARGO_FEATURE_HEADERS").is_some();
if headers_enabled {
write_headers();
}
}
#[cfg(not(feature = "cbindgen"))]
fn main() { }
2 changes: 1 addition & 1 deletion include/header.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Generated with cbindgen:0.19.0 */
/* Generated with cbindgen:0.22.0 */

/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */

Expand Down

0 comments on commit 12f0e5e

Please sign in to comment.