1{
2 lib,
3 rust-bindgen-unwrapped,
4 zlib,
5 bash,
6 runCommand,
7 runCommandCC,
8}:
9let
10 clang = rust-bindgen-unwrapped.clang;
11 self =
12 runCommand "rust-bindgen-${rust-bindgen-unwrapped.version}"
13 {
14 #for substituteAll
15 inherit bash;
16 unwrapped = rust-bindgen-unwrapped;
17 libclang = (lib.getLib clang.cc);
18 meta = rust-bindgen-unwrapped.meta // {
19 longDescription =
20 rust-bindgen-unwrapped.meta.longDescription
21 + ''
22 This version of bindgen is wrapped with the required compiler flags
23 required to find the c and c++ standard library, as well as the libraries
24 specified in the buildInputs of your derivation.
25 '';
26 };
27 passthru.tests = {
28 simple-c = runCommandCC "simple-c-bindgen-tests" { } ''
29 echo '#include <stdlib.h>' > a.c
30 ${self}/bin/bindgen a.c --allowlist-function atoi | tee output
31 grep atoi output
32 touch $out
33 '';
34 simple-cpp = runCommandCC "simple-cpp-bindgen-tests" { } ''
35 echo '#include <cmath>' > a.cpp
36 ${self}/bin/bindgen a.cpp --allowlist-function erf -- -xc++ | tee output
37 grep erf output
38 touch $out
39 '';
40 with-lib = runCommandCC "zlib-bindgen-tests" { buildInputs = [ zlib ]; } ''
41 echo '#include <zlib.h>' > a.c
42 ${self}/bin/bindgen a.c --allowlist-function compress | tee output
43 grep compress output
44 touch $out
45 '';
46 };
47 }
48 # if you modify the logic to find the right clang flags, also modify rustPlatform.bindgenHook
49 ''
50 mkdir -p $out/bin
51 export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)"
52 export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"
53 substituteAll ${./wrapper.sh} $out/bin/bindgen
54 chmod +x $out/bin/bindgen
55 '';
56in
57self