Skip to content

Commit

Permalink
Document rustc -Zlocation-detail flag (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthagen authored Sep 13, 2023
1 parent 810aa52 commit e413cf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:
working-directory: ${{ matrix.project_dir }}
run: >
rustup component add rust-src;
cargo +nightly build -Z build-std=std,panic_abort --target x86_64-unknown-linux-gnu --release;
RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build -Z build-std=std,panic_abort --target x86_64-unknown-linux-gnu --release;
cargo +nightly build -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort --target x86_64-unknown-linux-gnu --release;
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,22 @@ Enable this in `Cargo.toml`:
panic = "abort"
```

# Remove Location Details

![Minimum Rust: Nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-orange.svg)

By default, Rust includes file, line, and column information for `panic!()` and `[track_caller]`
to provide more useful traceback information. This information requires space in the binary and
thus increases the size of the compiled binaries.

To remove this file, line, and column information, use the unstable
[`rustc` `-Zlocation-detail`](https://github.com/rust-lang/rfcs/blob/master/text/2091-inline-semantic.md#location-detail-control)
flag:

```bash
$ RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build --release
```

# Optimize `libstd` with `build-std`

![Minimum Rust: Nightly](https://img.shields.io/badge/Minimum%20Rust%20Version-nightly-orange.svg)
Expand Down Expand Up @@ -180,7 +196,7 @@ host: x86_64-apple-darwin
# Use that target triple when building with build-std.
# Add the =std,panic_abort to the option to make panic = "abort" Cargo.toml option work.
# See: https://github.com/rust-lang/wg-cargo-std-aware/issues/56
$ cargo +nightly build -Z build-std=std,panic_abort --target x86_64-apple-darwin --release
$ RUSTFLAGS="-Zlocation-detail=none" cargo +nightly build -Z build-std=std,panic_abort --target x86_64-apple-darwin --release
```

On macOS, the final stripped binary size is reduced to 51KB.
Expand Down

0 comments on commit e413cf9

Please sign in to comment.