Skip to content

Commit 5286008

Browse files
committed
Add example usages
1 parent a357827 commit 5286008

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

text/3127-trim-paths.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,74 @@ On macOS and ELF platforms, these paths are introduced by `rustc` during codegen
191191
embedded into the binary by the linker `link.exe`. The linker has a `/PDBALTPATH` option allows us to change the embedded path written to the
192192
binary, which could be supplied by `rustc`
193193

194+
# Usage examples
195+
196+
## Alice wants to ship her binaries, but doesn't want others to see her username
197+
198+
It works out of the box!
199+
200+
```console
201+
Alice$ cargo build --release
202+
```
203+
204+
## Bob wants to profile his program and see the original function names in the report
205+
206+
He needs the debug information emitted and preserved, so he changes his `Cargo.toml` file
207+
208+
```toml
209+
[profile.release]
210+
trim-paths = "none"
211+
debuginfo = 1
212+
```
213+
214+
```console
215+
Bob$ cargo build --release && perf record cargo run --release
216+
```
217+
218+
## Eve wants to symbolicate her users' crash reports from binaries without debug information
219+
220+
She needs to use the `split-debuginfo` feature to produce a separate file containing debug information
221+
222+
```toml
223+
[profile.release]
224+
split-debuginfo = "packed"
225+
debuginfo = 1
226+
```
227+
228+
Again, the default works fine.
229+
230+
```console
231+
Eve$ cargo build --release
232+
```
233+
234+
She can ship her binary like Alice, without worrying about leaking usernames.
235+
236+
## Hana needs to compile a C program in their build script
237+
238+
They can consult `CARGO_TRIM_PATHS` in their build script to find out which paths need to be sanitised
239+
240+
```rust
241+
// in build.rs
242+
243+
let mut gcc = Command::new("gcc");
244+
245+
if let Ok(paths) = std::env::var("CARGO_TRIM_PATHS") {
246+
for to_trim in paths.split(','){
247+
gcc.arg(format!("-ffile-prefix-map={to_trim}=redacted"));
248+
}
249+
}
250+
251+
gcc.args(["-std=c11", "-O2", "-o=lib.o", "lib.c"]);
252+
253+
let output = gcc.output();
254+
255+
//... do stuff
256+
```
257+
258+
```console
259+
Hana$ cargo build --release
260+
```
261+
194262
# Drawbacks
195263
[drawbacks]: #drawbacks
196264

0 commit comments

Comments
 (0)