|
| 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**: Paths introduced by external tools or environment |
| 41 | + variables may not be covered by `--remap-path-prefix` unless explicitly accounted for. |
| 42 | + |
| 43 | + For example, generated code introduced by Cargo's build script. |
0 commit comments