1{ stdenv, fetchFromGitHub, rustPlatform, clang, llvmPackages, rustfmt, writeScriptBin,
2 runtimeShell }:
3
4rustPlatform.buildRustPackage rec {
5 name = "rust-bindgen-${version}";
6 version = "0.42.2";
7
8 src = fetchFromGitHub {
9 owner = "rust-lang-nursery";
10 repo = "rust-bindgen";
11 rev = "v${version}";
12 sha256 = "10h0h7x8yf4dsyw2p2nas2jg5p3i29np0y3rfzrdq898d70gvq4j";
13 };
14
15 cargoSha256 = "01jvi86xgz0r7ia9agnfpms6b6x68lzwj6f085m0w659i94acgpi";
16
17 libclang = llvmPackages.libclang.lib; #for substituteAll
18
19 buildInputs = [ libclang ];
20
21 propagatedBuildInputs = [ clang ]; # to populate NIX_CXXSTDLIB_COMPILE
22
23 configurePhase = ''
24 export LIBCLANG_PATH="${libclang}/lib"
25 '';
26
27 postInstall = ''
28 mv $out/bin/{bindgen,.bindgen-wrapped};
29 substituteAll ${./wrapper.sh} $out/bin/bindgen
30 chmod +x $out/bin/bindgen
31 '';
32
33 doCheck = true;
34 checkInputs =
35 let fakeRustup = writeScriptBin "rustup" ''
36 #!${runtimeShell}
37 shift
38 shift
39 exec "$@"
40 '';
41 in [
42 rustfmt
43 fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
44 clang
45 ];
46 preCheck = ''
47 # for the ci folder, notably
48 patchShebangs .
49 '';
50
51 meta = with stdenv.lib; {
52 description = "C and C++ binding generator";
53 longDescription = ''
54 Bindgen takes a c or c++ header file and turns them into
55 rust ffi declarations.
56 As with most compiler related software, this will only work
57 inside a nix-shell with the required libraries as buildInputs.
58 '';
59 homepage = https://github.com/rust-lang-nursery/rust-bindgen;
60 license = with licenses; [ bsd3 ];
61 maintainers = [ maintainers.ralith ];
62 };
63}