Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions tools.nix
Original file line number Diff line number Diff line change
Expand Up @@ -403,32 +403,30 @@ rec {
else parsed.urlFragment;
};

rootCargo = builtins.fromTOML (builtins.readFile "${src}/Cargo.toml");
isWorkspace = rootCargo ? "workspace";
isPackage = rootCargo ? "package";
containedCrates = rootCargo.workspace.members ++ (if isPackage then [ "." ] else [ ]);
allCargoTomls = lib.filter
(lib.hasSuffix "Cargo.toml")
(lib.filesystem.listFilesRecursive src);

getCrateNameFromPath = path:
let
cargoTomlCrate = builtins.fromTOML (builtins.readFile "${src}/${path}/Cargo.toml");
cargoTomlCrate = builtins.fromTOML (builtins.readFile path);
in
cargoTomlCrate.package.name;

pathToExtract =
if isWorkspace then
builtins.head
(builtins.filter
(to_filter:
(getCrateNameFromPath to_filter) == name
)
containedCrates)
else
".";
cargoTomlCrate.package.name or null;

packageCargoToml =
builtins.head
(builtins.filter
(to_filter:
(getCrateNameFromPath to_filter) == name
)
allCargoTomls);

pathToExtract = lib.removeSuffix "Cargo.toml" packageCargoToml;
in
pkgs.runCommand (lib.removeSuffix ".tar.gz" src.name) { }
''
mkdir -p $out
cp -apR ${src}/${pathToExtract}/* $out
cp -apR ${pathToExtract}/* $out
echo '{"package":null,"files":{}}' > $out/.cargo-checksum.json
'';

Expand Down