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]
6extern crate log;
7extern crate proc_macro2;
8#[macro_use]
9extern crate serde;
10extern crate serde_json;
11#[macro_use]
12extern crate quote;
13#[macro_use]
14extern crate syn;
15extern crate toml;
16
17mod bindgen;
18
19pub use crate::bindgen::*;
20
21use 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.
25pub fn generate<P: AsRef<Path>>(crate_dir: P) -> Result<Bindings, Error> {
26 let config: Config = Config::from_root_or_default(root: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.
33pub fn generate_with_config<P: AsRef<Path>>(
34 crate_dir: P,
35 config: Config,
36) -> Result<Bindings, Error> {
37 BuilderBuilder::new()
38 .with_config(config)
39 .with_crate(lib_dir:crate_dir)
40 .generate()
41}
42