nixpkgs/pkgs/build-support/rust/hooks/cargo-build-hook.sh
Alyssa Ross f5d8384094
rustPlatform.cargoBuildHook: don't let cargo strip
This fixes debug info of cloud-hypervisor, which recently added
strip = true to its release profile in Cargo.toml.
2023-06-20 09:51:42 +00:00

59 lines
1.5 KiB
Bash

declare -a cargoBuildFlags
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
if [ "${cargoBuildType}" != "debug" ]; then
cargoBuildProfileFlag="--${cargoBuildType}"
fi
if [ -n "${cargoBuildNoDefaultFeatures-}" ]; then
cargoBuildNoDefaultFeaturesFlag=--no-default-features
fi
if [ -n "${cargoBuildFeatures-}" ]; then
cargoBuildFeaturesFlag="--features=${cargoBuildFeatures// /,}"
fi
(
set -x
env \
"CC_@rustBuildPlatform@=@ccForBuild@" \
"CXX_@rustBuildPlatform@=@cxxForBuild@" \
"CC_@rustTargetPlatform@=@ccForHost@" \
"CXX_@rustTargetPlatform@=@cxxForHost@" \
cargo build -j $NIX_BUILD_CORES \
--target @rustTargetPlatformSpec@ \
--frozen \
${cargoBuildProfileFlag} \
${cargoBuildNoDefaultFeaturesFlag} \
${cargoBuildFeaturesFlag} \
${cargoBuildFlags}
)
if [ ! -z "${buildAndTestSubdir-}" ]; then
popd
fi
runHook postBuild
echo "Finished cargoBuildHook"
}
if [ -z "${dontCargoBuild-}" ] && [ -z "${buildPhase-}" ]; then
buildPhase=cargoBuildHook
fi