Skip to content

Commit e4938cb

Browse files
committed
Improve --remap-path-prefix documentation
1 parent c6a9554 commit e4938cb

File tree

3 files changed

+49
-14
lines changed

3 files changed

+49
-14
lines changed

src/doc/rustc/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [Linker-plugin-based LTO](linker-plugin-lto.md)
2424
- [Checking Conditional Configurations](check-cfg.md)
2525
- [Cargo Specifics](check-cfg/cargo-specifics.md)
26+
- [Remap source paths](remap-source-paths.md)
2627
- [Exploit Mitigations](exploit-mitigations.md)
2728
- [Symbol Mangling](symbol-mangling/index.md)
2829
- [v0 Symbol Format](symbol-mangling/v0.md)

src/doc/rustc/src/command-line-arguments.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,15 @@ This flag takes a number that specifies the width of the terminal in characters.
418418
Formatting of diagnostics will take the width into consideration to make them better fit on the screen.
419419

420420
<a id="option-remap-path-prefix"></a>
421-
## `--remap-path-prefix`: remap source names in output
421+
## `--remap-path-prefix`: remap source paths in output
422422

423423
Remap source path prefixes in all output, including compiler diagnostics,
424-
debug information, macro expansions, etc. It takes a value of the form
425-
`FROM=TO` where a path prefix equal to `FROM` is rewritten to the value `TO`.
426-
The `FROM` may itself contain an `=` symbol, but the `TO` value may not. This
427-
flag may be specified multiple times.
428-
429-
This is useful for normalizing build products, for example by removing the
430-
current directory out of pathnames emitted into the object files. The
431-
replacement is purely textual, with no consideration of the current system's
432-
pathname syntax. For example `--remap-path-prefix foo=bar` will match
433-
`foo/lib.rs` but not `./foo/lib.rs`.
434-
435-
When multiple remappings are given and several of them match, the **last**
436-
matching one is applied.
424+
debug information, macro expansions, etc. It takes a value of the form `FROM=TO`
425+
where a path prefix equal to `FROM` is rewritten to the value `TO`. This flag may be
426+
specified multiple times.
427+
428+
Refer to the [Remap source paths](remap-source-paths.md) of this book for
429+
further details and explanation.
437430

438431
<a id="option-json"></a>
439432
## `--json`: configure json messages printed by the compiler
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Remap source paths
2+
3+
`rustc` supports remaping source paths prefixes *(as a best effort)* in all output, including
4+
compiler diagnostics, debug information, macro expansions, etc.
5+
6+
This is useful for normalizing build products, for example by removing the current directory
7+
out of the paths emitted into the object files.
8+
9+
The remaping is done via the `--remap-path-prefix` option.
10+
11+
## `--remap-path-prefix`
12+
13+
It takes a value of the form `FROM=TO` where a path prefix equal to `FROM` is rewritten
14+
to the value `TO`. `FROM` may itself contain an `=` symbol, but `TO` value may not.
15+
16+
The replacement is purely textual, with no consideration of the current system's path separator.
17+
18+
When multiple remappings are given and several of them match, the **last** matching one is applied.
19+
20+
### Example
21+
22+
```bash
23+
rustc --remap-path-prefix "/home/user/project=/redacted"
24+
```
25+
26+
This example replaces all occurrences of `/home/user/project` in emitted paths with `/redacted`.
27+
28+
## Caveats and Limitations
29+
30+
- **Linkers generated paths**: On some platforms, especially Windows, the linker (such as `link.exe`)
31+
may embed absolute host paths and compiler arguments into debug info files (like `.pdb`) independently
32+
of rustc.
33+
34+
The `--remap-path-prefix` option does not affect these linker-generated paths.
35+
36+
- **Textual replacement only**: The remapping is strictly textual and does not account for different
37+
path separator conventions across platforms. Care must be taken when specifying prefixes, especially
38+
on Windows where both `/` and `\` may appear in paths.
39+
40+
- **External tools and build scripts**: Paths introduced by build scripts, external tools, or environment
41+
variables may not be covered by `--remap-path-prefix` unless explicitly accounted for.

0 commit comments

Comments
 (0)