You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/3127-trim-paths.md
+20-14Lines changed: 20 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -137,16 +137,17 @@ If `trim-paths` is not `none` or `false`, then the following paths are sanitised
137
137
2. Path to the working directory will be stripped. E.g. `/home/username/crate/src/lib.rs` -> `src/lib.rs`.
138
138
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`
139
139
140
-
Paths requiring sanitisation can be retrieved by build scripts at their execution time from the environment variable `CARGO_TRIM_PATHS`, in comma-separated format.
141
-
If a build script does anything that may result in these, or any other absolute paths, to be included in compilation outputs, such as by invoking a C compiler, then the build script should make sure they are trimmed.
142
-
Cargo's mapping scheme (what Cargo will map these paths to) is not provided in `CARGO_TRIM_PATHS`, and build scripts are free to decide as long as they are reproducible and privacy preserving.
143
-
144
140
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
145
141
is present. If it is, then some paths will point to the copy of the source files on your file system; if it isn't, then they will
146
142
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.
147
143
148
144
This will not affect any hard-coded paths in the source code, such as in strings.
149
145
146
+
### Environment variables Cargo sets for build scripts
147
+
*`CARGO_TRIM_PATHS` - The value of `trim-paths` profile option. If the build script introduces absolute paths to built artefacts (such as
148
+
by invoking a compiler), the user may request them to be sanitised in different types of artefacts. Common paths requiring sanitisation
149
+
include `OUT_DIR` and `CARGO_MANIFEST_DIR`, plus any other introduced by the build script, such as include directories.
@@ -159,9 +160,6 @@ If `trim-paths` is anything else, then its value is supplied directly to `rustc`
159
160
- If the compilation unit is under the working directory, from the the working directory absolute path to empty string.
160
161
If it's outside the working directory, from the absolute path of the package root to `[package name]-[package version]`.
161
162
162
-
If a package in the dependency tree has build scripts, then the absolute path to the package root is supplied by
163
-
the environment variable `CARGO_TRIM_PATHS` when executing build scripts.
164
-
165
163
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.
166
164
167
165
Some interactions with compiler-intrinsic macros need to be considered:
@@ -239,20 +237,28 @@ She can ship her binary like Alice, without worrying about leaking usernames.
239
237
240
238
## Hana needs to compile a C program in their build script
241
239
242
-
They can consult `CARGO_TRIM_PATHS` in their build script to find out which paths need to be sanitised
240
+
They can consult `CARGO_TRIM_PATHS` in their build script to find out paths in what places the user wants sanitised
0 commit comments