2024-01-28 22:08:44 +03:00
|
|
|
{ lib
|
|
|
|
, pkgsBuildBuild
|
2022-02-08 07:03:12 +03:00
|
|
|
}:
|
|
|
|
|
2024-01-28 22:08:44 +03:00
|
|
|
let
|
|
|
|
inherit (pkgsBuildBuild)
|
|
|
|
cargo
|
|
|
|
fetchgit
|
|
|
|
jq
|
|
|
|
runCommand;
|
|
|
|
|
|
|
|
craneUtils = pkgsBuildBuild.callPackage ../pkgs/crane-utils { };
|
|
|
|
in
|
2022-02-11 07:32:31 +03:00
|
|
|
{ git
|
2022-02-08 07:03:12 +03:00
|
|
|
, rev
|
2022-02-19 04:46:05 +03:00
|
|
|
, ref ? null
|
2023-09-22 07:08:53 +03:00
|
|
|
, sha256 ? null
|
2022-02-19 04:46:05 +03:00
|
|
|
, allRefs ? ref == null
|
2022-10-24 02:20:22 +03:00
|
|
|
}:
|
2022-02-08 07:03:12 +03:00
|
|
|
let
|
2022-02-19 04:46:05 +03:00
|
|
|
maybeRef = lib.optionalAttrs (ref != null) { inherit ref; };
|
2023-09-22 07:08:53 +03:00
|
|
|
repo =
|
|
|
|
if sha256 == null then
|
|
|
|
builtins.fetchGit
|
|
|
|
(maybeRef // {
|
|
|
|
inherit allRefs rev;
|
|
|
|
url = git;
|
|
|
|
submodules = true;
|
|
|
|
})
|
|
|
|
else
|
|
|
|
fetchgit {
|
|
|
|
inherit rev sha256;
|
|
|
|
url = git;
|
|
|
|
fetchSubmodules = true;
|
|
|
|
};
|
2022-02-11 07:32:31 +03:00
|
|
|
|
|
|
|
deps = {
|
|
|
|
nativeBuildInputs = [
|
|
|
|
cargo
|
2023-01-22 03:46:32 +03:00
|
|
|
craneUtils
|
2022-02-11 07:32:31 +03:00
|
|
|
jq
|
|
|
|
];
|
|
|
|
};
|
2022-02-08 07:03:12 +03:00
|
|
|
in
|
2023-09-04 03:33:25 +03:00
|
|
|
runCommand "cargo-git" deps ''
|
2022-02-11 07:32:31 +03:00
|
|
|
mkdir -p $out
|
2024-01-28 22:22:09 +03:00
|
|
|
declare -A existing_crates
|
2022-02-11 07:32:31 +03:00
|
|
|
while read -r cargoToml; do
|
2023-01-22 03:46:32 +03:00
|
|
|
local crate=$(
|
|
|
|
cargo metadata --format-version 1 --no-deps --manifest-path "$cargoToml" |
|
|
|
|
jq -r '.packages[] | select(.manifest_path == "'"$cargoToml"'") | "\(.name)-\(.version)"'
|
2022-02-11 07:32:31 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
if [ -n "$crate" ]; then
|
2024-01-28 22:22:09 +03:00
|
|
|
if [[ -n "''${existing_crates["$crate"]}" ]]; then
|
2022-11-10 05:12:34 +03:00
|
|
|
>&2 echo "warning: skipping duplicate package $crate found at $cargoToml"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2022-02-11 07:32:31 +03:00
|
|
|
local dest="$out/$crate"
|
2023-08-12 04:26:37 +03:00
|
|
|
cp -rL "$(dirname "$cargoToml")" "$dest"
|
2022-02-11 07:32:31 +03:00
|
|
|
chmod +w "$dest"
|
|
|
|
echo '{"files":{}, "package":null}' > "$dest/.cargo-checksum.json"
|
2022-11-10 05:12:34 +03:00
|
|
|
|
2023-01-22 03:46:32 +03:00
|
|
|
crane-resolve-workspace-inheritance "$cargoToml" > "$dest/Cargo.toml.resolved" &&
|
|
|
|
mv "$dest/Cargo.toml"{.resolved,}
|
|
|
|
|
2024-01-28 22:22:09 +03:00
|
|
|
existing_crates["$crate"]='1'
|
2022-02-11 07:32:31 +03:00
|
|
|
fi
|
|
|
|
done < <(find ${repo} -name Cargo.toml)
|
2022-02-08 07:03:12 +03:00
|
|
|
''
|