Skip to content

Update book: Rust 1.77 changed the default behaviour on debug symbol stripping #13638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/doc/src/reference/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ strip either symbols or debuginfo from a binary. This can be enabled like so:
# ...

[profile.release]
strip = "debuginfo"
strip = "symbols"
```

Possible string values of `strip` are `"none"`, `"debuginfo"`, and `"symbols"`.
The default is `"none"`.
For debug profiles the default is `"none"`, and for profiles with `debug = false`
the default is `"debuginfo"`.

Comment on lines 115 to 122
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust 1.77 changed the default behaviour on debug symbols stripping. That change seems not to be yet updated to the book, which this PR fixes.

I wonder if we need to update the documentation. The idea behind this is to emulate std respecting debug.

You can also configure this option with the boolean values `true` or `false`.
`strip = true` is equivalent to `strip = "symbols"`. `strip = false` is
Expand Down Expand Up @@ -293,7 +294,7 @@ The default settings for the `release` profile are:
opt-level = 3
debug = false
split-debuginfo = '...' # Platform-specific.
strip = "none"
strip = "debuginfo"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems incorrect to me. The default value of strip for release profile is still none.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is strip by default will be equal to none for the release profile if debug is set to false? I read #13677, #13257, #13763, and #13638 but still didn't get it. Thanks in advance!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior of auto-stripping debuginfo is kinda dynamic. The default release profile settings is still static and strip is none when you want to inherit it.

Share these pieces of code for clarity.

fn default_release(trim_paths_enabled: bool) -> Profile {
let trim_paths = trim_paths_enabled.then(|| TomlTrimPathsValue::Object.into());
Profile {
name: InternedString::new("release"),
root: ProfileRoot::Release,
opt_level: InternedString::new("3"),
trim_paths,
..Profile::default()
}
}

impl Default for Profile {
fn default() -> Profile {
Profile {
name: InternedString::new(""),
opt_level: InternedString::new("0"),
root: ProfileRoot::Debug,
lto: Lto::Bool(false),
codegen_backend: None,
codegen_units: None,
debuginfo: DebugInfo::Resolved(TomlDebugInfo::None),
debug_assertions: false,
split_debuginfo: None,
overflow_checks: false,
rpath: false,
incremental: false,
panic: PanicStrategy::Unwind,
strip: Strip::Deferred(StripInner::None),
rustflags: vec![],
trim_paths: None,
}
}
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default release profile settings is still static and strip is none when you want to inherit it.

Hmm.
According to Rust Blog:

Cargo profiles which do not enable debuginfo in outputs (e.g., debug = 0) will enable strip = "debuginfo" by default.

And according to Cargo Book:

[profile.release]
...
debug = false

I made a small test on 1.78.0 and release profile seems indeed have set strip = "debuginfo" by default.
Not sure that behaviour should be, but it seems for me also that documentation is not updated and #13677 make sense.
Or am I missing something here?
Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The settings are static. The actual flags passed to rustc are deferred later when Cargo see if it can safely strip std or not.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is still strip=none if you turn on debug for release profile. strip=debuginfo only happens for release profile when debug is off.

But debug is off by default for the release profile, so strip="debuginfo" will take place, no? 🤔
Not sure I get it correctly, but maybe it would be great to add more context to The Cargo Book.
Thanks for the explanation!

debug-assertions = false
overflow-checks = false
lto = false
Expand Down