diff options
| author | Christian Hopps <chopps@labn.net> | 2025-02-26 21:13:47 +0000 |
|---|---|---|
| committer | Christian Hopps <chopps@labn.net> | 2025-03-03 12:14:22 +0000 |
| commit | b4000e0ad7db49275cf3f592df3ceeb35021c296 (patch) | |
| tree | fd878567ad4e49aab9483c136ead4a77363ed8a2 /rustlibd/build.rs.in | |
| parent | 38c8603ebe694e92ef223df3a2c0c4c7fef43c13 (diff) | |
rustlibd: rust daemon templatedev/rust-skel
Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'rustlibd/build.rs.in')
| -rw-r--r-- | rustlibd/build.rs.in | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/rustlibd/build.rs.in b/rustlibd/build.rs.in new file mode 100644 index 0000000000..9d5741e461 --- /dev/null +++ b/rustlibd/build.rs.in @@ -0,0 +1,94 @@ +extern crate bindgen; +// extern crate gcc; + +use std::env; +use std::path::PathBuf; + +use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; +use std::sync::{Arc, RwLock}; + +use std::collections::HashSet; + +// +// This complexity is need to ignore a #define in netdb.h that is shadowing an +// anonymous enum in netinet/in.h +// +#[derive(Debug)] +struct MacroCallback { + macros: Arc<RwLock<HashSet<String>>>, +} + +impl ParseCallbacks for MacroCallback { + fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior { + self.macros.write().unwrap().insert(name.into()); + + if name == "IPPORT_RESERVED" { + return MacroParsingBehavior::Ignore; + } + + MacroParsingBehavior::Default + } +} + +fn main() { + // // Tell cargo to look for shared libraries in the specified directory + // println!("cargo:rustc-link-search=@abs_top_builddir@/lib/.libs/libfrr.so"); + // // Tell cargo to tell rustc to link libfrr shared library. + // println!("cargo:rustc-link-lib=frr"); + + // Tell cargo to invalidate the built crate whenever the wrapper changes + // println!("cargo:rerun-if-changed=@abs_srcdir@/wrapper.h"); + println!("cargo:rerun-if-changed=wrapper.h"); + + let macros = Arc::new(RwLock::new(HashSet::new())); + + // The bindgen::Builder is the main entry point + // to bindgen, and lets you build up options for + // the resulting bindings. + let bindings = bindgen::Builder::default() + .clang_args(&[ + "-I@abs_top_builddir@", // need to get this dynamically + "-I@abs_top_srcdir@", + "-I@abs_top_srcdir@/lib", + "-DHAVE_CONFIG_H", + "-D_ATOMIC_WANT_TYPEDEFS", + ]) + // The input header we would like to generate + // bindings for. + // .header("@abs_srcdir@/wrapper.h") + .header("wrapper.h") + // Tell cargo to invalidate the built crate whenever any of the + // included header files changed. + .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) + .parse_callbacks(Box::new(MacroCallback { + macros: macros.clone(), + })) + // Finish the builder and generate the bindings. + .blocklist_type("IPPORT_.*") + .blocklist_type("IPPORT_RESERVED") + // avoid creating bindings for things with u128 which doesn't yet have a + // stable FFI, for now. + + .blocklist_function("lyd_eval_xpath4") + .blocklist_function("q[efg]cvt.*") + .blocklist_function("strto.*") + .blocklist_function("strfrom.*") + + .generate() + // Unwrap the Result and panic on failure. + .expect("Unable to generate bindings"); + + // Write the bindings to the $OUT_DIR/bindings.rs file. + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); + + // cc::Build::new() + // .include("@abs_top_builddir@") + // .include("@abs_top_srcdir@") + // .include("@abs_top_srcdir@/lib") + // .define("HAVE_CONFIG_H", None) + // .file("@abs_srcdir@/rustlib_main.c") + // .compile("c_main_code"); +} |
