rust-bindgen: separate into unwrapped and wrapped

This commit is contained in:
Guillaume Girol 2022-02-03 12:00:00 +00:00
parent 7283e2dd06
commit 703bbde201
4 changed files with 85 additions and 76 deletions

View File

@ -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 ];
};
}

View File

@ -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 ];
};
}

View File

@ -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.

View File

@ -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;