rust-bindgen: some features of bindgen require a recent version of llvm
Features likes 'asm goto' are only available if compiled with llvm >= 11.
This is required for rust-in-linux development for example. I believe
binding to llvmPackages_latest is an acceptable tradeoff.
```
RUSTC L rust/build_error.o
error: unknown argument: '-fmacro-prefix-map=./='
error: unknown argument: '-fno-stack-clash-protection'
error: unknown warning option '-Wno-frame-address'; did you mean '-Wno-address'? [-Wunknown-warning-option]
error: unknown warning option '-Wno-pointer-to-enum-cast' [-Wunknown-warning-option]
./arch/x86/include/asm/bitops.h:138:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/bitops.h:162:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/bitops.h:201:9: error: 'asm goto' constructs are not supported yet
./include/linux/list.h:282:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:318:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:821:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:830:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./arch/x86/include/asm/atomic.h:83:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:123:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:137:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:152:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:76:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:118:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:132:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:147:9: error: 'asm goto' constructs are not supported yet
./include/linux/jump_label.h:278:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:284:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:306:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:309:3: error: expected '(' after 'asm'
./include/linux/jump_label.h:317:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:320:3: error: expected '(' after 'asm'
./include/linux/llist.h:189:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
fatal error: too many errors emitted, stopping now [-ferror-limit=]
error: unknown argument: '-fmacro-prefix-map=./=', err: true
error: unknown argument: '-fno-stack-clash-protection', err: true
error: unknown warning option '-Wno-frame-address'; did you mean '-Wno-address'? [-Wunknown-warning-option], err: true
error: unknown warning option '-Wno-pointer-to-enum-cast' [-Wunknown-warning-option], err: true
./arch/x86/include/asm/bitops.h:138:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/bitops.h:162:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/bitops.h:201:9: error: 'asm goto' constructs are not supported yet, err: true
./include/linux/list.h:282:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:318:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:821:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:830:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./arch/x86/include/asm/atomic.h:83:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:123:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:137:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:152:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:76:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:118:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:132:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:147:9: error: 'asm goto' constructs are not supported yet, err: true
./include/linux/jump_label.h:278:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:284:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:306:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:309:3: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:317:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:320:3: error: expected '(' after 'asm', err: true
./include/linux/llist.h:189:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'Unable to generate bindings: ()', src/main.rs:54:36
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make[1]: *** [rust/Makefile:141: rust/bindings_generated.rs] Error 1
make[1]: *** Deleting file 'rust/bindings_generated.rs'
```
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
2021-06-16 18:57:16 +01:00
|
|
|
{ lib, fetchFromGitHub, rustPlatform, clang, llvmPackages_latest, rustfmt, writeScriptBin
|
2021-01-21 19:16:58 +00:00
|
|
|
, runtimeShell
|
|
|
|
, bash
|
|
|
|
}:
|
2016-11-23 17:09:29 +00:00
|
|
|
|
2017-03-22 02:00:11 +00:00
|
|
|
rustPlatform.buildRustPackage rec {
|
2019-04-24 17:28:40 +01:00
|
|
|
pname = "rust-bindgen";
|
2021-03-09 13:28:21 +00:00
|
|
|
version = "0.57.0";
|
2016-11-23 17:09:29 +00:00
|
|
|
|
2019-08-25 13:23:01 +01:00
|
|
|
RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update
|
|
|
|
|
2016-11-23 17:09:29 +00:00
|
|
|
src = fetchFromGitHub {
|
2019-04-24 17:28:40 +01:00
|
|
|
owner = "rust-lang";
|
|
|
|
repo = pname;
|
2018-03-26 00:08:04 +01:00
|
|
|
rev = "v${version}";
|
2021-03-09 13:28:21 +00:00
|
|
|
sha256 = "sha256-0d8+Rkb4h1DoFUQ7u2/kPR/fUUz0YvI+hNT4iXL3mxY=";
|
2016-11-23 17:09:29 +00:00
|
|
|
};
|
|
|
|
|
2021-05-18 01:06:41 +01:00
|
|
|
cargoSha256 = "0r60smhlx1992a1s1k5sxjpdqllb2xsqcimgx3ldp5fdkfphk3cw";
|
2018-08-19 13:26:20 +01:00
|
|
|
|
2021-01-21 19:16:58 +00:00
|
|
|
#for substituteAll
|
rust-bindgen: some features of bindgen require a recent version of llvm
Features likes 'asm goto' are only available if compiled with llvm >= 11.
This is required for rust-in-linux development for example. I believe
binding to llvmPackages_latest is an acceptable tradeoff.
```
RUSTC L rust/build_error.o
error: unknown argument: '-fmacro-prefix-map=./='
error: unknown argument: '-fno-stack-clash-protection'
error: unknown warning option '-Wno-frame-address'; did you mean '-Wno-address'? [-Wunknown-warning-option]
error: unknown warning option '-Wno-pointer-to-enum-cast' [-Wunknown-warning-option]
./arch/x86/include/asm/bitops.h:138:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/bitops.h:162:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/bitops.h:201:9: error: 'asm goto' constructs are not supported yet
./include/linux/list.h:282:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:318:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:821:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./include/linux/list.h:830:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
./arch/x86/include/asm/atomic.h:83:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:123:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:137:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic.h:152:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:76:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:118:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:132:9: error: 'asm goto' constructs are not supported yet
./arch/x86/include/asm/atomic64_64.h:147:9: error: 'asm goto' constructs are not supported yet
./include/linux/jump_label.h:278:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:284:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:306:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:309:3: error: expected '(' after 'asm'
./include/linux/jump_label.h:317:2: error: expected '(' after 'asm'
./include/linux/jump_label.h:320:3: error: expected '(' after 'asm'
./include/linux/llist.h:189:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
fatal error: too many errors emitted, stopping now [-ferror-limit=]
error: unknown argument: '-fmacro-prefix-map=./=', err: true
error: unknown argument: '-fno-stack-clash-protection', err: true
error: unknown warning option '-Wno-frame-address'; did you mean '-Wno-address'? [-Wunknown-warning-option], err: true
error: unknown warning option '-Wno-pointer-to-enum-cast' [-Wunknown-warning-option], err: true
./arch/x86/include/asm/bitops.h:138:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/bitops.h:162:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/bitops.h:201:9: error: 'asm goto' constructs are not supported yet, err: true
./include/linux/list.h:282:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:318:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:821:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./include/linux/list.h:830:10: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
./arch/x86/include/asm/atomic.h:83:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:123:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:137:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic.h:152:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:76:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:118:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:132:9: error: 'asm goto' constructs are not supported yet, err: true
./arch/x86/include/asm/atomic64_64.h:147:9: error: 'asm goto' constructs are not supported yet, err: true
./include/linux/jump_label.h:278:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:284:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:306:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:309:3: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:317:2: error: expected '(' after 'asm', err: true
./include/linux/jump_label.h:320:3: error: expected '(' after 'asm', err: true
./include/linux/llist.h:189:9: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier], err: false
fatal error: too many errors emitted, stopping now [-ferror-limit=], err: true
thread 'main' panicked at 'Unable to generate bindings: ()', src/main.rs:54:36
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
make[1]: *** [rust/Makefile:141: rust/bindings_generated.rs] Error 1
make[1]: *** Deleting file 'rust/bindings_generated.rs'
```
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
2021-06-16 18:57:16 +01:00
|
|
|
libclang = llvmPackages_latest.libclang.lib;
|
2021-01-21 19:16:58 +00:00
|
|
|
inherit bash;
|
2018-08-19 13:26:20 +01:00
|
|
|
|
|
|
|
buildInputs = [ libclang ];
|
|
|
|
|
|
|
|
propagatedBuildInputs = [ clang ]; # to populate NIX_CXXSTDLIB_COMPILE
|
|
|
|
|
2016-11-23 17:09:29 +00: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 09:23:57 +01:00
|
|
|
export LIBCLANG_PATH="${libclang.lib}/lib"
|
2016-11-23 17:09:29 +00:00
|
|
|
'';
|
|
|
|
|
2017-05-05 06:17:56 +01:00
|
|
|
postInstall = ''
|
2018-08-19 13:26:20 +01:00
|
|
|
mv $out/bin/{bindgen,.bindgen-wrapped};
|
|
|
|
substituteAll ${./wrapper.sh} $out/bin/bindgen
|
|
|
|
chmod +x $out/bin/bindgen
|
2017-05-05 06:17:56 +01:00
|
|
|
'';
|
|
|
|
|
2018-11-23 16:52:25 +00:00
|
|
|
doCheck = true;
|
2018-08-19 13:26:20 +01:00
|
|
|
checkInputs =
|
|
|
|
let fakeRustup = writeScriptBin "rustup" ''
|
2019-02-26 11:45:54 +00:00
|
|
|
#!${runtimeShell}
|
2018-08-19 13:26:20 +01:00
|
|
|
shift
|
|
|
|
shift
|
|
|
|
exec "$@"
|
|
|
|
'';
|
|
|
|
in [
|
|
|
|
rustfmt
|
|
|
|
fakeRustup # the test suite insists in calling `rustup run nightly rustfmt`
|
|
|
|
clang
|
|
|
|
];
|
2018-11-23 16:52:25 +00:00
|
|
|
preCheck = ''
|
|
|
|
# for the ci folder, notably
|
|
|
|
patchShebangs .
|
|
|
|
'';
|
2016-11-23 17:09:29 +00:00
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2020-10-11 06:55:05 +01:00
|
|
|
description = "Automatically generates Rust FFI bindings to C (and some C++) libraries";
|
2018-08-19 13:26:20 +01: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-12 06:10:16 +00:00
|
|
|
homepage = "https://github.com/rust-lang/rust-bindgen";
|
2016-11-23 17:09:29 +00:00
|
|
|
license = with licenses; [ bsd3 ];
|
2019-06-24 21:05:28 +01:00
|
|
|
platforms = platforms.unix;
|
2020-08-17 00:30:07 +01:00
|
|
|
maintainers = with maintainers; [ johntitor ralith ];
|
2016-11-23 17:09:29 +00:00
|
|
|
};
|
|
|
|
}
|