2021-02-15 12:08:06 +01:00
|
|
|
declare -a cargoBuildFlags
|
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
cargoBuildHook() {
|
|
|
|
echo "Executing cargoBuildHook"
|
|
|
|
|
|
|
|
runHook preBuild
|
|
|
|
|
2023-06-07 19:42:06 +02:00
|
|
|
# Let stdenv handle stripping, for consistency and to not break
|
|
|
|
# separateDebugInfo.
|
|
|
|
export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
|
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
2021-12-26 09:02:26 +01:00
|
|
|
# ensure the output doesn't end up in the subdirectory
|
|
|
|
export CARGO_TARGET_DIR="$(pwd)/target"
|
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
pushd "${buildAndTestSubdir}"
|
|
|
|
fi
|
|
|
|
|
2021-03-03 19:09:04 +01:00
|
|
|
if [ "${cargoBuildType}" != "debug" ]; then
|
2023-09-23 20:58:14 +02:00
|
|
|
cargoBuildProfileFlag="--profile ${cargoBuildType}"
|
2021-03-03 19:09:04 +01:00
|
|
|
fi
|
|
|
|
|
2021-10-27 04:41:37 +02:00
|
|
|
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
|
|
|
|
cargoBuildNoDefaultFeaturesFlag=--no-default-features
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "${cargoBuildFeatures-}" ]; then
|
|
|
|
cargoBuildFeaturesFlag="--features=${cargoBuildFeatures// /,}"
|
|
|
|
fi
|
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
(
|
|
|
|
set -x
|
2023-08-06 05:21:02 +02:00
|
|
|
@setEnv@ cargo build -j $NIX_BUILD_CORES \
|
|
|
|
--target @rustHostPlatformSpec@ \
|
2021-02-11 17:32:47 +01:00
|
|
|
--frozen \
|
2021-03-03 19:09:04 +01:00
|
|
|
${cargoBuildProfileFlag} \
|
2021-10-27 04:41:37 +02:00
|
|
|
${cargoBuildNoDefaultFeaturesFlag} \
|
|
|
|
${cargoBuildFeaturesFlag} \
|
2021-02-11 17:32:47 +01:00
|
|
|
${cargoBuildFlags}
|
|
|
|
)
|
|
|
|
|
|
|
|
if [ ! -z "${buildAndTestSubdir-}" ]; then
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
|
2021-02-15 06:54:18 +01:00
|
|
|
runHook postBuild
|
|
|
|
|
2021-02-11 17:32:47 +01:00
|
|
|
echo "Finished cargoBuildHook"
|
|
|
|
}
|
|
|
|
|
2021-03-01 02:18:12 +01:00
|
|
|
if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
|
|
|
|
buildPhase=cargoBuildHook
|
|
|
|
fi
|