nixpkgs/pkgs/build-support/rust/hooks/cargo-install-hook.sh
Nathan Henrie 16f3c7ebcb rustPlatform.buildRustPackage: provide debug symbols on darwin
Currently we cannot debug rust binaries on darwin (via lldb).

The debug symbols seem to be provided by default in a number of files
in `target/debug/deps/*.rcgu.o`. As far as I can tell these have
hardcoded paths referring to the ephemeral build directory. However,
`split-debuginfo=packed` conveniently produces a `.dSYM` file that can
be copied to `$out/bin/` and immediately provide debugging information.

Fixes https://github.com/NixOS/nixpkgs/issues/262131
2024-08-23 13:07:16 -06:00

55 lines
1.5 KiB
Bash

cargoInstallPostBuildHook() {
echo "Executing cargoInstallPostBuildHook"
releaseDir=target/@targetSubdirectory@/$cargoBuildType
tmpDir="${releaseDir}-tmp";
mkdir -p $tmpDir
cp -r ${releaseDir}/* $tmpDir/
bins=$(find $tmpDir \
-maxdepth 1 \
-type f \
-executable ! \( -regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \))
echo "Finished cargoInstallPostBuildHook"
}
cargoInstallHook() {
echo "Executing cargoInstallHook"
runHook preInstall
# rename the output dir to a architecture independent one
releaseDir=target/@targetSubdirectory@/$cargoBuildType
tmpDir="${releaseDir}-tmp";
mapfile -t targets < <(find "$NIX_BUILD_TOP" -type d | grep "${tmpDir}$")
for target in "${targets[@]}"; do
rm -rf "$target/../../${cargoBuildType}"
ln -srf "$target" "$target/../../"
done
mkdir -p $out/bin $out/lib
xargs -r cp -t $out/bin <<< $bins
find $tmpDir \
-maxdepth 1 \
-regex ".*\.\(so.[0-9.]+\|so\|a\|dylib\)" \
-print0 | xargs -r -0 cp -t $out/lib
# If present, copy any .dSYM directories for debugging on darwin
# https://github.com/NixOS/nixpkgs/issues/330036
find "${releaseDir}" -maxdepth 1 -name '*.dSYM' -exec cp -RLt $out/bin/ {} +
rmdir --ignore-fail-on-non-empty $out/lib $out/bin
runHook postInstall
echo "Finished cargoInstallHook"
}
if [ -z "${dontCargoInstall-}" ] && [ -z "${installPhase-}" ]; then
installPhase=cargoInstallHook
postBuildHooks+=(cargoInstallPostBuildHook)
fi