fn main() { println!("cargo:rerun-if-changed=build.rs"); let cflags = match std::env::var("CARGO_FEATURE_LTO").is_ok() { true => "CFLAGS=\"-O3 -flto=thin\"", false => "CFLAGS=\"-O3\"", }; let out_dir = std::env::var("OUT_DIR").unwrap(); let manifest = std::env::var("CARGO_MANIFEST_DIR").unwrap(); let script = format!( r#" rm -rf {out_dir}/build cp -r {manifest}/liburing {out_dir}/build cd {out_dir}/build ./configure --cc=clang --use-libc make -C src V=1 {cflags} liburing-ffi.a cp src/liburing-ffi.a ../liburing2-sys.a "# ); std::process::Command::new("sh").arg("-c").arg(script).status().unwrap(); println!("cargo:rustc-link-lib=uring2-sys"); println!("cargo:rustc-link-search={out_dir}"); bindgen::Builder::default() .clang_arg("--define-macro=IOURINGINLINE=") .header(format!("{out_dir}/build/src/include/liburing.h")) .allowlist_function("io_uring.*") .allowlist_type("io_uring.*") .allowlist_var("IOSQE.*") .allowlist_var("IORING.*") .anon_fields_prefix("anonymous") .default_non_copy_union_style(bindgen::NonCopyUnionStyle::ManuallyDrop) .default_enum_style(bindgen::EnumVariation::ModuleConsts) .layout_tests(false) .merge_extern_blocks(true) .use_core() .generate() .unwrap() .write_to_file(format!("{out_dir}/bindings.rs")) .unwrap(); }