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.
This commit is contained in:
parent
0f95d05548
commit
fc5e595003
@ -2,7 +2,7 @@
|
|||||||
{ crateName,
|
{ crateName,
|
||||||
dependencies,
|
dependencies,
|
||||||
crateFeatures, libName, release, libPath,
|
crateFeatures, libName, release, libPath,
|
||||||
crateType, metadata, crateBin, finalBins,
|
crateType, metadata, crateBin,
|
||||||
extraRustcOpts, verbose, colors }:
|
extraRustcOpts, verbose, colors }:
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -117,11 +117,11 @@
|
|||||||
|
|
||||||
# the first two cases are the "new" default IIRC
|
# the first two cases are the "new" default IIRC
|
||||||
BIN_NAME_=$(echo $BIN_NAME | sed -e 's/-/_/g')
|
BIN_NAME_=$(echo $BIN_NAME | sed -e 's/-/_/g')
|
||||||
FILES=( "src/bin/$BIN_NAME_.rs" "src/bin/$BIN_NAME_/main.rs" "src/bin/main.rs" "src/main.rs" )
|
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" )
|
||||||
|
|
||||||
if ! [ -e "${libPath}" -o -e src/lib.rs -o -e "src/${libName}.rs" ]; then
|
if ! [ -e "${libPath}" -o -e src/lib.rs -o -e "src/${libName}.rs" ]; then
|
||||||
# if this is not a library the following path is also valid
|
# if this is not a library the following path is also valid
|
||||||
FILES=( "src/$BIN_NAME_.rs" "''${FILES[@]}" )
|
FILES=( "src/$BIN_NAME.rs" "src/$BIN_NAME_.rs" "''${FILES[@]}" )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for file in "''${FILES[@]}";
|
for file in "''${FILES[@]}";
|
||||||
@ -153,6 +153,5 @@
|
|||||||
''}
|
''}
|
||||||
# Remove object files to avoid "wrong ELF type"
|
# Remove object files to avoid "wrong ELF type"
|
||||||
find target -type f -name "*.o" -print0 | xargs -0 rm -f
|
find target -type f -name "*.o" -print0 | xargs -0 rm -f
|
||||||
'' + finalBins + ''
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
''
|
''
|
||||||
|
@ -115,8 +115,7 @@ stdenv.mkDerivation (rec {
|
|||||||
|
|
||||||
crateBin = if crate ? crateBin then
|
crateBin = if crate ? crateBin then
|
||||||
builtins.foldl' (bins: bin: let
|
builtins.foldl' (bins: bin: let
|
||||||
_name = (if bin ? name then bin.name else crateName);
|
name = (if bin ? name then bin.name else crateName);
|
||||||
name = lib.strings.replaceStrings ["-"] ["_"] _name;
|
|
||||||
path = if bin ? path then bin.path else "";
|
path = if bin ? path then bin.path else "";
|
||||||
in
|
in
|
||||||
bins + (if bin == "" then "" else ",") + "${name} ${path}"
|
bins + (if bin == "" then "" else ",") + "${name} ${path}"
|
||||||
@ -124,18 +123,6 @@ stdenv.mkDerivation (rec {
|
|||||||
) "" crate.crateBin
|
) "" crate.crateBin
|
||||||
else "";
|
else "";
|
||||||
|
|
||||||
finalBins = if crate ? crateBin then
|
|
||||||
builtins.foldl' (bins: bin:
|
|
||||||
let name = lib.strings.replaceStrings ["-"] ["_"]
|
|
||||||
(if bin ? name then bin.name else crateName);
|
|
||||||
new_name = if bin ? name then bin.name else crateName;
|
|
||||||
in
|
|
||||||
if name == new_name then bins else
|
|
||||||
(bins + "mv target/bin/${name} target/bin/${new_name};")
|
|
||||||
|
|
||||||
) "" crate.crateBin
|
|
||||||
else "";
|
|
||||||
|
|
||||||
build = crate.build or "";
|
build = crate.build or "";
|
||||||
workspace_member = crate.workspace_member or ".";
|
workspace_member = crate.workspace_member or ".";
|
||||||
crateVersion = crate.version;
|
crateVersion = crate.version;
|
||||||
@ -156,7 +143,7 @@ stdenv.mkDerivation (rec {
|
|||||||
buildPhase = buildCrate {
|
buildPhase = buildCrate {
|
||||||
inherit crateName dependencies
|
inherit crateName dependencies
|
||||||
crateFeatures libName release libPath crateType
|
crateFeatures libName release libPath crateType
|
||||||
metadata crateBin finalBins verbose colors
|
metadata crateBin verbose colors
|
||||||
extraRustcOpts;
|
extraRustcOpts;
|
||||||
};
|
};
|
||||||
installPhase = installCrate crateName metadata;
|
installPhase = installCrate crateName metadata;
|
||||||
|
@ -0,0 +1,95 @@
|
|||||||
|
{ lib, buildPlatform, buildRustCrate, fetchgit }:
|
||||||
|
let kernel = buildPlatform.parsed.kernel.name;
|
||||||
|
abi = buildPlatform.parsed.abi.name;
|
||||||
|
include = includedFiles: src: builtins.filterSource (path: type:
|
||||||
|
lib.lists.any (f:
|
||||||
|
let p = toString (src + ("/" + f)); in
|
||||||
|
(path == p) || (type == "directory" && lib.strings.hasPrefix path p)
|
||||||
|
) includedFiles
|
||||||
|
) src;
|
||||||
|
updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
|
||||||
|
mapFeatures = features: map (fun: fun { features = features; });
|
||||||
|
mkFeatures = feat: lib.lists.foldl (features: featureName:
|
||||||
|
if feat.${featureName} or false then
|
||||||
|
[ featureName ] ++ features
|
||||||
|
else
|
||||||
|
features
|
||||||
|
) [] (builtins.attrNames feat);
|
||||||
|
in
|
||||||
|
rec {
|
||||||
|
alloc_no_stdlib_1_3_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
||||||
|
crateName = "alloc-no-stdlib";
|
||||||
|
version = "1.3.0";
|
||||||
|
authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" ];
|
||||||
|
sha256 = "1jcp27pzmqdszgp80y484g4kwbjbg7x8a589drcwbxg0i8xwkir9";
|
||||||
|
crateBin = [ { name = "example"; } ];
|
||||||
|
inherit dependencies buildDependencies features;
|
||||||
|
};
|
||||||
|
brotli_2_5_0_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
||||||
|
crateName = "brotli";
|
||||||
|
version = "2.5.0";
|
||||||
|
authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" "The Brotli Authors" ];
|
||||||
|
sha256 = "1ynw4hkdwnp0kj30p86ls44ahv4s99258s019bqrq4mya8hlsb5b";
|
||||||
|
crateBin = [ { name = "brotli"; } ];
|
||||||
|
inherit dependencies buildDependencies features;
|
||||||
|
};
|
||||||
|
brotli_decompressor_1_3_1_ = { dependencies?[], buildDependencies?[], features?[] }: buildRustCrate {
|
||||||
|
crateName = "brotli-decompressor";
|
||||||
|
version = "1.3.1";
|
||||||
|
authors = [ "Daniel Reiter Horn <danielrh@dropbox.com>" "The Brotli Authors" ];
|
||||||
|
sha256 = "022g69q1xzwdj0130qm3fa4qwpn4q1jx3lc8yz0v0v201p7bm8fb";
|
||||||
|
crateBin = [ { name = "brotli-decompressor"; } ];
|
||||||
|
inherit dependencies buildDependencies features;
|
||||||
|
};
|
||||||
|
alloc_no_stdlib_1_3_0 = { features?(alloc_no_stdlib_1_3_0_features {}) }: alloc_no_stdlib_1_3_0_ {
|
||||||
|
features = mkFeatures (features.alloc_no_stdlib_1_3_0 or {});
|
||||||
|
};
|
||||||
|
alloc_no_stdlib_1_3_0_features = f: updateFeatures f (rec {
|
||||||
|
alloc_no_stdlib_1_3_0.default = (f.alloc_no_stdlib_1_3_0.default or true);
|
||||||
|
}) [];
|
||||||
|
brotli_2_5_0 = { features?(brotli_2_5_0_features {}) }: brotli_2_5_0_ {
|
||||||
|
dependencies = mapFeatures features ([ alloc_no_stdlib_1_3_0 brotli_decompressor_1_3_1 ]);
|
||||||
|
features = mkFeatures (features.brotli_2_5_0 or {});
|
||||||
|
};
|
||||||
|
brotli_2_5_0_features = f: updateFeatures f (rec {
|
||||||
|
alloc_no_stdlib_1_3_0."no-stdlib" =
|
||||||
|
(f.alloc_no_stdlib_1_3_0."no-stdlib" or false) ||
|
||||||
|
(brotli_2_5_0."no-stdlib" or false) ||
|
||||||
|
(f.brotli_2_5_0."no-stdlib" or false);
|
||||||
|
alloc_no_stdlib_1_3_0.default = true;
|
||||||
|
brotli_2_5_0.default = (f.brotli_2_5_0.default or true);
|
||||||
|
brotli_decompressor_1_3_1."disable-timer" =
|
||||||
|
(f.brotli_decompressor_1_3_1."disable-timer" or false) ||
|
||||||
|
(brotli_2_5_0."disable-timer" or false) ||
|
||||||
|
(f.brotli_2_5_0."disable-timer" or false);
|
||||||
|
brotli_decompressor_1_3_1."no-stdlib" =
|
||||||
|
(f.brotli_decompressor_1_3_1."no-stdlib" or false) ||
|
||||||
|
(brotli_2_5_0."no-stdlib" or false) ||
|
||||||
|
(f.brotli_2_5_0."no-stdlib" or false);
|
||||||
|
brotli_decompressor_1_3_1.benchmark =
|
||||||
|
(f.brotli_decompressor_1_3_1.benchmark or false) ||
|
||||||
|
(brotli_2_5_0.benchmark or false) ||
|
||||||
|
(f.brotli_2_5_0.benchmark or false);
|
||||||
|
brotli_decompressor_1_3_1.default = true;
|
||||||
|
brotli_decompressor_1_3_1.seccomp =
|
||||||
|
(f.brotli_decompressor_1_3_1.seccomp or false) ||
|
||||||
|
(brotli_2_5_0.seccomp or false) ||
|
||||||
|
(f.brotli_2_5_0.seccomp or false);
|
||||||
|
}) [ alloc_no_stdlib_1_3_0_features brotli_decompressor_1_3_1_features ];
|
||||||
|
brotli_decompressor_1_3_1 = { features?(brotli_decompressor_1_3_1_features {}) }: brotli_decompressor_1_3_1_ {
|
||||||
|
dependencies = mapFeatures features ([ alloc_no_stdlib_1_3_0 ]);
|
||||||
|
features = mkFeatures (features.brotli_decompressor_1_3_1 or {});
|
||||||
|
};
|
||||||
|
brotli_decompressor_1_3_1_features = f: updateFeatures f (rec {
|
||||||
|
alloc_no_stdlib_1_3_0."no-stdlib" =
|
||||||
|
(f.alloc_no_stdlib_1_3_0."no-stdlib" or false) ||
|
||||||
|
(brotli_decompressor_1_3_1."no-stdlib" or false) ||
|
||||||
|
(f.brotli_decompressor_1_3_1."no-stdlib" or false);
|
||||||
|
alloc_no_stdlib_1_3_0.default = true;
|
||||||
|
alloc_no_stdlib_1_3_0.unsafe =
|
||||||
|
(f.alloc_no_stdlib_1_3_0.unsafe or false) ||
|
||||||
|
(brotli_decompressor_1_3_1.unsafe or false) ||
|
||||||
|
(f.brotli_decompressor_1_3_1.unsafe or false);
|
||||||
|
brotli_decompressor_1_3_1.default = (f.brotli_decompressor_1_3_1.default or true);
|
||||||
|
}) [ alloc_no_stdlib_1_3_0_features ];
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
{ lib, stdenv, buildRustCrate, runCommand, writeTextFile, symlinkJoin }:
|
{ lib, stdenv, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage }:
|
||||||
let
|
let
|
||||||
mkCrate = args: let
|
mkCrate = args: let
|
||||||
p = {
|
p = {
|
||||||
@ -72,7 +72,30 @@ let
|
|||||||
crateBinNoPath3 = { crateBin = [{ name = "my-binary5"; }]; src = mkBin "src/bin/main.rs"; };
|
crateBinNoPath3 = { crateBin = [{ name = "my-binary5"; }]; src = mkBin "src/bin/main.rs"; };
|
||||||
crateBinNoPath4 = { crateBin = [{ name = "my-binary6"; }]; src = mkBin "src/main.rs";};
|
crateBinNoPath4 = { crateBin = [{ name = "my-binary6"; }]; src = mkBin "src/main.rs";};
|
||||||
};
|
};
|
||||||
in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases;
|
brotliCrates = (callPackage ./brotli-crates.nix {});
|
||||||
|
in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // {
|
||||||
|
brotliTest = let
|
||||||
|
pkg = brotliCrates.brotli_2_5_0 {};
|
||||||
|
in runCommand "run-brotli-test-cmd" {
|
||||||
|
nativeBuildInputs = [ pkg ];
|
||||||
|
} ''
|
||||||
|
${pkg}/bin/brotli -c ${pkg}/bin/brotli > /dev/null && touch $out
|
||||||
|
'';
|
||||||
|
allocNoStdLibTest = let
|
||||||
|
pkg = brotliCrates.alloc_no_stdlib_1_3_0 {};
|
||||||
|
in runCommand "run-alloc-no-stdlib-test-cmd" {
|
||||||
|
nativeBuildInputs = [ pkg ];
|
||||||
|
} ''
|
||||||
|
test -e ${pkg}/bin/example && touch $out
|
||||||
|
'';
|
||||||
|
brotliDecompressorTest = let
|
||||||
|
pkg = brotliCrates.brotli_decompressor_1_3_1 {};
|
||||||
|
in runCommand "run-brotli-decompressor-test-cmd" {
|
||||||
|
nativeBuildInputs = [ pkg ];
|
||||||
|
} ''
|
||||||
|
test -e ${pkg}/bin/brotli-decompressor && touch $out
|
||||||
|
'';
|
||||||
|
};
|
||||||
test = runCommand "run-buildRustCrate-tests" {
|
test = runCommand "run-buildRustCrate-tests" {
|
||||||
nativeBuildInputs = builtins.attrValues tests;
|
nativeBuildInputs = builtins.attrValues tests;
|
||||||
} "
|
} "
|
||||||
|
Loading…
x
Reference in New Issue
Block a user