cbindgen/
lib.rs

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
17#[cfg(feature = "unstable_ir")]
18pub mod bindgen;
19#[cfg(not(feature = "unstable_ir"))]
20mod bindgen;
21
22pub use crate::bindgen::*;
23
24use std::path::Path;
25
26/// A utility function for build scripts to generate bindings for a crate, using
27/// a `cbindgen.toml` if it exists.
28pub fn generate<P: AsRef<Path>>(crate_dir: P) -> Result<Bindings, Error> {
29    let config = Config::from_root_or_default(crate_dir.as_ref());
30
31    generate_with_config(crate_dir, config)
32}
33
34/// A utility function for build scripts to generate bindings for a crate with a
35/// custom config.
36pub fn generate_with_config<P: AsRef<Path>>(
37    crate_dir: P,
38    config: Config,
39) -> Result<Bindings, Error> {
40    Builder::new()
41        .with_config(config)
42        .with_crate(crate_dir)
43        .generate()
44}