nixpkgs/pkgs/build-support/rust/hooks/cargo-build-hook.sh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
Bash
Raw Normal View History

2024-08-24 21:41:25 +00:00
# shellcheck shell=bash disable=SC2154,SC2164
cargoBuildHook() {
echo "Executing cargoBuildHook"
runHook preBuild
# 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
# 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
pushd "${buildAndTestSubdir}"
fi
local flagsArray=(
"-j" "$NIX_BUILD_CORES"
"--target" "@rustHostPlatformSpec@"
"--offline"
)
if [ "${cargoBuildType}" != "debug" ]; then
flagsArray+=("--profile" "${cargoBuildType}")
fi
2021-10-27 02:41:37 +00:00
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
flagsArray+=("--no-default-features")
2021-10-27 02:41:37 +00:00
fi
if [ -n "${cargoBuildFeatures-}" ]; then
flagsArray+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
2021-10-27 02:41:37 +00:00
fi
concatTo flagsArray cargoBuildFlags
echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
@setEnv@ cargo build "${flagsArray[@]}"
2024-08-24 21:41:25 +00:00
if [ -n "${buildAndTestSubdir-}" ]; then
popd
fi
runHook postBuild
echo "Finished cargoBuildHook"
}
if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=cargoBuildHook
fi