summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/rust/hooks/cargo-check-hook.sh
blob: 55caa8eb796d1c8c6c7cf4f3bb0d3d7f24a4a05e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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")

    export RUST_TEST_THREADS=$NIX_BUILD_CORES
    if [[ ! -z ${dontUseCargoParallelTests-} ]]; then
        RUST_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" "@rustcTargetSpec@"
        "--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