Add copyCargoTargetToOutputHook

This commit is contained in:
Ivan Petkov 2021-12-26 18:06:19 -08:00
parent c2d7d083d5
commit 2d9788eb8b
No known key found for this signature in database
GPG Key ID: BB6F9EFC065832B6
3 changed files with 43 additions and 2 deletions

View File

@ -1,23 +1,38 @@
{ cargo { cargo
, configureCargoCommonVarsHook , configureCargoCommonVarsHook
, configureCargoVendoredDepsHook , configureCargoVendoredDepsHook
, copyCargoTargetToOutputHook
, lib , lib
, stdenv , stdenv
}: }:
args@{ nativeBuildInputs ? [ ], ... }: { doCopyTarget ? true
, doCopyTargetToSeparateOutput ? doCopyTarget
, nativeBuildInputs ? [ ]
, outputs ? [ "out" ]
, ...
}@args:
stdenv.mkDerivation (args // { stdenv.mkDerivation (args // {
inherit
doCopyTarget
doCopyTargetToSeparateOutput;
nativeBuildInputs = nativeBuildInputs ++ [ nativeBuildInputs = nativeBuildInputs ++ [
cargo cargo
configureCargoCommonVarsHook configureCargoCommonVarsHook
configureCargoVendoredDepsHook configureCargoVendoredDepsHook
copyCargoTargetToOutputHook
]; ];
outputs = outputs ++ lib.optional (doCopyTarget && doCopyTargetToSeparateOutput) "target";
buildPhase = '' buildPhase = ''
cargo check --release cargo check --release
''; '';
installPhase = '' installPhase = ''
touch $out runHook preInstall
mkdir -p $out
runHook postInstall
''; '';
}) })

View File

@ -0,0 +1,21 @@
copyCargoTargetToOutput() {
echo "Executing copyCargoTargetToOutput"
trap "echo Finished copyCargoTargetToOutput" RETURN
local target_dir=${CARGO_TARGET_DIR:-target}
if [ "1" != "${doCopyTarget}" ]; then
return
fi
if [ "1" = "${doCopyTargetToSeparateOutput}" ]; then
local dest="${target}"
else
mkdir -p "${out}"
local dest="${out}/target"
fi
mv "${target_dir}" "${dest}"
}
postInstallHooks+=(copyCargoTargetToOutput)

View File

@ -10,4 +10,9 @@
{ {
name = "configureCargoVendoredDepsHook"; name = "configureCargoVendoredDepsHook";
} ./configureCargoVendoredDepsHook.sh; } ./configureCargoVendoredDepsHook.sh;
copyCargoTargetToOutputHook = makeSetupHook
{
name = "copyCargoTargetToOutputHook";
} ./copyCargoTargetToOutputHook.sh;
} }