1{
2 lib,
3 fetchCrate,
4 rustPlatform,
5 clang,
6 rustfmt,
7}:
8let
9 # bindgen hardcodes rustfmt outputs that use nightly features
10 rustfmt-nightly = rustfmt.override { asNightly = true; };
11in
12rustPlatform.buildRustPackage rec {
13 pname = "rust-bindgen-unwrapped";
14 version = "0.72.0";
15
16 src = fetchCrate {
17 pname = "bindgen-cli";
18 inherit version;
19 hash = "sha256-0hIxXKq7zu/gq0QAs2Ffuq584a9w1RWctPs9SBfc0/I=";
20 };
21
22 cargoHash = "sha256-K/iM79RfNU+3f2ae6wy/FMFAD68vfqzSUebqALPJpJY=";
23
24 preConfigure = ''
25 export LIBCLANG_PATH="${lib.getLib clang.cc}/lib"
26 '';
27
28 # Disable the "runtime" feature, so libclang is linked.
29 buildNoDefaultFeatures = true;
30 buildFeatures = [ "logging" ];
31 checkNoDefaultFeatures = buildNoDefaultFeatures;
32 checkFeatures = buildFeatures;
33
34 doCheck = true;
35 nativeCheckInputs = [ clang ];
36
37 RUSTFMT = "${rustfmt-nightly}/bin/rustfmt";
38
39 preCheck = ''
40 # for the ci folder, notably
41 patchShebangs .
42 '';
43
44 passthru = { inherit clang; };
45
46 meta = with lib; {
47 description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
48 longDescription = ''
49 Bindgen takes a c or c++ header file and turns them into
50 rust ffi declarations.
51 '';
52 homepage = "https://github.com/rust-lang/rust-bindgen";
53 license = with licenses; [ bsd3 ];
54 maintainers = with maintainers; [ johntitor ];
55 mainProgram = "bindgen";
56 platforms = platforms.unix;
57 };
58}