git.iko.soy/typeable/nixpkgs
on master help sign in
buildRustCrate: added some edge cases with binaries

This commit adds test based on real-world crates (brotli). There were a few more edge cases that were missing beforehand. Also it turned out that we can get rid of the `finalBins` list since that will now be handled during runtime.

commitfc5e5950031d8af57f8b5b9e55187f3e4cb4f063 authorAndreas Rammhold <andreas@rammhold.de> dateThu 13 Sep 2018, 21:12 (8 years ago) parent0f95d05
4 files changed+125−21
pkgs/build-support/rust/build-rust-crate/build-crate.nix+3−4 pkgs/build-support/rust/build-rust-crate/default.nix+2−15 pkgs/build-support/rust/build-rust-crate/test/brotli-crates.nix+95 pkgs/build-support/rust/build-rust-crate/test/default.nix+25−2
pkgs/build-support/rust/build-rust-crate/build-crate.nix+3−4
@@ -2,7 +2,7 @@
22{ crateName,
33 dependencies,
44 crateFeatures, libName, release, libPath,
5− crateType, metadata, crateBin, finalBins,
5+ crateType, metadata, crateBin,
66 extraRustcOpts, verbose, colors }:
77
88 let
@@ -117,11 +117,11 @@
117117
118118 # the first two cases are the "new" default IIRC
119119 BIN_NAME_=$(echo $BIN_NAME | sed -e 's/-/_/g')
120− FILES=( "src/bin/$BIN_NAME_.rs" "src/bin/$BIN_NAME_/main.rs" "src/bin/main.rs" "src/main.rs" )
120+ FILES=( "src/bin/$BIN_NAME.rs" "src/bin/$BIN_NAME/main.rs" "src/bin/$BIN_NAME_.rs" "src/bin/$BIN_NAME_/main.rs" "src/bin/main.rs" "src/main.rs" )
121121
122122 if ! [ -e "${libPath}" -o -e src/lib.rs -o -e "src/${libName}.rs" ]; then
123123 # if this is not a library the following path is also valid
124− FILES=( "src/$BIN_NAME_.rs" "''${FILES[@]}" )
124+ FILES=( "src/$BIN_NAME.rs" "src/$BIN_NAME_.rs" "''${FILES[@]}" )
125125 fi
126126
127127 for file in "''${FILES[@]}";
@@ -153,6 +153,5 @@
153153 ''}
154154 # Remove object files to avoid "wrong ELF type"
155155 find target -type f -name "*.o" -print0 | xargs -0 rm -f
156− '' + finalBins + ''
157156 runHook postBuild
158157 ''
pkgs/build-support/rust/build-rust-crate/default.nix+2−15
@@ -115,8 +115,7 @@ stdenv.mkDerivation (rec {
115115
116116 crateBin = if crate ? crateBin then
117117 builtins.foldl' (bins: bin: let
118− _name = (if bin ? name then bin.name else crateName);
119− name = lib.strings.replaceStrings ["-"] ["_"] _name;
118+ name = (if bin ? name then bin.name else crateName);
120119 path = if bin ? path then bin.path else "";
121120 in
122121 bins + (if bin == "" then "" else ",") + "${name} ${path}"
@@ -124,18 +123,6 @@ stdenv.mkDerivation (rec {
124123 ) "" crate.crateBin
125124 else "";
126125
127− finalBins = if crate ? crateBin then
128− builtins.foldl' (bins: bin:
129− let name = lib.strings.replaceStrings ["-"] ["_"]
130− (if bin ? name then bin.name else crateName);
131− new_name = if bin ? name then bin.name else crateName;
132− in
133− if name == new_name then bins else
134− (bins + "mv target/bin/${name} target/bin/${new_name};")
135−
136− ) "" crate.crateBin
137− else "";
138−
139126 build = crate.build or "";
140127 workspace_member = crate.workspace_member or ".";
141128 crateVersion = crate.version;
@@ -156,7 +143,7 @@ stdenv.mkDerivation (rec {
156143 buildPhase = buildCrate {
157144 inherit crateName dependencies
158145 crateFeatures libName release libPath crateType
159− metadata crateBin finalBins verbose colors
146+ metadata crateBin verbose colors
160147 extraRustcOpts;
161148 };
162149 installPhase = installCrate crateName metadata;
pkgs/build-support/rust/build-rust-crate/test/brotli-crates.nixnew file+95
@@ -0,0 +1,95 @@
1+{ lib, buildPlatform, buildRustCrate, fetchgit }:
2+let kernel = buildPlatform.parsed.kernel.name;
3+ abi = buildPlatform.parsed.abi.name;
4+ include = includedFiles: src: builtins.filterSource (path: type:
5+ lib.lists.any (f:
6+ let p = toString (src + ("/" + f)); in
7+ (path == p) || (type == "directory" && lib.strings.hasPrefix path p)
8+ ) includedFiles
9+ ) src;
10+ updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
11+ mapFeatures = features: map (fun: fun { features = features; });
12+ mkFeatures = feat: lib.lists.foldl (features: featureName:
13+ if feat.${featureName} or false then
14+ [ featureName ] ++ features
15+ else
16+ features
17+ ) [] (builtins.attrNames feat);
18+in
19+rec {
20+ alloc_no_stdlib_1_3_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
21+ crateName = "alloc-no-stdlib";
22+ version = "1.3.0";
23+ authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" ];
24+ sha256 = "1jcp27pzmqdszgp80y484g4kwbjbg7x8a589drcwbxg0i8xwkir9";
25+ crateBin = [ { name = "example"; } ];
26+ inherit dependencies buildDependencies features;
27+ };
28+ brotli_2_5_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
29+ crateName = "brotli";
30+ version = "2.5.0";
31+ authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" "The Brotli Authors" ];
32+ sha256 = "1ynw4hkdwnp0kj30p86ls44ahv4s99258s019bqrq4mya8hlsb5b";
33+ crateBin = [ { name = "brotli"; } ];
34+ inherit dependencies buildDependencies features;
35+ };
36+ brotli_decompressor_1_3_1_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
37+ crateName = "brotli-decompressor";
38+ version = "1.3.1";
39+ authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" "The Brotli Authors" ];
40+ sha256 = "022g69q1xzwdj0130qm3fa4qwpn4q1jx3lc8yz0v0v201p7bm8fb";
41+ crateBin = [ { name = "brotli-decompressor"; } ];
42+ inherit dependencies buildDependencies features;
43+ };
44+ alloc_no_stdlib_1_3_0 = { features?(alloc_no_stdlib_1_3_0_features {}) }: alloc_no_stdlib_1_3_0_ {
45+ features = mkFeatures (features.alloc_no_stdlib_1_3_0 or {});
46+ };
47+ alloc_no_stdlib_1_3_0_features = f: updateFeatures f (rec {
48+ alloc_no_stdlib_1_3_0.default = (f.alloc_no_stdlib_1_3_0.default or true);
49+ }) [];
50+ brotli_2_5_0 = { features?(brotli_2_5_0_features {}) }: brotli_2_5_0_ {
51+ dependencies = mapFeatures features ([ alloc_no_stdlib_1_3_0 brotli_decompressor_1_3_1 ]);
52+ features = mkFeatures (features.brotli_2_5_0 or {});
53+ };
54+ brotli_2_5_0_features = f: updateFeatures f (rec {
55+ alloc_no_stdlib_1_3_0."no-stdlib" =
56+ (f.alloc_no_stdlib_1_3_0."no-stdlib" or false) ||
57+ (brotli_2_5_0."no-stdlib" or false) ||
58+ (f.brotli_2_5_0."no-stdlib" or false);
59+ alloc_no_stdlib_1_3_0.default = true;
60+ brotli_2_5_0.default = (f.brotli_2_5_0.default or true);
61+ brotli_decompressor_1_3_1."disable-timer" =
62+ (f.brotli_decompressor_1_3_1."disable-timer" or false) ||
63+ (brotli_2_5_0."disable-timer" or false) ||
64+ (f.brotli_2_5_0."disable-timer" or false);
65+ brotli_decompressor_1_3_1."no-stdlib" =
66+ (f.brotli_decompressor_1_3_1."no-stdlib" or false) ||
67+ (brotli_2_5_0."no-stdlib" or false) ||
68+ (f.brotli_2_5_0."no-stdlib" or false);
69+ brotli_decompressor_1_3_1.benchmark =
70+ (f.brotli_decompressor_1_3_1.benchmark or false) ||
71+ (brotli_2_5_0.benchmark or false) ||
72+ (f.brotli_2_5_0.benchmark or false);
73+ brotli_decompressor_1_3_1.default = true;
74+ brotli_decompressor_1_3_1.seccomp =
75+ (f.brotli_decompressor_1_3_1.seccomp or false) ||
76+ (brotli_2_5_0.seccomp or false) ||
77+ (f.brotli_2_5_0.seccomp or false);
78+ }) [ alloc_no_stdlib_1_3_0_features brotli_decompressor_1_3_1_features ];
79+ brotli_decompressor_1_3_1 = { features?(brotli_decompressor_1_3_1_features {}) }: brotli_decompressor_1_3_1_ {
80+ dependencies = mapFeatures features ([ alloc_no_stdlib_1_3_0 ]);
81+ features = mkFeatures (features.brotli_decompressor_1_3_1 or {});
82+ };
83+ brotli_decompressor_1_3_1_features = f: updateFeatures f (rec {
84+ alloc_no_stdlib_1_3_0."no-stdlib" =
85+ (f.alloc_no_stdlib_1_3_0."no-stdlib" or false) ||
86+ (brotli_decompressor_1_3_1."no-stdlib" or false) ||
87+ (f.brotli_decompressor_1_3_1."no-stdlib" or false);
88+ alloc_no_stdlib_1_3_0.default = true;
89+ alloc_no_stdlib_1_3_0.unsafe =
90+ (f.alloc_no_stdlib_1_3_0.unsafe or false) ||
91+ (brotli_decompressor_1_3_1.unsafe or false) ||
92+ (f.brotli_decompressor_1_3_1.unsafe or false);
93+ brotli_decompressor_1_3_1.default = (f.brotli_decompressor_1_3_1.default or true);
94+ }) [ alloc_no_stdlib_1_3_0_features ];
95+}
pkgs/build-support/rust/build-rust-crate/test/default.nix+25−2
@@ -1,4 +1,4 @@
1−{ lib, stdenv, buildRustCrate, runCommand, writeTextFile, symlinkJoin }:
1+{ lib, stdenv, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage }:
22let
33 mkCrate = args: let
44 p = {
@@ -72,7 +72,30 @@ let
7272 crateBinNoPath3 = { crateBin = [{ name = "my-binary5"; }]; src = mkBin "src/bin/main.rs"; };
7373 crateBinNoPath4 = { crateBin = [{ name = "my-binary6"; }]; src = mkBin "src/main.rs";};
7474 };
75− in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases;
75+ brotliCrates = (callPackage ./brotli-crates.nix {});
76+ in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // {
77+ brotliTest = let
78+ pkg = brotliCrates.brotli_2_5_0 {};
79+ in runCommand "run-brotli-test-cmd" {
80+ nativeBuildInputs = [ pkg ];
81+ } ''
82+ ${pkg}/bin/brotli -c ${pkg}/bin/brotli > /dev/null && touch $out
83+ '';
84+ allocNoStdLibTest = let
85+ pkg = brotliCrates.alloc_no_stdlib_1_3_0 {};
86+ in runCommand "run-alloc-no-stdlib-test-cmd" {
87+ nativeBuildInputs = [ pkg ];
88+ } ''
89+ test -e ${pkg}/bin/example && touch $out
90+ '';
91+ brotliDecompressorTest = let
92+ pkg = brotliCrates.brotli_decompressor_1_3_1 {};
93+ in runCommand "run-brotli-decompressor-test-cmd" {
94+ nativeBuildInputs = [ pkg ];
95+ } ''
96+ test -e ${pkg}/bin/brotli-decompressor && touch $out
97+ '';
98+ };
7699 test = runCommand "run-buildRustCrate-tests" {
77100 nativeBuildInputs = builtins.attrValues tests;
78101 } "