/// build.rs use std::env; use std::path::PathBuf; fn build_read() { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let include_path = PathBuf::from("include") .canonicalize() .expect("Failed to get include path"); let header_path = include_path.join("read.h"); let impl_path = include_path.join("read.c"); let header_path_str = header_path.to_str().expect("Failed to get header path"); let object_path = out_dir.join("read.o"); let lib_path = out_dir.join("libread.a"); println!("cargo:rustc-link-search=native={}", out_dir.to_str().unwrap()); // Ausgabe der statischen Bibliothek für den Linker println!("cargo:rustc-link-lib=static=read"); if !std::process::Command::new("clang") .arg("-c") .arg("-o") .arg(&object_path) .arg(&impl_path) .output() .expect("Failed to run clang") .status .success() { panic!("Failed to compile read.c"); } if !std::process::Command::new("ar") .arg("rcs") .arg(&lib_path) .arg(&object_path) .output() .expect("Failed to run ar") .status .success() { panic!("Failed to create static library"); } let bindings = bindgen::Builder::default() .header(header_path_str) .allowlist_function("validate_kml_file") .allowlist_function("read_kml_file") .allowlist_function("read_kml_name") .allowlist_function("read_kml_version") .allowlist_function("read_kml_author") .allowlist_function("read_kml_description") .allowlist_function("read_kml_size") .clang_arg("-I") .clang_arg(include_path.to_str().unwrap()) .clang_arg("-L") .clang_arg(out_dir.to_str().unwrap()) .clang_arg("-lread") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .generate() .expect("could not generate bindings"); let out_path = out_dir.join("read_bindings.rs"); bindings .write_to_file(out_path) .expect("could not write bindings"); } fn main() { build_read(); }