nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix

rustPlatform.bindgenHook: init

+29 -2
+2
doc/languages-frameworks/rust.section.md
··· 464 464 be disabled by setting `dontUseCargoParallelTests`. 465 465 * `cargoInstallHook`: install binaries and static/shared libraries 466 466 that were built using `cargoBuildHook`. 467 + * `bindgenHook`: for crates which use `bindgen` as a build dependency, lets 468 + `bindgen` find `libclang` and `libclang` find the libraries in `buildInputs`. 467 469 468 470 ### Examples {#examples} 469 471
+10
pkgs/build-support/rust/hooks/default.nix
··· 1 1 { buildPackages 2 2 , callPackage 3 3 , cargo 4 + , clang 4 5 , diffutils 5 6 , lib 6 7 , makeSetupHook ··· 93 92 rustBuildPlatform rustTargetPlatform rustTargetPlatformSpec; 94 93 }; 95 94 } ./maturin-build-hook.sh) {}; 95 + 96 + bindgenHook = callPackage ({}: makeSetupHook { 97 + name = "rust-bindgen-hook"; 98 + substitutions = { 99 + libclang = clang.cc.lib; 100 + inherit clang; 101 + }; 102 + } 103 + ./rust-bindgen-hook.sh) {}; 96 104 }
+13
pkgs/build-support/rust/hooks/rust-bindgen-hook.sh
··· 1 + # populates LIBCLANG_PATH and BINDGEN_EXTRA_CLANG_ARGS for rust projects that 2 + # depend on the bindgen crate 3 + 4 + # if you modify this, you probably also need to modify the wrapper for the cli 5 + # of bindgen in pkgs/development/tools/rust/bindgen/wrapper.sh 6 + 7 + populateBindgenEnv () { 8 + export LIBCLANG_PATH=@libclang@/lib 9 + BINDGEN_EXTRA_CLANG_ARGS="$(< @clang@/nix-support/cc-cflags) $(< @clang@/nix-support/libc-cflags) $(< @clang@/nix-support/libcxx-cxxflags) $NIX_CFLAGS_COMPILE" 10 + export BINDGEN_EXTRA_CLANG_ARGS 11 + } 12 + 13 + postHook="${postHook:-}"$'\n'"populateBindgenEnv"$'\n'
+1 -1
pkgs/development/compilers/rust/make-rust-platform.nix
··· 31 31 # Hooks 32 32 inherit (callPackage ../../../build-support/rust/hooks { 33 33 inherit stdenv cargo rustc; 34 - }) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook; 34 + }) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook bindgenHook; 35 35 }
+3 -1
pkgs/development/tools/rust/bindgen/default.nix
··· 34 34 touch $out 35 35 ''; 36 36 }; 37 - } '' 37 + } 38 + # if you modify the logic to find the right clang flags, also modify rustPlatform.bindgenHook 39 + '' 38 40 mkdir -p $out/bin 39 41 export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)" 40 42 export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"