2024-08-24 21:41:25 +00:00
|
|
|
# shellcheck shell=bash disable=SC2154,SC2164
|
|
|
|
|
2021-02-11 16:32:47 +00:00
|
|
|
cargoBuildHook() {
|
|
|
|
echo "Executing cargoBuildHook"
|
|
|
|
|
|
|
|
runHook preBuild
|
|
|
|
|
2023-06-07 17:42:06 +00:00
|
|
|
# Let stdenv handle stripping, for consistency and to not break
|
|
|
|
# separateDebugInfo.
|
|
|
|
export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
|
|
|
|
|
2024-08-24 21:41:25 +00:00
|
|
|
if [ -n "${buildAndTestSubdir-}" ]; then
|
2021-12-26 08:02:26 +00:00
|
|
|
# ensure the output doesn't end up in the subdirectory
|
2024-08-24 21:41:25 +00:00
|
|
|
CARGO_TARGET_DIR="$(pwd)/target"
|
|
|
|
export CARGO_TARGET_DIR
|
2021-12-26 08:02:26 +00:00
|
|
|
|
2021-02-11 16:32:47 +00:00
|
|
|
pushd "${buildAndTestSubdir}"
|
|
|
|
fi
|
|
|
|
|
2024-08-24 21:27:19 +00:00
|
|
|
local flagsArray=(
|
|
|
|
"-j" "$NIX_BUILD_CORES"
|
|
|
|
"--target" "@rustHostPlatformSpec@"
|
|
|
|
"--offline"
|
|
|
|
)
|
|
|
|
|
2021-03-03 18:09:04 +00:00
|
|
|
if [ "${cargoBuildType}" != "debug" ]; then
|
2024-08-24 21:27:19 +00:00
|
|
|
flagsArray+=("--profile" "${cargoBuildType}")
|
2021-03-03 18:09:04 +00:00
|
|
|
fi
|
|
|
|
|
2021-10-27 02:41:37 +00:00
|
|
|
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
|
2024-08-24 21:27:19 +00:00
|
|
|
flagsArray+=("--no-default-features")
|
2021-10-27 02:41:37 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${cargoBuildFeatures-}" ]; then
|
2024-08-24 21:27:19 +00:00
|
|
|
flagsArray+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
|
2021-10-27 02:41:37 +00:00
|
|
|
fi
|
|
|
|
|
2024-08-24 21:27:19 +00:00
|
|
|
concatTo flagsArray cargoBuildFlags
|
|
|
|
|
|
|
|
echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
|
|
|
|
@setEnv@ cargo build "${flagsArray[@]}"
|
2021-02-11 16:32:47 +00:00
|
|
|
|
2024-08-24 21:41:25 +00:00
|
|
|
if [ -n "${buildAndTestSubdir-}" ]; then
|
2021-02-11 16:32:47 +00:00
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2021-02-15 05:54:18 +00:00
|
|
|
runHook postBuild
|
|
|
|
|
2021-02-11 16:32:47 +00:00
|
|
|
echo "Finished cargoBuildHook"
|
|
|
|
}
|
|
|
|
|
2021-03-01 01:18:12 +00:00
|
|
|
if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
|
|
|
buildPhase=cargoBuildHook
|
|
|
|
fi
|