From 0af7df6bd31faabb6e1e5480989cb28a4b786470 Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 31 Jul 2025 13:42:52 +0200 Subject: [PATCH] rust-bindgen: link directly with libclang There's not really any reason for bindgen to dlopen libclang at all in Nixpkgs. Moving this out of the wrapper means that it will still work even when we don't want all the standard Nixpkgs cflags behavior, like in the Linux kernel build. --- pkgs/development/tools/rust/bindgen/default.nix | 2 -- pkgs/development/tools/rust/bindgen/unwrapped.nix | 8 ++++++-- pkgs/development/tools/rust/bindgen/wrapper.sh | 2 -- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/development/tools/rust/bindgen/default.nix b/pkgs/development/tools/rust/bindgen/default.nix index b574eb546421..734d31aba2d3 100644 --- a/pkgs/development/tools/rust/bindgen/default.nix +++ b/pkgs/development/tools/rust/bindgen/default.nix @@ -1,5 +1,4 @@ { - lib, rust-bindgen-unwrapped, zlib, bash, @@ -14,7 +13,6 @@ let #for substituteAll inherit bash; unwrapped = rust-bindgen-unwrapped; - libclang = (lib.getLib clang.cc); meta = rust-bindgen-unwrapped.meta // { longDescription = rust-bindgen-unwrapped.meta.longDescription + '' This version of bindgen is wrapped with the required compiler flags diff --git a/pkgs/development/tools/rust/bindgen/unwrapped.nix b/pkgs/development/tools/rust/bindgen/unwrapped.nix index c569789143d5..39b4de40b83b 100644 --- a/pkgs/development/tools/rust/bindgen/unwrapped.nix +++ b/pkgs/development/tools/rust/bindgen/unwrapped.nix @@ -21,12 +21,16 @@ rustPlatform.buildRustPackage rec { cargoHash = "sha256-K/iM79RfNU+3f2ae6wy/FMFAD68vfqzSUebqALPJpJY="; - buildInputs = [ (lib.getLib clang.cc) ]; - preConfigure = '' export LIBCLANG_PATH="${lib.getLib clang.cc}/lib" ''; + # Disable the "runtime" feature, so libclang is linked. + buildNoDefaultFeatures = true; + buildFeatures = [ "logging" ]; + checkNoDefaultFeatures = buildNoDefaultFeatures; + checkFeatures = buildFeatures; + doCheck = true; nativeCheckInputs = [ clang ]; diff --git a/pkgs/development/tools/rust/bindgen/wrapper.sh b/pkgs/development/tools/rust/bindgen/wrapper.sh index b7110385c26d..4311b9720aa8 100755 --- a/pkgs/development/tools/rust/bindgen/wrapper.sh +++ b/pkgs/development/tools/rust/bindgen/wrapper.sh @@ -27,10 +27,8 @@ fi; if [[ -n "$NIX_DEBUG" ]]; then set -x; fi; -export LIBCLANG_PATH="@libclang@/lib" # shellcheck disable=SC2086 # cxxflags and NIX_CFLAGS_COMPILE should be word-split exec -a "$0" @unwrapped@/bin/bindgen "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE # note that we add the flags after $@ which is incorrect. This is only for the sake # of simplicity. -