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