crane/pkgs/inheritCargoArtifactsHook.sh
Ivan Petkov 64914fbc98
Remove doCompressTarget option
* Reducing the parameter surface area for good measure, zstd compression
  works pretty well and it seems redundant to support multiple ways of
  copying the target directory around
2021-12-30 20:25:33 -08:00

25 lines
888 B
Bash

inheritCargoArtifacts() {
echo cargoArtifacts is ${cargoArtifacts}
local cargoTarget="${CARGO_TARGET_DIR:-target}"
mkdir -p "${cargoTarget}"
if [ -f "${cargoArtifacts}/target.tar.zst" ]; then
@zstd@ -d "${cargoArtifacts}/target.tar.zst" --stdout | \
tar -x -C "${cargoTarget}" --strip-components=1
else
echo "${cargoArtifacts} looks invalid, are you sure it is pointing to a ".target" output?"
false
fi
}
if [ -n "${cargoArtifacts-}" ]; then
# NB: inherit cargo artifacts after patching is done, that way target directory
# is fresher than the source and avoid invalidating the cache
# Doing this as early as possible also gives us the advantage that any other
# preBuild hooks (e.g. clippy) can also take advantage of the cache
postPatchHooks+=(inheritCargoArtifacts)
else
echo "cargoArtifacts not set, will not reuse any cargo artifacts"
fi