nixpkgs/pkgs/build-support/rust/hooks/cargo-build-hook.sh
Wolfgang Walther 9220a19a4d
rust: support structuredAttrs in setup hooks
Tested the following packages with and without structuredAttrs:
- rust-analyzer: cargo-build-hook, cargo-check-hook
- jujutsu: cargo-nextest-hook
- kornia-rs: maturin-build-hook
2024-09-10 08:32:33 +02:00

52 lines
1.2 KiB
Bash

cargoBuildHook() {
echo "Executing cargoBuildHook"
runHook preBuild
# Let stdenv handle stripping, for consistency and to not break
# separateDebugInfo.
export "CARGO_PROFILE_${cargoBuildType@U}_STRIP"=false
if [ ! -z "${buildAndTestSubdir-}" ]; then
# ensure the output doesn't end up in the subdirectory
export CARGO_TARGET_DIR="$(pwd)/target"
pushd "${buildAndTestSubdir}"
fi
local flagsArray=(
"-j" "$NIX_BUILD_CORES"
"--target" "@rustHostPlatformSpec@"
"--offline"
)
if [ "${cargoBuildType}" != "debug" ]; then
flagsArray+=("--profile" "${cargoBuildType}")
fi
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
flagsArray+=("--no-default-features")
fi
if [ -n "${cargoBuildFeatures-}" ]; then
flagsArray+=("--features=$(concatStringsSep "," cargoBuildFeatures)")
fi
concatTo flagsArray cargoBuildFlags
echoCmd 'cargoBuildHook flags' "${flagsArray[@]}"
@setEnv@ cargo build "${flagsArray[@]}"
if [ ! -z "${buildAndTestSubdir-}" ]; then
popd
fi
runHook postBuild
echo "Finished cargoBuildHook"
}
if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=cargoBuildHook
fi