diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2018-08-30 13:12:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 13:12:03 +0100 |
commit | da11a26008818b8bf64aa13709a1ee6b13fc8eba (patch) | |
tree | b2bb77b1d633a0440cb447bc9fae9ea705663737 /pkgs/development/tools/rust | |
parent | d347eed514244a8832f88dab1f402b06e724e18d (diff) | |
parent | 4c4fc2299c5e598f3a7f6f1e4a58739244acc975 (diff) |
Merge pull request #45330 from symphorien/bindgen2
rustup: wrap bindgen to find header files in a nix-shell
Diffstat (limited to 'pkgs/development/tools/rust')
-rw-r--r-- | pkgs/development/tools/rust/bindgen/default.nix | 49 | ||||
-rwxr-xr-x | pkgs/development/tools/rust/bindgen/wrapper.sh | 36 |
2 files changed, 75 insertions, 10 deletions
diff --git a/pkgs/development/tools/rust/bindgen/default.nix b/pkgs/development/tools/rust/bindgen/default.nix index aeeae494e5865..68df0af6ee462 100644 --- a/pkgs/development/tools/rust/bindgen/default.nix +++ b/pkgs/development/tools/rust/bindgen/default.nix @@ -1,6 +1,4 @@ -{ stdenv, fetchFromGitHub, rustPlatform, makeWrapper, llvmPackages }: - -# Future work: Automatically communicate NIX_CFLAGS_COMPILE to bindgen's tests and the bindgen executable itself. +{ stdenv, fetchFromGitHub, fetchpatch, rustPlatform, clang, llvmPackages, rustfmt, writeScriptBin }: rustPlatform.buildRustPackage rec { name = "rust-bindgen-${version}"; @@ -13,23 +11,54 @@ rustPlatform.buildRustPackage rec { sha256 = "0cqjr7qspjrfgqcp4nqxljmhhbqyijb2jpw3lajgjj48y6wrnw93"; }; - nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ llvmPackages.clang-unwrapped.lib ]; + cargoSha256 = "0b8v6c7q1abibzygrigldpd31lyd5ngmj4vq5d7zni96m20mm85w"; + + libclang = llvmPackages.libclang.lib; #for substituteAll + + buildInputs = [ libclang ]; + + propagatedBuildInputs = [ clang ]; # to populate NIX_CXXSTDLIB_COMPILE + + patches = [ + # https://github.com/rust-lang-nursery/rust-bindgen/pull/1376 + (fetchpatch { + url = https://github.com/rust-lang-nursery/rust-bindgen/commit/c8b5406f08af82a92bf8faf852c21ba941d9c176.patch; + sha256 = "16ibr2rplh0qz8rsq6gir45xlz5nasad4y8fprwhrb7ssv8wfkss"; + }) + ]; configurePhase = '' - export LIBCLANG_PATH="${llvmPackages.clang-unwrapped.lib}/lib" + export LIBCLANG_PATH="${libclang}/lib" ''; postInstall = '' - wrapProgram $out/bin/bindgen --set LIBCLANG_PATH "${llvmPackages.clang-unwrapped.lib}/lib" + mv $out/bin/{bindgen,.bindgen-wrapped}; + substituteAll ${./wrapper.sh} $out/bin/bindgen + chmod +x $out/bin/bindgen ''; - cargoSha256 = "0b8v6c7q1abibzygrigldpd31lyd5ngmj4vq5d7zni96m20mm85w"; - - doCheck = false; # A test fails because it can't find standard headers in NixOS + doCheck = false; # half the tests fail because our rustfmt is not nightly enough + checkInputs = + let fakeRustup = writeScriptBin "rustup" '' + #!${stdenv.shell} + shift + shift + exec "$@" + ''; + in [ + rustfmt + fakeRustup # the test suite insists in calling `rustup run nightly rustfmt` + clang + ]; meta = with stdenv.lib; { description = "C and C++ binding generator"; + 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-nursery/rust-bindgen; license = with licenses; [ bsd3 ]; maintainers = [ maintainers.ralith ]; diff --git a/pkgs/development/tools/rust/bindgen/wrapper.sh b/pkgs/development/tools/rust/bindgen/wrapper.sh new file mode 100755 index 0000000000000..95cd0901cec84 --- /dev/null +++ b/pkgs/development/tools/rust/bindgen/wrapper.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +sep='--' # whether to add -- before new options +cxx=0 # whether cxx was explicitly requested +lastWasx=0 # whether the last argument passed was -x +for e in "$@"; do + if [[ "$e" == "--" ]]; then + sep= + fi; + if [[ "$sep" == "" ]]; then + # we look for -x c++ after -- only + if [[ "$e" == "-x" ]]; then + lastWasx=1 + fi; + if [[ $lastWasx -eq 1 && "$e" == "c++" ]]; then + lastWasx=0 + cxx=1 + fi; + if [[ "$e" == "-xc++" || "$e" == -std=c++* ]]; then + cxx=1 + fi; + fi; +done; +cxxflags= +if [[ $cxx -eq 1 ]]; then + cxxflags=$NIX_CXXSTDLIB_COMPILE +fi; +if [[ -n "$NIX_DEBUG" ]]; then + set -x; +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 +# note that we add the flags after $@ which is incorrect. This is only for the sake +# of simplicity. + |