Skip to content

Commit

Permalink
Stabilize the strip profile option, now that rustc has stable `-C s…
Browse files Browse the repository at this point in the history
…trip`

rust-lang/rust#90058 stabilized `-Z strip` as
`-C strip`. Stabilize the corresponding Cargo option.

Update the documentation to move it from the unstable reference to the
profiles documentation.

Update the tests to account for stabilization, but make them no-ops on
stable/beta for now until rustc 1.58 releases.
  • Loading branch information
joshtriplett committed Dec 24, 2021
1 parent 47b869c commit 75e544d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@ fn build_base_args(
}

if strip != Strip::None {
cmd.arg("-Z").arg(format!("strip={}", strip));
cmd.arg("-C").arg(format!("strip={}", strip));
}

if unit.is_std {
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ features! {
(stable, resolver, "1.51", "reference/resolver.html#resolver-versions"),

// Allow to specify whether binaries should be stripped.
(unstable, strip, "", "reference/unstable.html#profile-strip-option"),
(stable, strip, "1.58", "reference/profiles.html#strip-option"),

// Specifying a minimal 'rust-version' attribute for crates
(stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"),
Expand Down
4 changes: 0 additions & 4 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,6 @@ impl TomlProfile {
}
}

if self.strip.is_some() {
features.require(Feature::strip())?;
}

if let Some(codegen_backend) = &self.codegen_backend {
features.require(Feature::codegen_backend())?;
if codegen_backend.contains(|c: char| !c.is_ascii_alphanumeric() && c != '_') {
Expand Down
21 changes: 21 additions & 0 deletions src/doc/src/reference/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ once more testing has been performed, and support for DWARF is stabilized.
[nightly channel]: ../../book/appendix-07-nightly-rust.html
[`-C split-debuginfo` flag]: ../../rustc/codegen-options/index.html#split-debuginfo

#### strip

The `strip` option controls the rustc `-C strip` option, which directs rustc to
strip either symbols or debuginfo from a binary. This can be enabled like so:

```toml
[package]
# ...

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

Other possible string values of `strip` are `none`, `symbols`, and `off`. The

This comment has been minimized.

Copy link
@rimutaka

rimutaka Mar 1, 2022

Contributor

It is not clear if debuginfo includes symbols or vice versa or if they are complimentary. I looked up the corresponding compiler setting (https://doc.rust-lang.org/rustc/codegen-options/index.html#strip), but I'm still not sure how they relate to each other. I suspect there will be enough dummies like myself pondering which option to go for to justify a clarification :)

default is `none`.

You can also configure this option with the two absolute boolean values
`true` and `false`. The former enables `strip` at its higher level, `symbols`,
while the latter disables `strip` completely.


#### debug-assertions

The `debug-assertions` setting controls the [`-C debug-assertions` flag] which
Expand Down
27 changes: 5 additions & 22 deletions src/doc/src/reference/unstable.md
Original file line number Diff line number Diff line change
Expand Up @@ -820,28 +820,6 @@ The following is a description of the JSON structure:
}
```

### Profile `strip` option
* Tracking Issue: [rust-lang/rust#72110](https://github.com/rust-lang/rust/issues/72110)

This feature provides a new option in the `[profile]` section to strip either
symbols or debuginfo from a binary. This can be enabled like so:

```toml
cargo-features = ["strip"]

[package]
# ...

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

Other possible string values of `strip` are `none`, `symbols`, and `off`. The default is `none`.

You can also configure this option with the two absolute boolean values
`true` and `false`. The former enables `strip` at its higher level, `symbols`,
while the latter disables `strip` completely.

### rustdoc-map
* Tracking Issue: [#8296](https://github.com/rust-lang/cargo/issues/8296)

Expand Down Expand Up @@ -1387,6 +1365,11 @@ See [`cargo fix --edition`](../commands/cargo-fix.md) and [The Edition Guide](..
Custom named profiles have been stabilized in the 1.57 release. See the
[profiles chapter](profiles.md#custom-profiles) for more information.

### Profile `strip` option

The profile `strip` option has been stabilized in the 1.58 release. See the
[profiles chapter](profiles.md#strip) for more information.

### Future incompat report

Support for generating a future-incompat report has been stabilized
Expand Down
74 changes: 10 additions & 64 deletions tests/testsuite/profiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,16 +472,14 @@ fn thin_lto_works() {
#[cargo_test]
fn strip_works() {
if !is_nightly() {
// -Zstrip is unstable
// rustc 1.58 stabilized -C strip; disable the test until that ships.
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["strip"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -494,73 +492,27 @@ fn strip_works() {
.build();

p.cargo("build --release -v")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -Z strip=symbols [..]`
[RUNNING] `rustc [..] -C strip=symbols [..]`
[FINISHED] [..]
",
)
.run();
}

#[cargo_test]
fn strip_requires_cargo_feature() {
if !is_nightly() {
// -Zstrip is unstable
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[profile.release]
strip = 'symbols'
"#,
)
.file("src/main.rs", "fn main() {}")
.build();

p.cargo("build --release -v")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
Caused by:
feature `strip` is required
The package requires the Cargo feature called `strip`, but that feature is \
not stabilized in this version of Cargo (1.[..]).
Consider adding `cargo-features = [\"strip\"]` to the top of Cargo.toml \
(above the [package] table) to tell Cargo you are opting in to use this unstable feature.
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#profile-strip-option \
for more information about the status of this feature.
",
)
.run();
}

#[cargo_test]
fn strip_passes_unknown_option_to_rustc() {
if !is_nightly() {
// -Zstrip is unstable
// rustc 1.58 stabilized -C strip; disable the test until that ships.
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["strip"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -573,13 +525,12 @@ fn strip_passes_unknown_option_to_rustc() {
.build();

p.cargo("build --release -v")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr_contains(
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -Z strip=unknown [..]`
error: incorrect value `unknown` for debugging option `strip` - either `none`, `debuginfo`, or `symbols` was expected
[RUNNING] `rustc [..] -C strip=unknown [..]`
error: incorrect value `unknown` for [..] `strip` [..] was expected
",
)
.run();
Expand All @@ -588,16 +539,14 @@ error: incorrect value `unknown` for debugging option `strip` - either `none`, `
#[cargo_test]
fn strip_accepts_true_to_strip_symbols() {
if !is_nightly() {
// -Zstrip is unstable
// rustc 1.58 stabilized -C strip; disable the test until that ships.
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["strip"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -610,11 +559,10 @@ fn strip_accepts_true_to_strip_symbols() {
.build();

p.cargo("build --release -v")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -Z strip=symbols [..]`
[RUNNING] `rustc [..] -C strip=symbols [..]`
[FINISHED] [..]
",
)
Expand All @@ -624,15 +572,14 @@ fn strip_accepts_true_to_strip_symbols() {
#[cargo_test]
fn strip_accepts_false_to_disable_strip() {
if !is_nightly() {
// -Zstrip is unstable
// rustc 1.58 stabilized -C strip; disable the test until that ships.
return;
}

let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["strip"]
[package]
name = "foo"
version = "0.1.0"
Expand All @@ -645,7 +592,6 @@ fn strip_accepts_false_to_disable_strip() {
.build();

p.cargo("build --release -v")
.masquerade_as_nightly_cargo()
.with_stderr_does_not_contain("-Z strip")
.with_stderr_does_not_contain("-C strip")
.run();
}

0 comments on commit 75e544d

Please sign in to comment.