cargo/tests/testsuite/profiles.rs

715 lines
17 KiB
Rust
Raw Normal View History

2019-11-25 02:42:45 +00:00
//! Tests for profiles.
2015-02-13 04:10:07 +00:00
use std::env;
2022-01-14 18:57:54 +00:00
use cargo_test_support::project;
2022-02-22 18:50:18 +00:00
use cargo_test_support::registry::Package;
#[cargo_test]
fn profile_overrides() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
2020-09-27 00:59:58 +00:00
name = "test"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.dev]
opt-level = 1
debug = false
rpath = true
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] test v0.0.0 ([CWD])
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
--emit=[..]link[..]\
-C opt-level=1[..]\
-C debug-assertions=on \
-C metadata=[..] \
-C rpath \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[FINISHED] dev [optimized] target(s) in [..]
2016-11-06 04:53:21 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn opt_level_override_0() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
2020-09-27 00:59:58 +00:00
name = "test"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.dev]
opt-level = 0
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] test v0.0.0 ([CWD])
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
--emit=[..]link[..]\
-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[FINISHED] [..] target(s) in [..]
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn debug_override_1() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "test"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.dev]
debug = 1
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] test v0.0.0 ([CWD])
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
--emit=[..]link[..]\
-C debuginfo=1 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[FINISHED] [..] target(s) in [..]
2016-11-06 04:53:21 +00:00
",
2018-12-08 11:19:47 +00:00
)
.run();
}
fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
&format!(
r#"
2020-09-27 00:59:58 +00:00
[package]
2020-09-27 00:59:58 +00:00
name = "test"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.dev]
opt-level = {level}
"#,
2018-03-14 15:17:44 +00:00
level = profile_level
),
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] test v0.0.0 ([CWD])
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
--emit=[..]link \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
-C opt-level={level}[..]\
-C debuginfo=2 \
-C debug-assertions=on \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/debug/deps`
[FINISHED] [..] target(s) in [..]
2016-11-06 04:53:21 +00:00
",
2018-03-14 15:17:44 +00:00
level = rustc_level
2018-12-08 11:19:47 +00:00
))
.run();
}
#[cargo_test]
fn opt_level_overrides() {
for &(profile_level, rustc_level) in &[
("1", "1"),
("2", "2"),
("3", "3"),
("\"s\"", "s"),
("\"z\"", "z"),
] {
check_opt_level_override(profile_level, rustc_level)
}
}
#[cargo_test]
fn top_level_overrides_deps() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
2020-09-27 00:59:58 +00:00
name = "test"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.release]
opt-level = 1
debug = true
2020-09-27 00:59:58 +00:00
[dependencies.foo]
path = "foo"
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
2018-03-14 15:17:44 +00:00
.file(
"foo/Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.0.0"
authors = []
2020-09-27 00:59:58 +00:00
[profile.release]
opt-level = 0
debug = false
2020-09-27 00:59:58 +00:00
[lib]
name = "foo"
crate_type = ["dylib", "rlib"]
"#,
2018-12-08 11:19:47 +00:00
)
.file("foo/src/lib.rs", "")
.build();
p.cargo("build -v --release")
.with_stderr(&format!(
2018-03-14 15:17:44 +00:00
"\
[COMPILING] foo v0.0.0 ([CWD]/foo)
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name foo foo/src/lib.rs [..]\
2017-01-03 21:22:58 +00:00
--crate-type dylib --crate-type rlib \
--emit=[..]link \
2017-01-03 21:22:58 +00:00
-C prefer-dynamic \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
-C opt-level=1[..]\
-C debuginfo=2 \
-C metadata=[..] \
--out-dir [CWD]/target/release/deps \
-L dependency=[CWD]/target/release/deps`
[COMPILING] test v0.0.0 ([CWD])
2019-09-25 01:17:36 +00:00
[RUNNING] `rustc --crate-name test src/lib.rs [..]--crate-type lib \
--emit=[..]link \
Add support for `-Cembed-bitcode=no` This commit is the Cargo half of support necessary for rust-lang/rust#70458. Today the compiler emits embedded bytecode in rlibs by default, but compresses it. This is both extraneous disk space and wasted build time for almost all builds, so the PR in question there is changing rustc to have a `-Cembed-bitcode` flag which, when enabled, places the bitcode in the object file rather than an auxiliary file (no extra compression), but also enables `-Cembed-bitcode=no` to disable bitcode emission entirely. This Cargo support changes Cargo to pass `-Cembed-bitcode=no` for almost all compilations. Cargo will keep `lto = true` and such working by not passing this flag (and thus allowing bitcode to get embedded), but by default `cargo build` and `cargo build --release` will no longer have any bitcode in rlibs which should result in speedier builds! Most of the changes here were around the test suite and various assertions about the `rustc` command lines we spit out. One test was hard-disabled until we can get `-Cembed-bitcode=no` into nightly, and then we can make it a nightly-only test. The test will then be stable again once `-Cembed-bitcode=no` hits stable. Note that this is intended to land before the upstream `-Cembed-bitcode` change. The thinking is that we'll land everything in rust-lang/rust all at once so there's no build time regressions for anyone. If we were to land the `-Cembed-bitcode` PR first then there would be a build time regression until we land Cargo changes because rustc would be emitting uncompressed bitcode by default and Cargo wouldn't be turning it off.
2020-04-01 18:41:27 +00:00
-C opt-level=1[..]\
-C debuginfo=2 \
-C metadata=[..] \
--out-dir [..] \
-L dependency=[CWD]/target/release/deps \
--extern foo=[CWD]/target/release/deps/\
{prefix}foo[..]{suffix} \
--extern foo=[CWD]/target/release/deps/libfoo.rlib`
[FINISHED] release [optimized + debuginfo] target(s) in [..]
",
2018-03-14 15:17:44 +00:00
prefix = env::consts::DLL_PREFIX,
suffix = env::consts::DLL_SUFFIX
2018-12-08 11:19:47 +00:00
))
.run();
}
2016-11-02 15:16:44 +00:00
#[cargo_test]
2016-11-02 15:16:44 +00:00
fn profile_in_non_root_manifest_triggers_a_warning() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[project]
name = "foo"
version = "0.1.0"
authors = []
2016-11-02 15:16:44 +00:00
2020-09-27 00:59:58 +00:00
[workspace]
members = ["bar"]
2016-11-02 15:16:44 +00:00
2020-09-27 00:59:58 +00:00
[profile.dev]
debug = false
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/main.rs", "fn main() {}")
2018-03-14 15:17:44 +00:00
.file(
"bar/Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[project]
name = "bar"
version = "0.1.0"
authors = []
workspace = ".."
[profile.dev]
opt-level = 1
"#,
2018-12-08 11:19:47 +00:00
)
.file("bar/src/main.rs", "fn main() {}")
.build();
2016-11-02 15:16:44 +00:00
p.cargo("build -v")
.cwd("bar")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
2016-11-02 15:16:44 +00:00
[WARNING] profiles for the non root package will be ignored, specify profiles at the workspace root:
package: [..]
workspace: [..]
[COMPILING] bar v0.1.0 ([..])
[RUNNING] `rustc [..]`
2018-03-14 15:17:44 +00:00
[FINISHED] dev [unoptimized] target(s) in [..]",
2018-12-08 11:19:47 +00:00
)
.run();
2016-11-02 15:16:44 +00:00
}
#[cargo_test]
2016-11-02 15:16:44 +00:00
fn profile_in_virtual_manifest_works() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[workspace]
members = ["bar"]
2016-11-02 15:16:44 +00:00
2020-09-27 00:59:58 +00:00
[profile.dev]
opt-level = 1
debug = false
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/main.rs", "fn main() {}")
2018-03-14 15:17:44 +00:00
.file(
"bar/Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[project]
name = "bar"
version = "0.1.0"
authors = []
workspace = ".."
"#,
2018-12-08 11:19:47 +00:00
)
.file("bar/src/main.rs", "fn main() {}")
.build();
2016-11-02 15:16:44 +00:00
p.cargo("build -v")
.cwd("bar")
.with_stderr(
2018-03-14 15:17:44 +00:00
"\
2016-11-02 15:16:44 +00:00
[COMPILING] bar v0.1.0 ([..])
[RUNNING] `rustc [..]`
2018-03-14 15:17:44 +00:00
[FINISHED] dev [optimized] target(s) in [..]",
2018-12-08 11:19:47 +00:00
)
.run();
2016-11-02 15:16:44 +00:00
}
2018-04-18 01:46:44 +00:00
#[cargo_test]
fn profile_panic_test_bench() {
let p = project()
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "foo"
version = "0.0.1"
2020-09-27 00:59:58 +00:00
[profile.test]
panic = "abort"
2020-09-27 00:59:58 +00:00
[profile.bench]
panic = "abort"
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build")
.with_stderr_contains(
"\
[WARNING] `panic` setting is ignored for `bench` profile
[WARNING] `panic` setting is ignored for `test` profile
",
2018-12-08 11:19:47 +00:00
)
.run();
}
2018-05-05 15:52:19 +00:00
#[cargo_test]
2018-05-05 15:52:19 +00:00
fn profile_doc_deprecated() {
let p = project()
2018-05-05 15:52:19 +00:00
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "foo"
version = "0.0.1"
2018-05-05 15:52:19 +00:00
2020-09-27 00:59:58 +00:00
[profile.doc]
opt-level = 0
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
2018-05-05 15:52:19 +00:00
.build();
p.cargo("build")
.with_stderr_contains("[WARNING] profile `doc` is deprecated and has no effect")
.run();
2018-05-05 15:52:19 +00:00
}
#[cargo_test]
fn panic_unwind_does_not_build_twice() {
// Check for a bug where `lib` was built twice, once with panic set and
// once without. Since "unwind" is the default, they are the same and
// should only be built once.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[profile.dev]
panic = "unwind"
"#,
)
.file("src/lib.rs", "")
.file("src/main.rs", "fn main() {}")
.file("tests/t1.rs", "")
.build();
p.cargo("test -v --tests --no-run")
.with_stderr_unordered(
"\
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo src/lib.rs [..]--crate-type lib [..]
[RUNNING] `rustc --crate-name foo src/lib.rs [..] --test [..]
[RUNNING] `rustc --crate-name foo src/main.rs [..]--crate-type bin [..]
[RUNNING] `rustc --crate-name foo src/main.rs [..] --test [..]
[RUNNING] `rustc --crate-name t1 tests/t1.rs [..]
[FINISHED] [..]
[EXECUTABLE] `[..]/target/debug/deps/t1-[..][EXE]`
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
[EXECUTABLE] `[..]/target/debug/deps/foo-[..][EXE]`
",
)
.run();
}
#[cargo_test]
fn debug_0_report() {
// The finished line handles 0 correctly.
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[profile.dev]
debug = 0
"#,
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_stderr(
"\
[COMPILING] foo v0.1.0 [..]
[RUNNING] `rustc --crate-name foo src/lib.rs [..]-C debuginfo=0 [..]
[FINISHED] dev [unoptimized] target(s) in [..]
",
)
.run();
}
2019-11-25 02:42:45 +00:00
#[cargo_test]
fn thin_lto_works() {
let p = project()
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[project]
name = "top"
version = "0.5.0"
authors = []
[profile.release]
lto = 'thin'
"#,
2019-11-25 02:42:45 +00:00
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build --release -v")
.with_stderr(
"\
[COMPILING] top [..]
[RUNNING] `rustc [..] -C lto=thin [..]`
[FINISHED] [..]
",
)
.run();
}
2020-05-18 18:57:12 +00:00
#[cargo_test]
fn strip_works() {
let p = project()
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "foo"
version = "0.1.0"
2020-05-18 18:57:12 +00:00
2020-09-27 00:59:58 +00:00
[profile.release]
strip = 'symbols'
"#,
2020-05-18 18:57:12 +00:00
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build --release -v")
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -C strip=symbols [..]`
2020-05-18 18:57:12 +00:00
[FINISHED] [..]
",
)
.run();
}
2020-05-19 18:03:59 +00:00
#[cargo_test]
fn strip_passes_unknown_option_to_rustc() {
2020-05-19 18:03:59 +00:00
let p = project()
.file(
"Cargo.toml",
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "foo"
version = "0.1.0"
2020-05-19 18:03:59 +00:00
2020-09-27 00:59:58 +00:00
[profile.release]
strip = 'unknown'
2020-09-27 00:59:58 +00:00
"#,
2020-05-19 18:03:59 +00:00
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build --release -v")
.with_status(101)
.with_stderr_contains(
2020-05-19 18:03:59 +00:00
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -C strip=unknown [..]`
error: incorrect value `unknown` for [..] `strip` [..] was expected
",
)
.run();
}
2020-05-19 18:03:59 +00:00
#[cargo_test]
fn strip_accepts_true_to_strip_symbols() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[profile.release]
strip = true
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build --release -v")
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc [..] -C strip=symbols [..]`
[FINISHED] [..]
2020-05-19 18:03:59 +00:00
",
)
.run();
}
#[cargo_test]
fn strip_accepts_false_to_disable_strip() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[profile.release]
strip = false
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build --release -v")
.with_stderr_does_not_contain("-C strip")
.run();
}
2021-12-19 03:31:32 +00:00
#[cargo_test]
fn rustflags_works() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["profile-rustflags"]
[profile.dev]
rustflags = ["-C", "link-dead-code=yes"]
[package]
name = "foo"
version = "0.0.1"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build -v")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]
[FINISHED] [..]
",
)
.run();
}
#[cargo_test]
fn rustflags_works_with_env() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["profile-rustflags"]
[package]
name = "foo"
version = "0.0.1"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build -v")
.env("CARGO_PROFILE_DEV_RUSTFLAGS", "-C link-dead-code=yes")
.masquerade_as_nightly_cargo()
.with_stderr(
"\
[COMPILING] foo [..]
[RUNNING] `rustc --crate-name foo [..] -C link-dead-code=yes [..]
[FINISHED] [..]
",
)
.run();
}
#[cargo_test]
fn rustflags_requires_cargo_feature() {
let p = project()
.file(
"Cargo.toml",
r#"
[profile.dev]
rustflags = ["-C", "link-dead-code=yes"]
[package]
name = "foo"
version = "0.0.1"
"#,
)
.file("src/main.rs", "fn main() {}")
.build();
p.cargo("build -v")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
[ERROR] failed to parse manifest at `[CWD]/Cargo.toml`
2022-02-22 18:50:18 +00:00
Caused by:
feature `profile-rustflags` is required
The package requires the Cargo feature called `profile-rustflags`, but that feature is \
not stabilized in this version of Cargo (1.[..]).
Consider adding `cargo-features = [\"profile-rustflags\"]` 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-rustflags-option \
for more information about the status of this feature.
",
)
.run();
Package::new("bar", "1.0.0").publish();
p.change_file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.0.1"
[dependencies]
bar = "1.0"
[profile.dev.package.bar]
rustflags = ["-C", "link-dead-code=yes"]
"#,
);
p.cargo("check")
.masquerade_as_nightly_cargo()
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[ROOT]/foo/Cargo.toml`
2021-12-19 03:31:32 +00:00
Caused by:
feature `profile-rustflags` is required
The package requires the Cargo feature called `profile-rustflags`, but that feature is \
not stabilized in this version of Cargo (1.[..]).
Consider adding `cargo-features = [\"profile-rustflags\"]` 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-rustflags-option \
for more information about the status of this feature.
",
)
.run();
}