Conversation
This stabilizes several parts:
* `profile.<name>.trim-paths = "none" | "object" | "all"`
in both manifest and config
* The remap rules of how Cargo passes `--remap-path-{prefix,scope}`.
The exact remap prefixes still stay unspecified.
* The unremap file `<artifact>.trim-paths.json` (schema v1),
which is emitted beside final artifacts when debuginfo is on.
* `CARGO_TRIM_PATHS_SCOPE` and `CARGO_TRIM_PATHS_REMAP` for build scripts.
This is assumed to be stabilized in 1.101.
No drift. Just move to final locations.
|
|
||
| /// Allow setting trim-paths in a profile to control the sanitisation of file paths in build outputs. | ||
| (unstable, trim_paths, "", "reference/unstable.html#profile-trim-paths-option"), | ||
| (stable, trim_paths, "1.101", "reference/profiles.html#trim-paths"), |
There was a problem hiding this comment.
Aimed at Rust 1.101
|
r? @Muscraft rustbot has assigned @Muscraft. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
|
@weihanglo has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
|
|
||
| ## Default profiles | ||
|
|
||
| ### dev |
There was a problem hiding this comment.
Don't we need to update dev and release?
| [`build.rustflags`]. Note that since Rust 1.55, `RUSTFLAGS` is removed from | ||
| the environment; scripts should use `CARGO_ENCODED_RUSTFLAGS` instead. | ||
| * `CARGO_PKG_<var>` --- The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. | ||
| * `CARGO_TRIM_PATHS_SCOPE` --- The value of the [`trim-paths`] profile option. |
There was a problem hiding this comment.
Not including build-rs on or before stabilization is poor messaging. Including it would also provide an example for those not using it in how to read things.
Stabilization report:
profile.trim-pathsResolves #12137
Resolves rust-lang/rust#111540
RFC: https://rust-lang.github.io/rfcs/3127-trim-paths.html
What is stabilized
The rustc side
--remap-path-scopewas already stabilized in Rust 1.95 via rust-lang/rust#147611This stabilizes the Cargo side:
profile.<name>.trim-paths = "none" | "object" | "all"in both manifest and config
--remap-path-{prefix,scope}.The exact remap prefixes still stay unspecified.
<artifact>.trim-paths.json(schema v1),which is emitted beside final artifacts when debuginfo is on.
CARGO_TRIM_PATHS_SCOPEandCARGO_TRIM_PATHS_REMAPfor build scripts.When this is merged and sync in rust-lang/rust,
we'll also stabilize
rust-gdbandrust-lldbunremap loaders.RUST_GDB_TRIM_PATHS=unstableandRUST_LLDB_TRIM_PATHS=unstableare not needed anymore.See doc for details:
cargo/doc/book/src/reference/unstable.md
Lines 1441 to 1645 in 8814ead
What is not stabilized / included
--remap-path-scopevalues in rustc (macro,diagnostics,debuginfo,coverage),boolean values, and comma-separated list options.
These are removed in fix(trim-paths)!: limit options to
none|object|all#17432.They can come back later when needed.
RFC originall proposed to set
releaseto"object".This is left for future when this is more adopted and battle-tested.
We have loose stability guarantee for changing profile settings anyway.
__CARGO_RUSTC_BOOTSTRAP_WS_REMAP.This stays as an internal thing between rustc bootstrap and cargo
(see feat(trim-paths): honor workspace prefix override from env #17349, fix(trim-paths): custom workspace-relative member paths remap #17366)
documentationscope.This will be integrated in the future incrementally
when those scopes and features are stable.
However, in practice,
rustc bootstrap and debugger depend on the stabilized shape,
so any change needs careful coordination with them.
build-rsAPI for the two build script variables: deferred, non-blocking.Doors closed
.trim-paths.jsonand the v1 schema.CARGO_TRIM_PATHS_SCOPEandCARGO_TRIM_PATHS_REMAP.Post-RFC changes
split-debuginfoscopes,and Cargo followed and stopped caring split debuginfo.
<name>-<version>.In fix(trim-paths): unambiguous and reversible remap rules #17302 we chose workspace members relative remap,
so debuggers resolve workspace sources with zero configuration.
The RFC worried that relative paths only work when running from the right directory,
and symbolication tools need a second process for joining workspace relative paths.
THe unremap file has
workspace_root, so the join is fairly mechanical.Remap prefixes are unspecified anyway,
so we can still change if it turns out not ideal.
for helping debugging find sources,
as well as our keeping remap rules unspecified.
The RFC had no answer about this.
CARGO_TRIM_PATHS_REMAPbuild script env is new.It lets build scripts forward the same rules to C/C++ compilers to flags like
-fmacro-prefix-map.cc-rshas integrated that since feat: inherit path remap rules from cargo trim-paths cc-rs#1794.Feedback
trim-pathsvia bootstrap: leverage cargo trim-paths rust#161049 since 2026-09-02.
This exercises the sysroot remap and the workspace prefix override in rust-lang/rust CI.
cc-rsforwards the remap rules to C/C++ compiler since 1.3.0: https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.3.0Known limitations
This sanitization is best-effort. See
cargo/doc/book/src/reference/unstable.md
Lines 1603 to 1626 in 8814ead
Implementation
History
-Ztrim-pathsCARGO_TRIM_PATHSfor build scriptstrim-pathsfrom different profilesOSOandSOcannot be trimmedbuild.build-dir--remap-path-scopestabilized in 1.95-nightlyCARGO_TRIM_PATHS_REMAPfor build.rs/cargo/depsfallback sourcesnone|object|allTest coverage
"object"with everysplit-debuginfomode"all"diagnostics remapping for rustc and rustdoccargo clean, JSON messages-Zbuild-stdbacktraces show/rustc/<hash>pathsFollow-ups after stabilization
Absolute paths of workspace and
CARGO_HOMEstill get into-Cmetadata/-Cextra-filename/fingerprints.With
trim-paths = "object"we might be able to also trim paths in those places.releasesrc/etc/gdb_trim_paths.pyandsrc/etc/lldb_trim_paths.pybuild-rsaddingCARGO_TRIM_PATHS_SCOPEandCARGO_TRIM_PATHS_REMAPsupport🤖 LLM disclosure: impl history was generated. heading was generated. meats are human-written.