2021-01-25 00:26:54 -08:00
|
|
|
{ lib, fetchFromGitHub, rustPlatform, clang, llvmPackages, rustfmt, writeScriptBin
|
2021-01-21 11:16:58 -08:00
|
|
|
, runtimeShell
|
|
|
|
, bash
|
|
|
|
}:
|
2016-11-23 09:09:29 -08:00
|
|
|
|
2017-03-21 19:00:11 -07:00
|
|
|
rustPlatform.buildRustPackage rec {
|
2019-04-24 09:28:40 -07:00
|
|
|
pname = "rust-bindgen";
|
2021-03-09 05:28:21 -08:00
|
|
|
version = "0.57.0";
|
2016-11-23 09:09:29 -08:00
|
|
|
|
2019-08-25 05:23:01 -07:00
|
|
|
RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update
|
|
|
|
|
2016-11-23 09:09:29 -08:00
|
|
|
src = fetchFromGitHub {
|
2019-04-24 09:28:40 -07:00
|
|
|
owner = "rust-lang";
|
|
|
|
repo = pname;
|
2018-03-25 16:08:04 -07:00
|
|
|
rev = "v${version}";
|
2021-03-09 05:28:21 -08:00
|
|
|
sha256 = "sha256-0d8+Rkb4h1DoFUQ7u2/kPR/fUUz0YvI+hNT4iXL3mxY=";
|
2016-11-23 09:09:29 -08:00
|
|
|
};
|
|
|
|
|
2021-05-17 17:06:41 -07:00
|
|
|
cargoSha256 = "0r60smhlx1992a1s1k5sxjpdqllb2xsqcimgx3ldp5fdkfphk3cw";
|
2018-08-19 05:26:20 -07:00
|
|
|
|
2021-01-21 11:16:58 -08:00
|
|
|
#for substituteAll
|
|
|
|
libclang = llvmPackages.libclang.lib;
|
|
|
|
inherit bash;
|
2018-08-19 05:26:20 -07:00
|
|
|
|
|
|
|
buildInputs = [ libclang ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ clang ]; # to populate NIX_CXXSTDLIB_COMPILE
|
|
|
|
|
2016-11-23 09:09:29 -08:00
|
|
|
configurePhase = ''
|
llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.
The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.
Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.
----
Other misc notes, highly incomplete
- lvm-config-native and llvm-config are put in `dev` because they are
tools just for build time.
- Clang no longer has an lld dep. That was introduced in
db29857eb391ed002046090851a44c452b80bdbd, but if clang needs help
finding lld when it is used we should just pass it flags / put in the
resource dir. Providing it at build time increases critical path
length for no good reason.
----
A note on `nativeCC`:
`stdenv` takes tools from the previous stage, so:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`
while:
1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2020-10-15 01:23:57 -07:00
|
|
|
export LIBCLANG_PATH="${libclang.lib}/lib"
|
2016-11-23 09:09:29 -08:00
|
|
|
'';
|
|
|
|
|
2017-05-04 22:17:56 -07:00
|
|
|
postInstall = ''
|
2018-08-19 05:26:20 -07:00
|
|
|
mv $out/bin/{bindgen,.bindgen-wrapped};
|
|
|
|
substituteAll ${./wrapper.sh} $out/bin/bindgen
|
|
|
|
chmod +x $out/bin/bindgen
|
2017-05-04 22:17:56 -07:00
|
|
|
'';
|
|
|
|
|
2018-11-23 08:52:25 -08:00
|
|
|
doCheck = true;
|
2018-08-19 05:26:20 -07:00
|
|
|
checkInputs =
|
|
|
|
let fakeRustup = writeScriptBin "rustup" ''
|
2019-02-26 03:45:54 -08:00
|
|
|
#!${runtimeShell}
|
2018-08-19 05:26:20 -07:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
exec "$@"
|
|
|
|
'';
|
|
|
|
in [
|
|
|
|
rustfmt
|
|
|
|
fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
|
|
|
|
clang
|
|
|
|
];
|
2018-11-23 08:52:25 -08:00
|
|
|
preCheck = ''
|
|
|
|
# for the ci folder, notably
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2016-11-23 09:09:29 -08:00
|
|
|
|
2021-01-10 23:54:33 -08:00
|
|
|
meta = with lib; {
|
2020-10-10 22:55:05 -07:00
|
|
|
description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
|
2018-08-19 05:26:20 -07:00
|
|
|
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.
|
|
|
|
'';
|
2020-03-11 23:10:16 -07:00
|
|
|
homepage = "https://github.com/rust-lang/rust-bindgen";
|
2016-11-23 09:09:29 -08:00
|
|
|
license = with licenses; [ bsd3 ];
|
2019-06-24 13:05:28 -07:00
|
|
|
platforms = platforms.unix;
|
2020-08-16 16:30:07 -07:00
|
|
|
maintainers = with maintainers; [ johntitor ralith ];
|
2016-11-23 09:09:29 -08:00
|
|
|
};
|
|
|
|
}
|