pytrainer: unpin python 3.10
[NixPkgs.git] / pkgs / build-support / rust / hooks / cargo-build-hook.sh
blob749ebed8b01b7367283c8acb95b168ea6b9c7949
1 # shellcheck shell=bash disable=SC2154,SC2164
3 cargoBuildHook() {
4 echo "Executing cargoBuildHook"
6 runHook preBuild
8 # Let stdenv handle stripping, for consistency and to not break
9 # separateDebugInfo.
10 export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
12 if [ -n "${buildAndTestSubdir-}" ]; then
13 # ensure the output doesn't end up in the subdirectory
14 CARGO_TARGET_DIR="$(pwd)/target"
15 export CARGO_TARGET_DIR
17 pushd "${buildAndTestSubdir}"
20 local flagsArray=(
21 "-j" "$NIX_BUILD_CORES"
22 "--target" "@rustHostPlatformSpec@"
23 "--offline"
26 if [ "${cargoBuildType}" != "debug" ]; then
27 flagsArray+=("--profile" "${cargoBuildType}")
30 if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
31 flagsArray+=("--no-default-features")
34 if [ -n "${cargoBuildFeatures-}" ]; then
35 flagsArray+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
38 concatTo flagsArray cargoBuildFlags
40 echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
41 @setEnv@ cargo build "${flagsArray[@]}"
43 if [ -n "${buildAndTestSubdir-}" ]; then
44 popd
47 runHook postBuild
49 echo "Finished cargoBuildHook"
52 if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
53 buildPhase=cargoBuildHook