| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
#[macro_use] |
| 6 |
extern crate log; |
| 7 |
extern crate proc_macro2; |
| 8 |
#[macro_use] |
| 9 |
extern crate serde; |
| 10 |
extern crate serde_json; |
| 11 |
#[macro_use] |
| 12 |
extern crate quote; |
| 13 |
#[macro_use] |
| 14 |
extern crate syn; |
| 15 |
extern crate toml; |
| 16 |
|
| 17 |
mod bindgen; |
| 18 |
|
| 19 |
pub use crate::bindgen::*; |
| 20 |
|
| 21 |
use std::path::Path; |
| 22 |
|
| 23 |
/// A utility function for build scripts to generate bindings for a crate, using |
| 24 |
/// a `cbindgen.toml` if it exists. |
| 25 |
pub fn generate<P: AsRef<Path>>(crate_dir: P) -> Result<Bindings, Error> { |
| 26 |
let config = Config::from_root_or_default(crate_dir.as_ref()); |
| 27 |
|
| 28 |
generate_with_config(crate_dir, config) |
| 29 |
} |
| 30 |
|
| 31 |
/// A utility function for build scripts to generate bindings for a crate with a |
| 32 |
/// custom config. |
| 33 |
pub fn generate_with_config<P: AsRef<Path>>( |
| 34 |
crate_dir: P, |
| 35 |
config: Config, |
| 36 |
) -> Result<Bindings, Error> { |
| 37 |
Builder::new() |
| 38 |
.with_config(config) |
| 39 |
.with_crate(crate_dir) |
| 40 |
.generate() |
| 41 |
} |