diff --git a/pkgs/development/tools/rust/bindgen/default.nix b/pkgs/development/tools/rust/bindgen/default.nix index 0da7303a36fb..f4fbbeedd5d4 100644 --- a/pkgs/development/tools/rust/bindgen/default.nix +++ b/pkgs/development/tools/rust/bindgen/default.nix @@ -1,78 +1,18 @@ -{ lib, fetchFromGitHub, rustPlatform, clang, 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="; - +{ rust-bindgen-unwrapped, bash, runCommand }: +let + clang = rust-bindgen-unwrapped.clang; +in +runCommand "rust-bindgen-${rust-bindgen-unwrapped.version}" +{ #for substituteAll - libclang = clang.cc.lib; # use the same version of clang for cxxincludes and libclang inherit bash; + unwrapped = rust-bindgen-unwrapped; + libclang = clang.cc.lib; +} '' + 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 +'' - buildInputs = [ libclang ]; - - preConfigure = '' - export LIBCLANG_PATH="${lib.getLib libclang}/lib" - ''; - - postInstall = '' - mv $out/bin/{bindgen,.bindgen-wrapped}; - 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. - This version of bindgen is wrapped with the required compiler flags - required to find the c and c++ standard libary of the input clang - derivation. - ''; - 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/unwrapped.nix b/pkgs/development/tools/rust/bindgen/unwrapped.nix new file mode 100644 index 000000000000..3438724525a1 --- /dev/null +++ b/pkgs/development/tools/rust/bindgen/unwrapped.nix @@ -0,0 +1,68 @@ +{ 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. + As with most compiler related software, this will only work + inside a nix-shell with the required libraries as buildInputs. + This version of bindgen is wrapped with the required compiler flags + required to find the c and c++ standard libary of the input clang + derivation. + ''; + 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 60dc293d528e..b7110385c26d 100755 --- a/pkgs/development/tools/rust/bindgen/wrapper.sh +++ b/pkgs/development/tools/rust/bindgen/wrapper.sh @@ -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 @cincludes@ $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. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index d1e2011a4cfb..1485b6a0f27e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -13151,6 +13151,7 @@ with pkgs; inherit (darwin.apple_sdk.frameworks) CoreServices; }; rust-analyzer = callPackage ../development/tools/rust/rust-analyzer/wrapper.nix { }; + rust-bindgen-unwrapped = callPackage ../development/tools/rust/bindgen/unwrapped.nix { }; rust-bindgen = callPackage ../development/tools/rust/bindgen { }; rust-cbindgen = callPackage ../development/tools/rust/cbindgen { inherit (darwin.apple_sdk.frameworks) Security;