build-support/rust/buildRustCrate: Search for matching Cargo.toml in sub directories
This is what cargo does for git repositories. See related issues: * https://github.com/kolloch/crate2nix/issues/53 * https://github.com/kolloch/crate2nix/issues/33
This commit is contained in:
@@ -8,6 +8,14 @@ let
|
||||
} // args;
|
||||
in buildRustCrate p;
|
||||
|
||||
mkCargoToml =
|
||||
{ name, crateVersion ? "0.1.0", path ? "Cargo.toml" }:
|
||||
mkFile path ''
|
||||
[package]
|
||||
name = ${builtins.toJSON name}
|
||||
version = ${builtins.toJSON crateVersion}
|
||||
'';
|
||||
|
||||
mkFile = destination: text: writeTextFile {
|
||||
name = "src";
|
||||
destination = "/${destination}";
|
||||
@@ -89,7 +97,7 @@ let
|
||||
in rec {
|
||||
|
||||
tests = let
|
||||
cases = {
|
||||
cases = rec {
|
||||
libPath = { libPath = "src/my_lib.rs"; src = mkLib "src/my_lib.rs"; };
|
||||
srcLib = { src = mkLib "src/lib.rs"; };
|
||||
|
||||
@@ -220,6 +228,40 @@ let
|
||||
];
|
||||
};
|
||||
};
|
||||
rustCargoTomlInSubDir = {
|
||||
# The "workspace_member" can be set to the sub directory with the crate to build.
|
||||
# By default ".", meaning the top level directory is assumed.
|
||||
# Using null will trigger a search.
|
||||
workspace_member = null;
|
||||
src = symlinkJoin rec {
|
||||
name = "find-cargo-toml";
|
||||
paths = [
|
||||
(mkCargoToml { name = "ignoreMe"; })
|
||||
(mkTestFileWithMain "src/main.rs" "ignore_main")
|
||||
|
||||
(mkCargoToml { name = "rustCargoTomlInSubDir"; path = "subdir/Cargo.toml"; })
|
||||
(mkTestFileWithMain "subdir/src/main.rs" "src_main")
|
||||
(mkTestFile "subdir/tests/foo/main.rs" "tests_foo")
|
||||
(mkTestFile "subdir/tests/bar/main.rs" "tests_bar")
|
||||
];
|
||||
};
|
||||
buildTests = true;
|
||||
expectedTestOutputs = [
|
||||
"test src_main ... ok"
|
||||
"test tests_foo ... ok"
|
||||
"test tests_bar ... ok"
|
||||
];
|
||||
};
|
||||
|
||||
rustCargoTomlInTopDir =
|
||||
let
|
||||
withoutCargoTomlSearch = builtins.removeAttrs rustCargoTomlInSubDir [ "workspace_member" ];
|
||||
in
|
||||
withoutCargoTomlSearch // {
|
||||
expectedTestOutputs = [
|
||||
"test ignore_main ... ok"
|
||||
];
|
||||
};
|
||||
};
|
||||
brotliCrates = (callPackage ./brotli-crates.nix {});
|
||||
in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // {
|
||||
|
||||
Reference in New Issue
Block a user