From a93e90cf3c50344a2582acb0e60187dbef90ee28 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Mon, 30 May 2022 20:44:53 +0200 Subject: cmake: add example how to integrate cargo --- .../libcalc/build.rs | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 content/2022-05-30-cmake-cargo-example/libcalc/build.rs (limited to 'content/2022-05-30-cmake-cargo-example/libcalc/build.rs') diff --git a/content/2022-05-30-cmake-cargo-example/libcalc/build.rs b/content/2022-05-30-cmake-cargo-example/libcalc/build.rs new file mode 100644 index 0000000..acfa6a7 --- /dev/null +++ b/content/2022-05-30-cmake-cargo-example/libcalc/build.rs @@ -0,0 +1,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); +} -- cgit v1.2.3