nixpkgs/pkgs/build-support/rust/hooks/cargo-check-hook.sh
binarycat 683f97e378 rustPlatform: cargo test is now called with the same environment variables as cargo build
this means that cargo dependancies will no longer be built twice.
2024-10-09 09:42:38 +02:00

55 lines
1.3 KiB
Bash

# shellcheck shell=bash disable=SC2154,SC2164
cargoCheckHook() {
echo "Executing cargoCheckHook"
runHook preCheck
if [[ -n "${buildAndTestSubdir-}" ]]; then
pushd "${buildAndTestSubdir}"
fi
local flagsArray=("-j" "$NIX_BUILD_CORES")
if [[ -z ${dontUseCargoParallelTests-} ]]; then
prependToVar checkFlags "--test-threads=$NIX_BUILD_CORES"
else
prependToVar checkFlags "--test-threads=1"
fi
if [ "${cargoCheckType}" != "debug" ]; then
flagsArray+=("--profile" "${cargoCheckType}")
fi
if [ -n "${cargoCheckNoDefaultFeatures-}" ]; then
flagsArray+=("--no-default-features")
fi
if [ -n "${cargoCheckFeatures-}" ]; then
flagsArray+=("--features=$(concatStringsSep "," cargoCheckFeatures)")
fi
flagsArray+=(
"--target" "@rustHostPlatformSpec@"
"--offline"
)
prependToVar checkFlags "--"
concatTo flagsArray cargoTestFlags checkFlags checkFlagsArray
echoCmd 'cargoCheckHook flags' "${flagsArray[@]}"
@setEnv@ cargo test "${flagsArray[@]}"
if [[ -n "${buildAndTestSubdir-}" ]]; then
popd
fi
echo "Finished cargoCheckHook"
runHook postCheck
}
if [ -z "${dontCargoCheck-}" ] && [ -z "${checkPhase-}" ]; then
checkPhase=cargoCheckHook
fi