Commit 42454fed authored by Ryan Hunt's avatar Ryan Hunt
Browse files

Make build scripts more ergonomic

Fixes #19
parent 060a79f0
......@@ -32,17 +32,13 @@ Here's an example build.rs script:
extern crate cbindgen;
use std::env;
use cbindgen::{Config, Library};
fn main() {
let root = env::var("CARGO_MANIFEST_DIR").unwrap();
let config = Config::from_root_or_default(&root);
Library::load_crate(Path::new(root),
"CRATE_NAME",
&config)
.generate().unwrap()
.write_to_file("bindings.h");
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
cbindgen::generate(crate_dir)
.unwrap()
.write_to_file("bindings.h");
}
```
......
......@@ -51,5 +51,5 @@ mod writer;
pub use self::cargo::*;
pub use self::config::*;
pub use self::library::Library;
pub use self::library::{GeneratedBindings, Library};
pub use self::cargo_toml::manifest;
......@@ -14,3 +14,19 @@ extern crate toml;
mod bindgen;
pub use bindgen::*;
use std::path::Path;
/// A utility function for build scripts to generate bindings for a crate, using
/// a `cbindgen.toml` if it exists.
pub fn generate(crate_dir: &str) -> Result<GeneratedBindings, String> {
let crate_dir = Path::new(crate_dir);
Library::load_crate(Cargo::load(crate_dir, None)?,
&Config::from_root_or_default(crate_dir))?.generate()
}
/// A utility function for build scripts to generate bindings for a crate with a
/// custom config.
pub fn generate_config(crate_dir: &str, config: &Config) -> Result<GeneratedBindings, String> {
Library::load_crate(Cargo::load(Path::new(crate_dir), None)?, config)?.generate()
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment