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
This commit is contained in:
Nathan Henrie 2024-07-14 09:14:59 -06:00
parent a3836576dd
commit 16f3c7ebcb
2 changed files with 10 additions and 0 deletions

View File

@ -97,6 +97,11 @@ assert useSysroot -> !(args.doCheck or true);
stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "cargoLock" ]) // lib.optionalAttrs useSysroot {
RUSTFLAGS = "--sysroot ${sysroot} " + (args.RUSTFLAGS or "");
} // lib.optionalAttrs (stdenv.isDarwin && buildType == "debug") {
RUSTFLAGS =
"-C split-debuginfo=packed "
+ lib.optionalString useSysroot "--sysroot ${sysroot} "
+ (args.RUSTFLAGS or "");
} // {
inherit buildAndTestSubdir cargoDeps;

View File

@ -36,6 +36,11 @@ cargoInstallHook() {
-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