about summary refs log tree commit diff
path: root/pkgs/development/tools/rust/bindgen/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/development/tools/rust/bindgen/default.nix')
-rw-r--r--pkgs/development/tools/rust/bindgen/default.nix114
1 files changed, 42 insertions, 72 deletions
diff --git a/pkgs/development/tools/rust/bindgen/default.nix b/pkgs/development/tools/rust/bindgen/default.nix
index 2c69ad9876ecb..782996d92180d 100644
--- a/pkgs/development/tools/rust/bindgen/default.nix
+++ b/pkgs/development/tools/rust/bindgen/default.nix
@@ -1,75 +1,45 @@
-{ lib, fetchFromGitHub, rustPlatform, clang, llvmPackages_latest, rustfmt, writeTextFile
-, runtimeShell
-, bash
-}:
-
-rustPlatform.buildRustPackage rec {
-  pname = "rust-bindgen";
-  version = "0.59.2";
-
-  RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update
-
-  src = fetchFromGitHub {
-    owner = "rust-lang";
-    repo = pname;
-    rev = "v${version}";
-    sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs=";
-  };
-
-  cargoSha256 = "sha256-zhENlrqj611RkKDvpDtDFWc58wfQVamkJnpe2nvRieE=";
-
-  #for substituteAll
-  libclang = llvmPackages_latest.libclang.lib;
-  inherit bash;
-
-  buildInputs = [ libclang ];
-
-  propagatedBuildInputs = [ clang ]; # to populate NIX_CXXSTDLIB_COMPILE
-
-  configurePhase = ''
-    export LIBCLANG_PATH="${libclang.lib}/lib"
-  '';
-
-  postInstall = ''
-    mv $out/bin/{bindgen,.bindgen-wrapped};
+{ rust-bindgen-unwrapped, zlib, bash, runCommand, runCommandCC }:
+let
+  clang = rust-bindgen-unwrapped.clang;
+  self = runCommand "rust-bindgen-${rust-bindgen-unwrapped.version}"
+    {
+      #for substituteAll
+      inherit bash;
+      unwrapped = rust-bindgen-unwrapped;
+      libclang = clang.cc.lib;
+      meta = rust-bindgen-unwrapped.meta // {
+        longDescription = rust-bindgen-unwrapped.meta.longDescription + ''
+          This version of bindgen is wrapped with the required compiler flags
+          required to find the c and c++ standard libary, as well as the libraries
+          specified in the buildInputs of your derivation.
+        '';
+      };
+      passthru.tests = {
+        simple-c = runCommandCC "simple-c-bindgen-tests" { } ''
+          echo '#include <stdlib.h>' > a.c
+          ${self}/bin/bindgen a.c --whitelist-function atoi | tee output
+          grep atoi output
+          touch $out
+        '';
+        simple-cpp = runCommandCC "simple-cpp-bindgen-tests" { } ''
+          echo '#include <cmath>' > a.cpp
+          ${self}/bin/bindgen a.cpp --whitelist-function erf -- -xc++ | tee output
+          grep erf output
+          touch $out
+        '';
+        with-lib = runCommandCC "zlib-bindgen-tests" { buildInputs = [ zlib ]; } ''
+          echo '#include <zlib.h>' > a.c
+          ${self}/bin/bindgen a.c --whitelist-function compress | tee output
+          grep compress output
+          touch $out
+        '';
+      };
+    } ''
+    mkdir -p $out/bin
+    export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)"
+    export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)"
     substituteAll ${./wrapper.sh} $out/bin/bindgen
     chmod +x $out/bin/bindgen
   '';
-
-  doCheck = true;
-  checkInputs =
-    let fakeRustup = writeTextFile {
-      name = "fake-rustup";
-      executable = true;
-      destination = "/bin/rustup";
-      text = ''
-        #!${runtimeShell}
-        shift
-        shift
-        exec "$@"
-      '';
-    };
-  in [
-    rustfmt
-    fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
-    clang
-  ];
-  preCheck = ''
-    # for the ci folder, notably
-    patchShebangs .
-  '';
-
-  meta = with lib; {
-    description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
-    longDescription = ''
-      Bindgen takes a c or c++ header file and turns them into
-      rust ffi declarations.
-      As with most compiler related software, this will only work
-      inside a nix-shell with the required libraries as buildInputs.
-    '';
-    homepage = "https://github.com/rust-lang/rust-bindgen";
-    license = with licenses; [ bsd3 ];
-    platforms = platforms.unix;
-    maintainers = with maintainers; [ johntitor ralith ];
-  };
-}
+in
+self