From 43d8f3a10140b6ceff07d7323cc8193cb7c9cf1f Mon Sep 17 00:00:00 2001 From: _cry64 Date: Tue, 31 Mar 2026 11:19:58 +1000 Subject: [PATCH] more cleaning for build.rs --- nixide-sys/Cargo.toml | 1 + nixide-sys/build.rs | 38 +++++++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/nixide-sys/Cargo.toml b/nixide-sys/Cargo.toml index 0c021dd..910f875 100644 --- a/nixide-sys/Cargo.toml +++ b/nixide-sys/Cargo.toml @@ -30,6 +30,7 @@ nix-main-c = [] [build-dependencies] bindgen = { default-features = false, features = [ "logging", "runtime" ], version = "0.72.1" } doxygen-bindgen = "0.1.3" +itertools = "0.14.0" pkg-config.workspace = true cc.workspace = true diff --git a/nixide-sys/build.rs b/nixide-sys/build.rs index 1fee802..ede5d4f 100644 --- a/nixide-sys/build.rs +++ b/nixide-sys/build.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use std::{env, fs}; use bindgen::callbacks::ParseCallbacks; +use itertools::Itertools; #[derive(Debug)] struct DoxygenCallbacks; @@ -18,6 +19,7 @@ impl ParseCallbacks for DoxygenCallbacks { } } +// WARNING: NOTE: the random panic occurs when you're missing imports!! const LIBS: &[&'static str] = &[ #[cfg(feature = "nix-util-c")] "nix-util-c", @@ -37,26 +39,32 @@ fn main() { // Invalidate the built crate if the binding headers change // println!("cargo::rerun-if-changed=include"); - let lib_args: Vec = LIBS - .iter() - .map(|&name| { - let lib = pkg_config::probe_library(name) - .expect(&format!("Unable to find .pc file for {}", name)); + let lib_args: Vec = vec![ /* EXTRA ARGS */ ] + .into_iter() + .map(|s: &str| s.to_owned()) + .chain( + LIBS.iter() + .map(|&name| { + let lib = pkg_config::probe_library(name) + .expect(&format!("Unable to find .pc file for {}", name)); - for p in lib.link_files { - println!("cargo::rustc-link-lib={}", p.display()); - } + for p in lib.link_files { + println!("cargo::rustc-link-lib={}", p.display()); + } - lib.include_paths - .into_iter() - .map(|p| format!("-I{}", p.display())) - }) - .flatten() - .chain(vec!["-Wall".to_owned(), "-xc++".to_owned()]) + lib.include_paths + .into_iter() + .map(|p| format!("-I{}", p.display())) + }) + .flatten(), + ) + .unique() .collect(); + dbg!(&lib_args); + let mut builder = bindgen::Builder::default() - // .clang_arg("") // libnix uses c++23 + // .enable_cxx_namespaces() .clang_args(lib_args) .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) // Add `doxygen_bindgen` callbacks