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