···11-{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile
22-, runtimeShell
33-, bash
44-}:
55-66-rustPlatform.buildRustPackage rec {
77- pname = "rust-bindgen";
88- version = "0.59.2";
99-1010- RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update
1111-1212- src = fetchFromGitHub {
1313- owner = "rust-lang";
1414- repo = pname;
1515- rev = "v${version}";
1616- sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs=";
1717- };
1818-1919- cargoSha256 = "sha256-zhENlrqj611RkKDvpDtDFWc58wfQVamkJnpe2nvRieE=";
2020-11+{ rust-bindgen-unwrapped, bash, runCommand }:
22+let
33+ clang = rust-bindgen-unwrapped.clang;
44+in
55+runCommand "rust-bindgen-${rust-bindgen-unwrapped.version}"
66+{
217 #for substituteAll
2222- libclang = clang.cc.lib; # use the same version of clang for cxxincludes and libclang
238 inherit bash;
2424-2525- buildInputs = [ libclang ];
2626-2727- preConfigure = ''
2828- export LIBCLANG_PATH="${lib.getLib libclang}/lib"
2929- '';
3030-3131- postInstall = ''
3232- mv $out/bin/{bindgen,.bindgen-wrapped};
3333- export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)"
3434- export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"
3535- substituteAll ${./wrapper.sh} $out/bin/bindgen
3636- chmod +x $out/bin/bindgen
3737- '';
3838-3939- doCheck = true;
4040- checkInputs =
4141- let fakeRustup = writeTextFile {
4242- name = "fake-rustup";
4343- executable = true;
4444- destination = "/bin/rustup";
4545- text = ''
4646- #!${runtimeShell}
4747- shift
4848- shift
4949- exec "$@"
5050- '';
5151- };
5252- in [
5353- rustfmt
5454- fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
5555- clang
5656- ];
5757- preCheck = ''
5858- # for the ci folder, notably
5959- patchShebangs .
6060- '';
99+ unwrapped = rust-bindgen-unwrapped;
1010+ libclang = clang.cc.lib;
1111+} ''
1212+ mkdir -p $out/bin
1313+ export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)"
1414+ export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"
1515+ substituteAll ${./wrapper.sh} $out/bin/bindgen
1616+ chmod +x $out/bin/bindgen
1717+''
61186262- meta = with lib; {
6363- description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
6464- longDescription = ''
6565- Bindgen takes a c or c++ header file and turns them into
6666- rust ffi declarations.
6767- As with most compiler related software, this will only work
6868- inside a nix-shell with the required libraries as buildInputs.
6969- This version of bindgen is wrapped with the required compiler flags
7070- required to find the c and c++ standard libary of the input clang
7171- derivation.
7272- '';
7373- homepage = "https://github.com/rust-lang/rust-bindgen";
7474- license = with licenses; [ bsd3 ];
7575- platforms = platforms.unix;
7676- maintainers = with maintainers; [ johntitor ralith ];
7777- };
7878-}
+68
pkgs/development/tools/rust/bindgen/unwrapped.nix
···11+{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile
22+, runtimeShell
33+, bash
44+}:
55+66+rustPlatform.buildRustPackage rec {
77+ pname = "rust-bindgen-unwrapped";
88+ version = "0.59.2";
99+1010+ RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update
1111+1212+ src = fetchFromGitHub {
1313+ owner = "rust-lang";
1414+ repo = "rust-bindgen";
1515+ rev = "v${version}";
1616+ sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs=";
1717+ };
1818+1919+ cargoSha256 = "sha256-RKZY5vf6CSFaKweuuNkeFF0ZXlSUibAkcL/YhkE0MoQ=";
2020+2121+ buildInputs = [ clang.cc.lib ];
2222+2323+ preConfigure = ''
2424+ export LIBCLANG_PATH="${clang.cc.lib}/lib"
2525+ '';
2626+2727+ doCheck = true;
2828+ checkInputs =
2929+ let fakeRustup = writeTextFile {
3030+ name = "fake-rustup";
3131+ executable = true;
3232+ destination = "/bin/rustup";
3333+ text = ''
3434+ #!${runtimeShell}
3535+ shift
3636+ shift
3737+ exec "$@"
3838+ '';
3939+ };
4040+ in [
4141+ rustfmt
4242+ fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
4343+ clang
4444+ ];
4545+ preCheck = ''
4646+ # for the ci folder, notably
4747+ patchShebangs .
4848+ '';
4949+5050+ passthru = { inherit clang; };
5151+5252+ meta = with lib; {
5353+ description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
5454+ longDescription = ''
5555+ Bindgen takes a c or c++ header file and turns them into
5656+ rust ffi declarations.
5757+ As with most compiler related software, this will only work
5858+ inside a nix-shell with the required libraries as buildInputs.
5959+ This version of bindgen is wrapped with the required compiler flags
6060+ required to find the c and c++ standard libary of the input clang
6161+ derivation.
6262+ '';
6363+ homepage = "https://github.com/rust-lang/rust-bindgen";
6464+ license = with licenses; [ bsd3 ];
6565+ platforms = platforms.unix;
6666+ maintainers = with maintainers; [ johntitor ralith ];
6767+ };
6868+}
+1-1
pkgs/development/tools/rust/bindgen/wrapper.sh
···3030export LIBCLANG_PATH="@libclang@/lib"
3131# shellcheck disable=SC2086
3232# cxxflags and NIX_CFLAGS_COMPILE should be word-split
3333-exec -a "$0" @out@/bin/.bindgen-wrapped "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE
3333+exec -a "$0" @unwrapped@/bin/bindgen "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE
3434# note that we add the flags after $@ which is incorrect. This is only for the sake
3535# of simplicity.
3636