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