Skip to content

Commit 2bd2792

Browse files
committed
Rename flag to --remap-path-scope and typo fixes
1 parent f92a321 commit 2bd2792

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

text/3127-trim-paths.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ the separate debug symbols file (depending on `split-debuginfo` settings).
1313
`cargo build` with the default `release` profile should not produce any host filesystem dependent paths into binary executable or library. But
1414
it will retain the paths in separate debug symbols file, if one exists, to help debuggers and profilers locate the source files.
1515

16-
To facilitate this, a new flag named `--remap-scope` should be added to `rustc` controlling the behaviour of `--remap-path-prefix`, allowing us to fine
17-
tune the scope of remapping, speicifying paths under which context (in macro expansion, in debuginfo or in diagnostics)
18-
should or shouldn't be remapped.
16+
To facilitate this, a new flag named `--remap-path-scope` should be added to `rustc` controlling the behaviour of `--remap-path-prefix`, allowing us to fine
17+
tune the scope of remapping, specifying paths under which context (in macro expansion, in debuginfo or in diagnostics)
18+
should or shouldn't be remapped.
1919

2020
# Motivation
2121
[motivation]: #motivation
@@ -65,10 +65,11 @@ This is undesirable for the following reasons:
6565

6666
1. **Privacy**. `release` binaries may be distributed, and anyone could then see the builder's local OS account username.
6767
Additionally, some CI (such as [GitLab CI](https://docs.gitlab.com/runner/best_practice/#build-directory)) checks out the repo under a path where
68-
it may include things that really aren't meant to be public. Without sanitising the path by default, this may be inadvertently leaked.
68+
non-public information is included. Without sanitising the path by default, this may be inadvertently leaked.
6969
2. **Build reproducibility**. We would like to make it easier to reproduce binary equivalent builds. While it is not required to maintain
70-
reproducibility across different environments, removing environment-sensitive information from the build will increase tolerance on the inevitable
71-
environment differences when trying to verify builds.
70+
reproducibility across different environments, removing environment-sensitive information from the build will increase the tolerance on the
71+
inevitable environment differences. This helps with build verification, as well as producing deterministic builds when using a distributed build
72+
system.
7273

7374
## Handling sysroot paths
7475
At the moment, paths to the source files of standard and core libraries, even when they are present, always begin with a virtual prefix in the form
@@ -86,10 +87,10 @@ should support finer grained control over paths in which contexts should be rema
8687

8788
## The rustc book: Command-line arguments
8889

89-
### `--remap-scope`: configure the scope of path remapping
90+
### `--remap-path-scope`: configure the scope of path remapping
9091

9192
When the `--remap-path-prefix` option is passed to rustc then source path prefixes in all output will be affected.
92-
The `--remap-scope` argument can be used in conjunction with `--remap-path-prefix` to determine paths in which output context should be affected.
93+
The `--remap-path-scope` argument can be used in conjunction with `--remap-path-prefix` to determine paths in which output context should be affected.
9394
This flag accepts a comma-separated list of values and may be specified multiple times. The valid scopes are:
9495

9596
- `macro` - apply remappings to the expansion of `std::file!()` macro. This is where paths in embedded panic messages come from
@@ -119,7 +120,7 @@ When a path is in scope for sanitisation, it is replaced with the following rule
119120
1. Path to the source files of the standard and core library (sysroot) will begin with `/rustc/[rustc commit hash]`.
120121
E.g. `/home/username/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs` ->
121122
`/rustc/fe72845f7bb6a77b9e671e6a4f32fe714962cec4/library/core/src/result.rs`
122-
2. Path to the working directory will be replaced with `.`. E.g. `/home/username/crate/src/lib.rs` -> `./src/lib.rs`.
123+
2. Path to the working directory will be stripped. E.g. `/home/username/crate/src/lib.rs` -> `src/lib.rs`.
123124
3. Path to packages outside of the working directory will be replaced with `[package name]-[version]`. E.g. `/home/username/deps/foo/src/lib.rs` -> `foo-0.1.0/src/lib.rs`
124125

125126
When a path to the source files of the standard and core library is *not* in scope for sanitisation, the emitted path will depend on if `rust-src` component
@@ -137,23 +138,23 @@ We only need to change the behaviour for `Test` and `Build` compile modes.
137138

138139
If `trim-paths` is `0` (`false`), no extra flag is supplied to `rustc`.
139140

140-
If `trip-paths` is `1` or `2` (`true`), then two `--remap-path-prefix` arguments are supplied to `rustc`:
141+
If `trim-paths` is `1` or `2` (`true`), then two `--remap-path-prefix` arguments are supplied to `rustc`:
141142
- From the path of the local sysroot to `/rustc/[commit hash]`.
142-
- If the compilation unit is under the working directory, from the absolute path to the working directory to `.`.
143+
- If the compilation unit is under the working directory, from the the working directory absolute path to empty string.
143144
If it's outside the working directory, from the absolute path of the package root to `[package name]-[package version]`.
144145

145-
A further `--remap-scope` is also supplied for options `1` and `2`:
146+
A further `--remap-path-scope` is also supplied for options `1` and `2`:
146147

147148
If `trim-path` is `1`, then it depends on the setting of `split-debuginfo` (whether the setting is explicitly supplied or from the default)
148-
- If `split-debuginfo` is `off`, then `--remap-scope=macro,debuginfo`.
149-
- If `split-debuginfo` is `packed` or `unpacked`, then `--remap-scope=macro`
149+
- If `split-debuginfo` is `off`, then `--remap-path-scope=macro,debuginfo`.
150+
- If `split-debuginfo` is `packed` or `unpacked`, then `--remap-path-scope=macro`
150151
This is because we always want to remap panic messages as they will always be embedded in executable/library, but we don't need to touch the separate
151152
symbols file
152153

153-
If `trim-path` is `2` (`true`), all paths will be affected, equivalent to `--remap-scope=macro,debuginfo,diagnostics`
154+
If `trim-path` is `2` (`true`), all paths will be affected, equivalent to `--remap-path-scope=macro,debuginfo,diagnostics`
154155

155156

156-
Some interactions with compiler-intrinstic macros need to be considered:
157+
Some interactions with compiler-intrinsic macros need to be considered:
157158
1. Path (of the current file) introduced by [`file!()`](https://doc.rust-lang.org/std/macro.file.html) *will* be remapped. **Things may break** if
158159
the code interacts with its own source file at runtime by using this macro.
159160
2. Path introduced by [`include!()`](https://doc.rust-lang.org/std/macro.include.html) *will* be remapped, given that the included file is under
@@ -172,8 +173,9 @@ only the file name of the .pdb file without the path to it.
172173
The virtualisation of sysroot files to `/rustc/[commit hash]/library/...` was done at compiler bootstraping, specifically when
173174
`remap-debuginfo = true` in `config.toml`. This is done for Rust distribution on all channels.
174175

175-
At `rustc` runtime (i.e. compiling some code), we try to correlate this virtual path to a real path pointing to the file on the local file system
176-
Currently the result is represented internally as if the path was remapped by a `--remap-path-prefix`, from local `rust-src` path to the virtual path.
176+
At `rustc` runtime (i.e. compiling some code), we try to correlate this virtual path to a real path pointing to the file on the local file system.
177+
Currently the result is represented internally as if the path was remapped by a `--remap-path-prefix`, from local `rust-src` path to the virtual
178+
path.
177179
Only the virtual name is ever emitted for metadata or codegen. We want to change this behaviour such that, when `rust-src` source files can be
178180
discovered, the virtual path is discarded and therefore the local path will be embedded, unless there is a `--remap-path-prefix` that causes this
179181
local path to be remapped in the usual way.
@@ -183,7 +185,7 @@ local path to be remapped in the usual way.
183185
[drawbacks]: #drawbacks
184186

185187
The user will not be able to `Ctrl+click` on any paths provided in panic messages or backtraces outside of the working directory. But
186-
there shouldn't be any confusion as the combination of pacakge name and version can be used to pinpoint the file.
188+
there shouldn't be any confusion as the combination of package name and version can be used to pinpoint the file.
187189

188190
As mentioned above, `trim-paths` may break code that relies on `std::file!()` to evaluate to an accessible path to the file. Hence enabling
189191
it by default for release builds may be a technically breaking change. Occurrences of such use should be extremely rare but should be investigated
@@ -200,7 +202,7 @@ Path to sysroot crates are specially handled by `rustc`. Due to this, the behavi
200202
Although good for privacy and reproducibility, some people find it a hinderance for debugging: https://github.com/rust-lang/rust/issues/85463.
201203
Hence the user should be given control on if they want the virtual or local path.
202204

203-
An alternative to `--remap-scope` is to have individual `--remap-path-prefix`-like flags, one each for macro, debuginfo and diagnostics, requiring
205+
An alternative to `--remap-path-scope` is to have individual `--remap-path-prefix`-like flags, one each for macro, debuginfo and diagnostics, requiring
204206
the full mapping to be given for each context. This is similar to what GCC and Clang does as described below, but we have added a third context
205207
for diagnostics. This technically enables for even finer grained control, allowing different paths in different
206208
contexts to be remapped differently. However it will cause the command line to be very verbose under most normal use cases.
@@ -215,7 +217,7 @@ Go does not enable this by default. Since Go does not differ between debug and r
215217
a hassle for debugging. However this is not an issue for Rust as we have separate debug build profile.
216218

217219
GCC and Clang both have a flag equivalent to `--remap-path-prefix`, but they also both have two separate flags one for only macro expansion and
218-
the other for only debuginfo: https://reproducible-builds.org/docs/build-path/. This is the origin of the `--remap-scope` idea.
220+
the other for only debuginfo: https://reproducible-builds.org/docs/build-path/. This is the origin of the `--remap-path-scope` idea.
219221

220222
# Unresolved questions
221223
[unresolved-questions]: #unresolved-questions

0 commit comments

Comments
 (0)