2021-12-31 05:44:19 +03:00
|
|
|
{ buildDepsOnly
|
|
|
|
, jq
|
|
|
|
}:
|
|
|
|
|
2022-09-28 05:05:06 +03:00
|
|
|
expectedArg: mkDrv: args:
|
2021-12-31 05:44:19 +03:00
|
|
|
let
|
2022-09-28 05:05:06 +03:00
|
|
|
runCargoAndCheckFreshness = cmd: extra:
|
|
|
|
let
|
|
|
|
expected =
|
|
|
|
if builtins.isAttrs expectedArg then
|
|
|
|
expectedArg.${cmd} or ""
|
|
|
|
else
|
|
|
|
expectedArg;
|
|
|
|
in
|
|
|
|
''
|
2022-01-05 01:40:24 +03:00
|
|
|
cargo ${cmd} \
|
|
|
|
--release \
|
|
|
|
--message-format json-diagnostic-short \
|
|
|
|
${extra} \
|
|
|
|
${args.cargoExtraArgs or ""} >${cmd}out
|
2022-11-21 03:28:49 +03:00
|
|
|
|
2021-12-31 05:44:19 +03:00
|
|
|
filter='select(.reason == "compiler-artifact" and .fresh != true) | .target.name'
|
2021-12-31 07:12:52 +03:00
|
|
|
builtTargets="$(jq -r "$filter" <${cmd}out | sort -u)"
|
2022-11-21 03:28:49 +03:00
|
|
|
|
2021-12-31 05:44:19 +03:00
|
|
|
# Make sure only the crate needed building
|
2021-12-31 07:12:52 +03:00
|
|
|
if [[ "${expected}" != "$builtTargets" ]]; then
|
2022-09-28 05:05:06 +03:00
|
|
|
echo for command ${cmd}
|
2021-12-31 07:12:52 +03:00
|
|
|
echo expected \""${expected}"\"
|
|
|
|
echo but got \""$builtTargets"\"
|
2021-12-31 05:44:19 +03:00
|
|
|
false
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in
|
2022-09-20 04:05:43 +03:00
|
|
|
mkDrv (args // {
|
2022-01-09 04:14:05 +03:00
|
|
|
doInstallCargoArtifacts = false;
|
2021-12-31 05:44:19 +03:00
|
|
|
|
2021-12-31 07:12:52 +03:00
|
|
|
# NB: explicit call here so that the buildDepsOnly call
|
|
|
|
# doesn't inherit our build commands
|
2022-09-20 04:05:43 +03:00
|
|
|
cargoArtifacts = buildDepsOnly args;
|
2021-12-31 05:44:19 +03:00
|
|
|
|
|
|
|
nativeBuildInputs = [ jq ];
|
|
|
|
|
|
|
|
buildPhase = ''
|
|
|
|
runHook preBuild
|
|
|
|
|
2022-01-05 01:40:24 +03:00
|
|
|
${runCargoAndCheckFreshness "check" ""}
|
|
|
|
${runCargoAndCheckFreshness "build" ""}
|
2021-12-31 05:44:19 +03:00
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
2022-01-01 04:43:56 +03:00
|
|
|
checkPhase = ''
|
|
|
|
runHook preCheck
|
2021-12-31 05:44:19 +03:00
|
|
|
|
2022-01-05 01:40:24 +03:00
|
|
|
${runCargoAndCheckFreshness "test" "--no-run"}
|
2021-12-31 05:44:19 +03:00
|
|
|
|
2022-01-01 04:43:56 +03:00
|
|
|
runHook postCheck
|
|
|
|
'';
|
2021-12-31 05:44:19 +03:00
|
|
|
|
2022-01-01 04:43:56 +03:00
|
|
|
installPhase = ''
|
|
|
|
touch $out
|
|
|
|
'';
|
2022-01-04 20:28:58 +03:00
|
|
|
})
|