Description
This is part of #12137
As of 6982b44, the remap of -Ztrim-paths
is relatively simple. It follows what is described in RFC 3127:
For the the current package (where the current working directory is in), from the the absolute path of the package root to empty string. For other packages, from the absolute path of the package root to
[package name]-[package version]
.
In Cargo, that is:
cargo/src/cargo/core/compiler/mod.rs
Lines 1222 to 1230 in 6982b44
However, this is not ideal for debugger. Several questions emerge in rust-lang/rust#111540 (comment).
- Impossible to manually configure remap for debugger — People need to configure one remap rules per per dependency. That is not possible for people to do it manually for each
<pkg>-<version>/
back to absolute paths. It would require a dedicated tool to restore all the paths. - The same issue also affects path dependency remap. For path dependencies outside the current workspace root, we remap paths to
<pkg>-<version>
as well. - There is no way to distinguish relative path from different Cargo workspace — For path dependencies inside a workspace Cargo currently remaps to paths relative to workspace root. Imagine you have multiple Cargo workspaces and there is one non-Rust root project compiles them together. Now all your debuginfo files are messed up since they were remapped to relative path like
src/some/file.rs
.
Possible options
Registry and git dependencies
Updated as suggested in #13171 (comment)
In rust-lang/rust#111540 (comment), @michaelwoerister brought up a smarter remap strategy. We could remap paths from $CARGO_HOME/registry/src
and $CARGO_HOME/git/checkouts
to a empty string for registry and git dependencies respectively, so that there is a finite set of rule (two exactly) to configure in debugger for each platform. That is to say, cargo could unconditionally pass these to the compiler:
--remap-path-prefix=$CARGO_HOME/.cargo/registry/src=
--remap-path-prefix=$CARGO_HOME/.cargo/git/checkouts=
(or conditionally if we want to reduce number of args passed in to rustc)
That is, example
/home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.193/src/lib.rs
-> index.crates.io-6f17d22bba15001f/serde-1.0.193/src/lib.rs
/home/user/.cargo/git/checkouts/cargo-new-release-57ee03ad5db79cc6/589ded5/src/lib.rs
-> cargo-new-release-57ee03ad5db79cc6/589ded5/src/lib.rs
To restore source paths for debuggers, you only need to set two paths. For example in gdb, set
directory /home/user/.cargo/registry/src
directory /home/user/.cargo/git/checkouts
Path dependencies
For path dependencies, I wonder if we can always remap to relative path to workspace root, regardless whether the package is inside or outside the workspace. Developers should be responsible for locals dependencies, and if they want, they are able to have their own remap rules via --remap-path-prefix
.
Other sources
Vendor and local-registry dependencies
They are both sort of local dependencies. I would suggest treating them as path dependencies. We can always apply new rules to them later on.
Patched dependencies
Just apply all the suggested remap rule above, if not sufficient, people can write their own rule via --remap-path-prefix
.