rustPlatform.bindgenHook: init
This commit is contained in:
parent
d914868235
commit
bedabfbcef
5 changed files with 29 additions and 2 deletions
|
@ -464,6 +464,8 @@ you of the correct hash.
|
|||
be disabled by setting `dontUseCargoParallelTests`.
|
||||
* `cargoInstallHook`: install binaries and static/shared libraries
|
||||
that were built using `cargoBuildHook`.
|
||||
* `bindgenHook`: for crates which use `bindgen` as a build dependency, lets
|
||||
`bindgen` find `libclang` and `libclang` find the libraries in `buildInputs`.
|
||||
|
||||
### Examples {#examples}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{ buildPackages
|
||||
, callPackage
|
||||
, cargo
|
||||
, clang
|
||||
, diffutils
|
||||
, lib
|
||||
, makeSetupHook
|
||||
|
@ -92,4 +93,13 @@ in {
|
|||
rustBuildPlatform rustTargetPlatform rustTargetPlatformSpec;
|
||||
};
|
||||
} ./maturin-build-hook.sh) {};
|
||||
|
||||
bindgenHook = callPackage ({}: makeSetupHook {
|
||||
name = "rust-bindgen-hook";
|
||||
substitutions = {
|
||||
libclang = clang.cc.lib;
|
||||
inherit clang;
|
||||
};
|
||||
}
|
||||
./rust-bindgen-hook.sh) {};
|
||||
}
|
||||
|
|
13
pkgs/build-support/rust/hooks/rust-bindgen-hook.sh
Normal file
13
pkgs/build-support/rust/hooks/rust-bindgen-hook.sh
Normal file
|
@ -0,0 +1,13 @@
|
|||
# populates LIBCLANG_PATH and BINDGEN_EXTRA_CLANG_ARGS for rust projects that
|
||||
# depend on the bindgen crate
|
||||
|
||||
# if you modify this, you probably also need to modify the wrapper for the cli
|
||||
# of bindgen in pkgs/development/tools/rust/bindgen/wrapper.sh
|
||||
|
||||
populateBindgenEnv () {
|
||||
export LIBCLANG_PATH=@libclang@/lib
|
||||
BINDGEN_EXTRA_CLANG_ARGS="$(< @clang@/nix-support/cc-cflags) $(< @clang@/nix-support/libc-cflags) $(< @clang@/nix-support/libcxx-cxxflags) $NIX_CFLAGS_COMPILE"
|
||||
export BINDGEN_EXTRA_CLANG_ARGS
|
||||
}
|
||||
|
||||
postHook="${postHook:-}"$'\n'"populateBindgenEnv"$'\n'
|
|
@ -31,5 +31,5 @@ rec {
|
|||
# Hooks
|
||||
inherit (callPackage ../../../build-support/rust/hooks {
|
||||
inherit stdenv cargo rustc;
|
||||
}) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook;
|
||||
}) cargoBuildHook cargoCheckHook cargoInstallHook cargoSetupHook maturinBuildHook bindgenHook;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,9 @@ let
|
|||
touch $out
|
||||
'';
|
||||
};
|
||||
} ''
|
||||
}
|
||||
# if you modify the logic to find the right clang flags, also modify rustPlatform.bindgenHook
|
||||
''
|
||||
mkdir -p $out/bin
|
||||
export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)"
|
||||
export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"
|
||||
|
|
Loading…
Reference in a new issue