Skip to content

Commit 23394fc

Browse files
committed
Add object and all as alias scopes
1 parent 2d49c09 commit 23394fc

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

text/3127-trim-paths.md

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -97,19 +97,16 @@ This flag accepts a comma-separated list of values and may be specified multiple
9797
- `unsplit-debuginfo` - apply to remappings to debug information only when they are written to compiled executables or libraries, but not when they are in split files
9898
- `split-debuginfo` - apply remappings to debug information only when they are written to split debug information files, but not in compiled executables or libraries
9999
- `split-debuginfo-file` - apply remappings to the paths pointing to split debug information files. Does nothing when these files are not generated.
100+
- `object` - an alias for `macro,unsplit-debuginfo,split-debuginfo-file`. This ensures all paths in compiled executables or libraries are remapped, but not elsewhere.
101+
- `all` and `true` - an alias for all of the above, also equivalent to supplying `--remap-path-prefix` without this option.
100102

101103
Debug information are written to split files when the separate codegen option `-C split-debuginfo=packed` or `unpacked` (whether by default or explicitly set).
102104

103105
## Cargo
104106

105-
`trim-paths` is a profile setting which controls the sanitisation of file paths in compilation outputs. It has three valid options:
106-
- `none` or `false`: no sanitisation at all
107-
- `object`: sanitise only the paths in emitted executable or library binaries. It always affects paths from macros such as panic messages, and in debug information
108-
only if they will be embedded together with the binary (the default on platforms with ELF binaries, such as Linux and windows-gnu),
109-
but will not touch them if they are in separate files (the default on Windows MSVC and macOS). But the path to these separate files are sanitised.
110-
- `all` or `true`: sanitise paths in all compilation outputs, including compiled executable/library, debug information, and compiler diagnostics.
107+
`trim-paths` is a profile setting which enables and controls the sanitisation of file paths in compilation outputs. It corresponds to the `--remap-path-scope` flag of rustc and accepts all valid scope, or combination of scopes that `--remap-path-scope` accepts, in addition to the `none` or `false` option which disables path sanitisation completely.
111108

112-
The default release profile uses option `object`. You can also manually override it by specifying this option in `Cargo.toml`:
109+
It is defaulted to `none` for debug profiles, and `object` for release profiles. You can manually override it by specifying this option in `Cargo.toml`:
113110
```toml
114111
[profile.dev]
115112
trim-paths = all
@@ -118,7 +115,11 @@ trim-paths = all
118115
trim-paths = none
119116
```
120117

121-
When a path is in scope for sanitisation, it is handled by the following rules:
118+
The default release profile setting (`object`) sanitises only the paths in emitted executable or library files. It always affects paths from macros such as panic messages, and in debug information
119+
only if they will be embedded together with the binary (the default on platforms with ELF binaries, such as Linux and windows-gnu),
120+
but will not touch them if they are in separate files (the default on Windows MSVC and macOS). But the path to these separate files are sanitised.
121+
122+
The following paths are sanitised, if they appear in a covered scope:
122123

123124
1. Path to the source files of the standard and core library (sysroot) will begin with `/rustc/[rustc commit hash]`.
124125
E.g. `/home/username/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs` ->
@@ -130,7 +131,7 @@ When a path to the source files of the standard and core library is *not* in sco
130131
is present. If it is, then the real path pointing to a copy of the source files on your file system will be emitted; if it isn't, then they will
131132
show up as `/rustc/[rustc commit hash]/library/...` (just like when it is selected for sanitisation). Paths to all other source files will not be affected.
132133

133-
This will not affect any hard-coded paths in the source code.
134+
This will not affect any hard-coded paths in the source code, such as in strings.
134135

135136
# Reference-level explanation
136137
[reference-level-explanation]: #reference-level-explanation
@@ -141,19 +142,12 @@ We only need to change the behaviour for `Test` and `Build` compile modes.
141142

142143
If `trim-paths` is `none` (`false`), no extra flag is supplied to `rustc`.
143144

144-
If `trim-paths` is `object` or `all` (`true`), then two `--remap-path-prefix` arguments are supplied to `rustc`:
145+
If `trim-paths` is anything else, then its value is supplied directly to `rustc`'s `--remap-path-scope` option, along with two `--remap-path-prefix` arguments:
145146
- From the path of the local sysroot to `/rustc/[commit hash]`.
146147
- If the compilation unit is under the working directory, from the the working directory absolute path to empty string.
147148
If it's outside the working directory, from the absolute path of the package root to `[package name]-[package version]`.
148149

149-
A further `--remap-path-scope` is also supplied for options `object` and `all`:
150-
151-
If `trim-path` is `object`, then `--remap-path-scope=macro,unsplit-debuginfo,split-debuginfo-file`.
152-
153-
As a result, panic messages (which are always embedded) are sanitised. If debug information is embedded, then they are sanitised; if they are split then they are kept untouched, but the paths to these split files are sanitised.
154-
155-
If `trim-path` is `all` (`true`), all paths will be affected, equivalent to `--remap-path-scope=macro,split-debuginfo,unsplit-debuginfo,diagnostics,split-debuginfo-file` (or not supplying `--remap-path-scope` at all).
156-
150+
The default value of `trim-paths` is `object` for release profile. As a result, panic messages (which are always embedded) are sanitised. If debug information is embedded, then they are sanitised; if they are split then they are kept untouched, but the paths to these split files are sanitised.
157151

158152
Some interactions with compiler-intrinsic macros need to be considered:
159153
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
@@ -259,8 +253,3 @@ or is it a part of the path; if the first `:` supplied belongs to the path then
259253

260254
In any case, future inclusion of this new syntax will not affect `--remap-path-scope` introduced in this RFC. Scopes specified in `--remap-path-scope`
261255
will be used as default for all mappings, and explicit scopes for an individual mapping will take precedence on that mapping.
262-
263-
## Alias for scope options
264-
`--remap-path-scope` can be made to accept additional options that act as aliases for one or more of the existing options. For instance, `--remap-path-scope=debuginfo` can be made equivalent to `--remap-path-scope=split-debuginfo,unsplit-debuginfo`.
265-
266-
Additionally, `none`, `object` and `all` can be made aliases of what Cargo's `trim-paths` option is supposed to provide, such that Cargo's `trim-paths` option can be directly used as the value of `--remap-path-scope`. This allows the user to write `object,split-debuginfo` in `trim-paths` to remap paths in binaries/executables and split debuginfo files, but not in diagnostics.

0 commit comments

Comments
 (0)