crane/pkgs/installFromCargoArtifactsHook.sh
2021-12-28 17:51:51 -08:00

44 lines
964 B
Bash

installFromCargoArtifactsDir() {
local dir="$1"
local libs=".*\.\(so.[0-9.]+\|so\|a\|dylib\)"
echo "installing artifacts from ${dir}"
find "${dir}" \
-maxdepth 1 \
-regex "${libs}" \
-print0 | xargs -0 -r cp -t "${out}/lib"
find "${dir}" \
-maxdepth 1 \
-type f \
-executable \
! \( -regex "${libs}" \) \
-print0 | xargs -0 -r cp -t "${out}/bin"
}
installFromCargoArtifacts() {
runHook preInstall
echo "Executing cargoInstall"
mkdir -p "${out}/bin"
mkdir -p "${out}/lib"
for profile in release debug; do
local dir="${CARGO_TARGET_DIR:-target}/${profile}"
if [ -d "${dir}" ]; then
installFromCargoArtifactsDir "${dir}"
break
fi
done
rmdir --ignore-fail-on-non-empty "${out}/bin"
rmdir --ignore-fail-on-non-empty "${out}/lib"
runHook postInstall
}
if [ -z "${dontInstallFromCargoArtifacts-}" ] && [ -z "${installPhase-}" ]; then
installPhase=installFromCargoArtifacts
fi