aboutsummaryrefslogtreecommitdiffhomepage
path: root/content/2022-05-30-cmake-cargo-example/libcalc/build.rs
blob: acfa6a70c1c491e1a89cd330612f0298eb5942c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
fn main() {
    let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();

    let out_file = format!("{}/libcalc.h", std::env::var("LIBCALC_BUILD_DIR").unwrap_or(String::from(".")));

    let cfg = cbindgen::Config {
        cpp_compat: true,
        ..Default::default()
    };

    if std::path::Path::new(&out_file).exists() {
        std::fs::remove_file(&out_file).unwrap();
    }

    let ok = cbindgen::Builder::new()
        .with_config(cfg)
        .with_crate(crate_dir)
        .with_language(cbindgen::Language::C)
        .with_include_guard("LIBCALC_H")
        .generate()
        .expect("Unable to generate bindings")
        .write_to_file(&out_file);
    assert!(ok);
}