diff options
author | Guillaume Girol <symphorien@users.noreply.github.com> | 2022-02-06 12:41:57 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-06 12:41:57 +0000 |
commit | 942b0817e898262cc6e3f0a5f706ce09d8f749f1 (patch) | |
tree | 9117f18fc8ea67112dae85636ec03ba8741dc84b /pkgs/development | |
parent | 8fedc72324626d01e3404fcb4ee4fc34087ba4d1 (diff) | |
parent | d1d0d1184e284e5f184837743d2afc572f6fc2c7 (diff) |
Merge pull request #158041 from symphorien/bindgen
rust-bindgen: fix finding c++ stdlib
Diffstat (limited to 'pkgs/development')
-rw-r--r-- | pkgs/development/tools/rust/bindgen/default.nix | 114 | ||||
-rw-r--r-- | pkgs/development/tools/rust/bindgen/unwrapped.nix | 63 | ||||
-rwxr-xr-x | pkgs/development/tools/rust/bindgen/wrapper.sh | 4 |
3 files changed, 107 insertions, 74 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 diff --git a/pkgs/development/tools/rust/bindgen/unwrapped.nix b/pkgs/development/tools/rust/bindgen/unwrapped.nix new file mode 100644 index 0000000000000..65ce8e20bc0ef --- /dev/null +++ b/pkgs/development/tools/rust/bindgen/unwrapped.nix @@ -0,0 +1,63 @@ +{ lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile +, runtimeShell +, bash +}: + +rustPlatform.buildRustPackage rec { + pname = "rust-bindgen-unwrapped"; + version = "0.59.2"; + + RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update + + src = fetchFromGitHub { + owner = "rust-lang"; + repo = "rust-bindgen"; + rev = "v${version}"; + sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs="; + }; + + cargoSha256 = "sha256-RKZY5vf6CSFaKweuuNkeFF0ZXlSUibAkcL/YhkE0MoQ="; + + buildInputs = [ clang.cc.lib ]; + + preConfigure = '' + export LIBCLANG_PATH="${clang.cc.lib}/lib" + ''; + + 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 . + ''; + + passthru = { inherit clang; }; + + 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. + ''; + homepage = "https://github.com/rust-lang/rust-bindgen"; + license = with licenses; [ bsd3 ]; + platforms = platforms.unix; + maintainers = with maintainers; [ johntitor ralith ]; + }; +} diff --git a/pkgs/development/tools/rust/bindgen/wrapper.sh b/pkgs/development/tools/rust/bindgen/wrapper.sh index 0b3e3cd4c1e03..b7110385c26d6 100755 --- a/pkgs/development/tools/rust/bindgen/wrapper.sh +++ b/pkgs/development/tools/rust/bindgen/wrapper.sh @@ -22,7 +22,7 @@ for e in "$@"; do done; cxxflags= if [[ $cxx -eq 1 ]]; then - cxxflags=$NIX_CXXSTDLIB_COMPILE + cxxflags="@cxxincludes@" fi; if [[ -n "$NIX_DEBUG" ]]; then set -x; @@ -30,7 +30,7 @@ fi; export LIBCLANG_PATH="@libclang@/lib" # shellcheck disable=SC2086 # cxxflags and NIX_CFLAGS_COMPILE should be word-split -exec -a "$0" @out@/bin/.bindgen-wrapped "$@" $sep $cxxflags $NIX_CFLAGS_COMPILE +exec -a "$0" @unwrapped@/bin/bindgen "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE # note that we add the flags after $@ which is incorrect. This is only for the sake # of simplicity. |