Skip to content
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

Stabilize the strip profile option, now that rustc has stable -C strip #10088

Merged
merged 3 commits into from
Jan 4, 2022
Merged
Show file tree
Hide file tree
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
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
22 changes: 22 additions & 0 deletions src/doc/src/reference/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,28 @@ 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 [`-C strip` flag], 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
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.
joshtriplett marked this conversation as resolved.
Show resolved Hide resolved

[`-C strip` flag]: ../../rustc/codegen-options/index.html#strip

#### 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.59 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();
}