crane/pkgs/copyCargoTargetToOutputHook.sh

26 lines
760 B
Bash
Raw Normal View History

prepareCargoTargetDirAndCopyToDir() {
# Allow for calling with customized parameters
# or fall back to defaults if none are provided
local dir="${1:-${target}}"
local cargoTargetDir="${2:-${CARGO_TARGET_DIR:-target}}"
local dest="${dir}/target.tar.zst"
echo "copying ${cargoTargetDir} to ${dest}"
2021-12-27 05:06:19 +03:00
export SOURCE_DATE_EPOCH=1
mkdir -p "${dir}"
# See: https://reproducible-builds.org/docs/archives/
tar --sort=name \
--mtime="@${SOURCE_DATE_EPOCH}" \
--owner=0 \
--group=0 \
--numeric-owner \
--pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \
-c "${cargoTargetDir}" | @zstd@ -o "${dest}"
2021-12-27 05:06:19 +03:00
}
if [ "1" = "${doCopyTargetToOutput-}" ]; then
postInstallHooks+=(prepareCargoTargetDirAndCopyToDir)
fi