Skip to content

Commit d8344ef

Browse files
committed
Use plural
1 parent 97e4104 commit d8344ef

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

text/3127-trim-path.md renamed to text/3127-trim-paths.md

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
- Feature Name: trim-path
1+
- Feature Name: trim-paths
22
- Start Date: 2021-05-24
33
- RFC PR: [rust-lang/rfcs#3127](https://github.com/rust-lang/rfcs/pull/3127)
44
- Rust Issue: N/A
55

66
# Summary
77
[summary]: #summary
88

9-
Cargo should have a [profile setting](https://doc.rust-lang.org/cargo/reference/profiles.html#profile-settings) named `trim-path`
9+
Cargo should have a [profile setting](https://doc.rust-lang.org/cargo/reference/profiles.html#profile-settings) named `trim-paths`
1010
to sanitise absolute paths introduced during compilation that may be embedded in the compilation output. This should be enabled by default for
1111
`release` profile.
1212

@@ -72,17 +72,17 @@ the local paths to show up in panic messages and backtraces.
7272
# Guide-level explanation
7373
[guide-level-explanation]: #guide-level-explanation
7474

75-
`trim-path` is a profile setting which can be set to either `true` or `false`. This is enabled by default when you do a release build,
75+
`trim-paths` is a profile setting which can be set to either `true` or `false`. This is enabled by default when you do a release build,
7676
such as via `cargo build --release`. You can also manually override it by specifying this option in `Cargo.toml`:
7777
```toml
7878
[profile.dev]
79-
trim-path = true
79+
trim-paths = true
8080

8181
[profile.release]
82-
trim-path = false
82+
trim-paths = false
8383
```
8484

85-
With `trim-path` option enabled, the compilation process will not introduce any absolute paths into the build output. Instead, paths containing
85+
With `trim-paths` option enabled, the compilation process will not introduce any absolute paths into the build output. Instead, paths containing
8686
certain prefixes will be replaced with something stable by the following rules:
8787

8888
1. Path to the source files of the standard and core library will begin with `/rustc/[rustc version]`.
@@ -94,18 +94,18 @@ certain prefixes will be replaced with something stable by the following rules:
9494
If using MSVC toolchain, path to the .pdb file containing debug information are be embedded as the file name of the .pdb file only, wihtout any path
9595
information.
9696

97-
With `trim-path` option disabled, the embedding of path to the source files of the standard and core library will depend on if `rust-src` component is present. If it is, then the real path pointing to a copy of the source files on your file system will be embedded; if it isn't, then they will
98-
show up as `/rustc/[rustc version]/library/...` (just like when `trim-path` is enabled). Paths to all other source files will not be affected.
97+
With `trim-paths` option disabled, the embedding of path to the source files of the standard and core library will depend on if `rust-src` component is present. If it is, then the real path pointing to a copy of the source files on your file system will be embedded; if it isn't, then they will
98+
show up as `/rustc/[rustc version]/library/...` (just like when `trim-paths` is enabled). Paths to all other source files will not be affected.
9999

100100
Note that this will not affect any hard-coded paths in the source code.
101101

102102
# Reference-level explanation
103103
[reference-level-explanation]: #reference-level-explanation
104104

105-
## `trim-path` implementation in Cargo
105+
## `trim-paths` implementation in Cargo
106106
We only need to change the behaviour for `Test` and `Build` compile modes.
107107

108-
If `trim-path` is enabled, Cargo will emit two `--remap-path-prefix` arguments to `rustc` for each compilation unit. One mapping is from the path of
108+
If `trim-paths` is enabled, Cargo will emit two `--remap-path-prefix` arguments to `rustc` for each compilation unit. One mapping is from the path of
109109
the local sysroot to `/rustc/[rust version]`. The other mapping depends on if the package containing the compilation unit is under the working
110110
directory. If it is, then the mapping is from the absolute path to the working directory to `.`. If it's outside the working directory, then the
111111
mapping is from the absolute path of the package root to `[package name]-[package version]`.
@@ -118,7 +118,7 @@ Some interactions with compiler-intrinstic macros need to be considered, though
118118
the current working directory or a dependency package.
119119

120120
If the user further supplies custom `--remap-path-prefix` arguments via `RUSTFLAGS` or similar mechanisms, they will take precedence over the one
121-
supplied by `trim-path`. This means that the user-defined `--remap-path-prefix`s must be supplied *after* Cargo's own remapping.
121+
supplied by `trim-paths`. This means that the user-defined `--remap-path-prefix`s must be supplied *after* Cargo's own remapping.
122122

123123
Additionally, when using MSVC linker, Cargo should emit `/PDBALTPATH:%_PDB%` to the linker via `-C link-arg`. This makes the linker embed
124124
only the file name of the .pdb file without the path to it.
@@ -133,21 +133,21 @@ Only the virtual name is ever emitted for metadata or codegen. We want to change
133133
discovered, the virtual path is discarded and therefore will be embedded unless being remapped by `--remap-path-prefix` in the usual way. The relevant part of the code is here:
134134
https://github.com/rust-lang/rust/blob/d8af907491e20339e41d048d6a32b41ddfa91dfe/compiler/rustc_metadata/src/rmeta/decoder.rs#L1637-L1765
135135

136-
We would also like to change the virtualisation of sysroot to `/rustc/[rustc version]/library/...`, instead of the rustc commit hash. This is shorter and more helpful as an identifier, and makes `trim-path` easier to implement: to make the embedded path the same whether or not `rust-src` is installed, we need to emit the same sysroot virutalisation as was done during bootstrapping. Getting the version number is easier than getting the commit hash. The relevant part of the code is here: https://github.com/rust-lang/rust/blob/d8af907491e20339e41d048d6a32b41ddfa91dfe/src/bootstrap/lib.rs#L831-L834
136+
We would also like to change the virtualisation of sysroot to `/rustc/[rustc version]/library/...`, instead of the rustc commit hash. This is shorter and more helpful as an identifier, and makes `trim-paths` easier to implement: to make the embedded path the same whether or not `rust-src` is installed, we need to emit the same sysroot virutalisation as was done during bootstrapping. Getting the version number is easier than getting the commit hash. The relevant part of the code is here: https://github.com/rust-lang/rust/blob/d8af907491e20339e41d048d6a32b41ddfa91dfe/src/bootstrap/lib.rs#L831-L834
137137

138138
# Drawbacks
139139
[drawbacks]: #drawbacks
140140

141-
With `trim-path` enabled, if the `debug` option is simultaneously not `false` (it is turned off by default under `release` profile), paths in
141+
With `trim-paths` enabled, if the `debug` option is simultaneously not `false` (it is turned off by default under `release` profile), paths in
142142
debuginfo will also be remapped. Debuggers will no longer be able to automatically discover and load source files outside of the working directory.
143143
This can be remidated by [debugger features](https://lldb.llvm.org/use/map.html#miscellaneous) remapping the path back to a filesystem path.
144144

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

148-
As mentioned above, `trim-path` may break code that relies on `file!()` to evaluate to an accessible path to the file. Hence enabling
148+
As mentioned above, `trim-paths` may break code that relies on `file!()` to evaluate to an accessible path to the file. Hence enabling
149149
it by default for release builds may be a technically breaking change. Occurances of such use should be extremely rare but should be investigated
150-
via a Crater run. In case this breakage is unacceptable, `trim-path` can be made an opt-in option rather than default in any build profile.
150+
via a Crater run. In case this breakage is unacceptable, `trim-paths` can be made an opt-in option rather than default in any build profile.
151151

152152
# Rationale and alternatives
153153
[rationale-and-alternatives]: #rationale-and-alternatives
@@ -168,7 +168,7 @@ affect sysroot paths at all).
168168
# Prior art
169169
[prior-art]: #prior-art
170170

171-
The name `trim-path` came from the [similar feature](https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies) in Go. An alternative name
171+
The name `trim-paths` came from the [similar feature](https://golang.org/cmd/go/#hdr-Compile_packages_and_dependencies) in Go. An alternative name
172172
`sanitize-paths` was first considered but the spelling of "sanitise" differs across the pond and down under. It is also not as short and concise.
173173

174174
Go does not enable this by default. Since Go does not differ between debug and release builds, removing absolute paths for all build would be
@@ -177,8 +177,6 @@ a hassle for debugging. However this is not an issue for Rust as we have separat
177177
# Unresolved questions
178178
[unresolved-questions]: #unresolved-questions
179179

180-
- Should the option be called `trim-paths` (plural) instead of `trim-path`? Quite a few other option names are plural, such as `debug-assertions`
181-
and `overflow-checks`.
182180
- Should we treat the current working directory the same as other packages? We could have one fewer remapping rule by remapping all
183181
package roots to `[package name]-[version]`. A minor downside to this is not being able to `Ctrl+click` on paths to files the user is working
184182
on from panic messages.

0 commit comments

Comments
 (0)