|
| 1 | +# Remap source paths |
| 2 | + |
| 3 | +`rustc` supports remapping source paths prefixes **as a best effort** in all compiler generated |
| 4 | +output, including compiler diagnostics, debug informations, 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 remapping 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 |
| 31 | + |
| 32 | +On some platforms, the linker (such as `link.exe`) may embed absolute host paths and compiler arguments |
| 33 | +into debug info files (like `.pdb`) independently of rustc. |
| 34 | + |
| 35 | +This currently the case on Apple linkers where the [OSO entries] are not remapped by the compiler and |
| 36 | +needs to be manually remapped with `-oso_prefix`. |
| 37 | + |
| 38 | +The `--remap-path-prefix` option does not affect these linker-generated paths. |
| 39 | + |
| 40 | +### Textual replacement only |
| 41 | + |
| 42 | +The remapping is strictly textual and does not account for different path separator conventions across |
| 43 | +platforms. Care must be taken when specifying prefixes, especially on Windows where both `/` and `\` may |
| 44 | +appear in paths. |
| 45 | + |
| 46 | +### External tools |
| 47 | + |
| 48 | +Paths introduced by external tools or environment variables may not be covered by `--remap-path-prefix` |
| 49 | +unless explicitly accounted for. |
| 50 | + |
| 51 | +For example, generated code introduced by Cargo's build script. |
| 52 | + |
| 53 | +[OSO entries]: https://wiki.dwarfstd.org/Apple%27s_%22Lazy%22_DWARF_Scheme.md |
0 commit comments