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