rust-bindgen: separate into unwrapped and wrapped

+85 -76
+15 -75
pkgs/development/tools/rust/bindgen/default.nix
··· 1 - { lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile 2 - , runtimeShell 3 - , bash 4 - }: 5 - 6 - rustPlatform.buildRustPackage rec { 7 - pname = "rust-bindgen"; 8 - version = "0.59.2"; 9 - 10 - RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update 11 - 12 - src = fetchFromGitHub { 13 - owner = "rust-lang"; 14 - repo = pname; 15 - rev = "v${version}"; 16 - sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs="; 17 - }; 18 - 19 - cargoSha256 = "sha256-zhENlrqj611RkKDvpDtDFWc58wfQVamkJnpe2nvRieE="; 20 - 21 #for substituteAll 22 - libclang = clang.cc.lib; # use the same version of clang for cxxincludes and libclang 23 inherit bash; 24 - 25 - buildInputs = [ libclang ]; 26 - 27 - preConfigure = '' 28 - export LIBCLANG_PATH="${lib.getLib libclang}/lib" 29 - ''; 30 - 31 - postInstall = '' 32 - mv $out/bin/{bindgen,.bindgen-wrapped}; 33 - export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)" 34 - export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)" 35 - substituteAll ${./wrapper.sh} $out/bin/bindgen 36 - chmod +x $out/bin/bindgen 37 - ''; 38 - 39 - doCheck = true; 40 - checkInputs = 41 - let fakeRustup = writeTextFile { 42 - name = "fake-rustup"; 43 - executable = true; 44 - destination = "/bin/rustup"; 45 - text = '' 46 - #!${runtimeShell} 47 - shift 48 - shift 49 - exec "$@" 50 - ''; 51 - }; 52 - in [ 53 - rustfmt 54 - fakeRustup # the test suite insists in calling `rustup run nightly rustfmt` 55 - clang 56 - ]; 57 - preCheck = '' 58 - # for the ci folder, notably 59 - patchShebangs . 60 - ''; 61 62 - meta = with lib; { 63 - description = "Automatically generates Rust FFI bindings to C (and some C++) libraries"; 64 - longDescription = '' 65 - Bindgen takes a c or c++ header file and turns them into 66 - rust ffi declarations. 67 - As with most compiler related software, this will only work 68 - inside a nix-shell with the required libraries as buildInputs. 69 - This version of bindgen is wrapped with the required compiler flags 70 - required to find the c and c++ standard libary of the input clang 71 - derivation. 72 - ''; 73 - homepage = "https://github.com/rust-lang/rust-bindgen"; 74 - license = with licenses; [ bsd3 ]; 75 - platforms = platforms.unix; 76 - maintainers = with maintainers; [ johntitor ralith ]; 77 - }; 78 - }
··· 1 + { rust-bindgen-unwrapped, bash, runCommand }: 2 + let 3 + clang = rust-bindgen-unwrapped.clang; 4 + in 5 + runCommand "rust-bindgen-${rust-bindgen-unwrapped.version}" 6 + { 7 #for substituteAll 8 inherit bash; 9 + unwrapped = rust-bindgen-unwrapped; 10 + libclang = clang.cc.lib; 11 + } '' 12 + mkdir -p $out/bin 13 + export cincludes="$(< ${clang}/nix-support/cc-cflags) $(< ${clang}/nix-support/libc-cflags)" 14 + export cxxincludes="$(< ${clang}/nix-support/libcxx-cxxflags)" 15 + substituteAll ${./wrapper.sh} $out/bin/bindgen 16 + chmod +x $out/bin/bindgen 17 + '' 18
+68
pkgs/development/tools/rust/bindgen/unwrapped.nix
···
··· 1 + { lib, fetchFromGitHub, rustPlatform, clang, rustfmt, writeTextFile 2 + , runtimeShell 3 + , bash 4 + }: 5 + 6 + rustPlatform.buildRustPackage rec { 7 + pname = "rust-bindgen-unwrapped"; 8 + version = "0.59.2"; 9 + 10 + RUSTFLAGS = "--cap-lints warn"; # probably OK to remove after update 11 + 12 + src = fetchFromGitHub { 13 + owner = "rust-lang"; 14 + repo = "rust-bindgen"; 15 + rev = "v${version}"; 16 + sha256 = "sha256-bJYdyf5uZgWe7fQ80/3QsRV0qyExYn6P9UET3tzwPFs="; 17 + }; 18 + 19 + cargoSha256 = "sha256-RKZY5vf6CSFaKweuuNkeFF0ZXlSUibAkcL/YhkE0MoQ="; 20 + 21 + buildInputs = [ clang.cc.lib ]; 22 + 23 + preConfigure = '' 24 + export LIBCLANG_PATH="${clang.cc.lib}/lib" 25 + ''; 26 + 27 + doCheck = true; 28 + checkInputs = 29 + let fakeRustup = writeTextFile { 30 + name = "fake-rustup"; 31 + executable = true; 32 + destination = "/bin/rustup"; 33 + text = '' 34 + #!${runtimeShell} 35 + shift 36 + shift 37 + exec "$@" 38 + ''; 39 + }; 40 + in [ 41 + rustfmt 42 + fakeRustup # the test suite insists in calling `rustup run nightly rustfmt` 43 + clang 44 + ]; 45 + preCheck = '' 46 + # for the ci folder, notably 47 + patchShebangs . 48 + ''; 49 + 50 + passthru = { inherit clang; }; 51 + 52 + meta = with lib; { 53 + description = "Automatically generates Rust FFI bindings to C (and some C++) libraries"; 54 + longDescription = '' 55 + Bindgen takes a c or c++ header file and turns them into 56 + rust ffi declarations. 57 + As with most compiler related software, this will only work 58 + inside a nix-shell with the required libraries as buildInputs. 59 + This version of bindgen is wrapped with the required compiler flags 60 + required to find the c and c++ standard libary of the input clang 61 + derivation. 62 + ''; 63 + homepage = "https://github.com/rust-lang/rust-bindgen"; 64 + license = with licenses; [ bsd3 ]; 65 + platforms = platforms.unix; 66 + maintainers = with maintainers; [ johntitor ralith ]; 67 + }; 68 + }
+1 -1
pkgs/development/tools/rust/bindgen/wrapper.sh
··· 30 export LIBCLANG_PATH="@libclang@/lib" 31 # shellcheck disable=SC2086 32 # cxxflags and NIX_CFLAGS_COMPILE should be word-split 33 - exec -a "$0" @out@/bin/.bindgen-wrapped "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE 34 # note that we add the flags after $@ which is incorrect. This is only for the sake 35 # of simplicity. 36
··· 30 export LIBCLANG_PATH="@libclang@/lib" 31 # shellcheck disable=SC2086 32 # cxxflags and NIX_CFLAGS_COMPILE should be word-split 33 + exec -a "$0" @unwrapped@/bin/bindgen "$@" $sep $cxxflags @cincludes@ $NIX_CFLAGS_COMPILE 34 # note that we add the flags after $@ which is incorrect. This is only for the sake 35 # of simplicity. 36
+1
pkgs/top-level/all-packages.nix
··· 13151 inherit (darwin.apple_sdk.frameworks) CoreServices; 13152 }; 13153 rust-analyzer = callPackage ../development/tools/rust/rust-analyzer/wrapper.nix { }; 13154 rust-bindgen = callPackage ../development/tools/rust/bindgen { }; 13155 rust-cbindgen = callPackage ../development/tools/rust/cbindgen { 13156 inherit (darwin.apple_sdk.frameworks) Security;
··· 13151 inherit (darwin.apple_sdk.frameworks) CoreServices; 13152 }; 13153 rust-analyzer = callPackage ../development/tools/rust/rust-analyzer/wrapper.nix { }; 13154 + rust-bindgen-unwrapped = callPackage ../development/tools/rust/bindgen/unwrapped.nix { }; 13155 rust-bindgen = callPackage ../development/tools/rust/bindgen { }; 13156 rust-cbindgen = callPackage ../development/tools/rust/cbindgen { 13157 inherit (darwin.apple_sdk.frameworks) Security;