lib.rs 1.04 KB
Newer Older
Ryan Hunt's avatar
Ryan Hunt committed
1
2
3
4
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

5
6
#[macro_use]
extern crate log;
Ryan Hunt's avatar
Ryan Hunt committed
7
8
9
extern crate serde;
#[macro_use]
extern crate serde_derive;
10
extern crate serde_json;
11
extern crate syn;
12
extern crate toml;
13
14
15
16

mod bindgen;

pub use bindgen::*;
Ryan Hunt's avatar
Ryan Hunt committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

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()
}