Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
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 = rust-bindgen-unwrapped.meta.longDescription + '' 20 This version of bindgen is wrapped with the required compiler flags 21 required to find the c and c++ standard library, as well as the libraries 22 specified in the buildInputs of your derivation. 23 ''; 24 }; 25 passthru.tests = { 26 simple-c = runCommandCC "simple-c-bindgen-tests" { } '' 27 echo '#include <stdlib.h>' > a.c 28 ${self}/bin/bindgen a.c --allowlist-function atoi | tee output 29 grep atoi output 30 touch $out 31 ''; 32 simple-cpp = runCommandCC "simple-cpp-bindgen-tests" { } '' 33 echo '#include <cmath>' > a.cpp 34 ${self}/bin/bindgen a.cpp --allowlist-function erf -- -xc++ | tee output 35 grep erf output 36 touch $out 37 ''; 38 with-lib = runCommandCC "zlib-bindgen-tests" { buildInputs = [ zlib ]; } '' 39 echo '#include <zlib.h>' > a.c 40 ${self}/bin/bindgen a.c --allowlist-function compress | tee output 41 grep compress output 42 touch $out 43 ''; 44 }; 45 } 46 # if you modify the logic to find the right clang flags, also modify rustPlatform.bindgenHook 47 '' 48 mkdir -p $out/bin 49 export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)" 50 export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)" 51 substituteAll ${./wrapper.sh} $out/bin/bindgen 52 chmod +x $out/bin/bindgen 53 ''; 54in 55self