2019-11-25 02:42:45 +00:00
|
|
|
//! Tests for profile overrides (build-override and per-package overrides).
|
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::registry::Package;
|
|
|
|
use cargo_test_support::{basic_lib_manifest, basic_manifest, project};
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-21 20:47:01 +00:00
|
|
|
fn profile_override_basic() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-21 20:47:01 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
authors = []
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = {path = "bar"}
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev]
|
|
|
|
opt-level = 1
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev.package.bar]
|
|
|
|
opt-level = 3
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-21 20:47:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check -v")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr(
|
2023-02-16 02:35:08 +00:00
|
|
|
"[CHECKING] bar [..]
|
2018-04-21 20:47:01 +00:00
|
|
|
[RUNNING] `rustc --crate-name bar [..] -C opt-level=3 [..]`
|
2023-02-16 02:35:08 +00:00
|
|
|
[CHECKING] foo [..]
|
2018-04-21 20:47:01 +00:00
|
|
|
[RUNNING] `rustc --crate-name foo [..] -C opt-level=1 [..]`
|
|
|
|
[FINISHED] dev [optimized + debuginfo] target(s) in [..]",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-04-21 20:47:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-05 23:13:09 +00:00
|
|
|
fn profile_override_warnings() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-21 20:47:01 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = {path = "bar"}
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev.package.bart]
|
|
|
|
opt-level = 3
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev.package.no-suggestion]
|
|
|
|
opt-level = 3
|
2018-05-05 23:13:09 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev.package."bar:1.2.3"]
|
|
|
|
opt-level = 3
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-21 20:47:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2019-12-27 03:59:19 +00:00
|
|
|
p.cargo("build")
|
|
|
|
.with_stderr_contains(
|
2018-04-21 20:47:01 +00:00
|
|
|
"\
|
2022-04-19 21:00:15 +00:00
|
|
|
[WARNING] profile package spec `bar@1.2.3` in profile `dev` \
|
2019-12-27 03:59:19 +00:00
|
|
|
has a version or URL that does not match any of the packages: \
|
|
|
|
bar v0.5.0 ([..]/foo/bar)
|
|
|
|
[WARNING] profile package spec `bart` in profile `dev` did not match any packages
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2019-06-21 18:36:53 +00:00
|
|
|
<tab>Did you mean `bar`?
|
2019-12-27 03:59:19 +00:00
|
|
|
[WARNING] profile package spec `no-suggestion` in profile `dev` did not match any packages
|
2018-04-21 20:47:01 +00:00
|
|
|
[COMPILING] [..]
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-04-21 20:47:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-21 20:47:01 +00:00
|
|
|
fn profile_override_bad_settings() {
|
|
|
|
let bad_values = [
|
|
|
|
(
|
|
|
|
"panic = \"abort\"",
|
2019-10-10 21:39:30 +00:00
|
|
|
"`panic` may not be specified in a `package` profile",
|
2018-04-21 20:47:01 +00:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"lto = true",
|
2019-10-10 21:39:30 +00:00
|
|
|
"`lto` may not be specified in a `package` profile",
|
2018-04-21 20:47:01 +00:00
|
|
|
),
|
|
|
|
(
|
|
|
|
"rpath = true",
|
2019-10-10 21:39:30 +00:00
|
|
|
"`rpath` may not be specified in a `package` profile",
|
|
|
|
),
|
2019-12-27 03:59:19 +00:00
|
|
|
("package = {}", "package-specific profiles cannot be nested"),
|
2018-04-21 20:47:01 +00:00
|
|
|
];
|
2019-03-27 00:53:53 +00:00
|
|
|
for &(snippet, expected) in bad_values.iter() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-21 20:47:01 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
&format!(
|
|
|
|
r#"
|
2020-09-27 00:59:58 +00:00
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[dependencies]
|
|
|
|
bar = {{path = "bar"}}
|
2018-04-21 20:47:01 +00:00
|
|
|
|
2020-09-27 00:59:58 +00:00
|
|
|
[profile.dev.package.bar]
|
|
|
|
{}
|
|
|
|
"#,
|
2018-04-21 20:47:01 +00:00
|
|
|
snippet
|
|
|
|
),
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-04-21 20:47:01 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(format!("Caused by:\n {}", expected))
|
|
|
|
.run();
|
2018-04-21 20:47:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-22 00:21:42 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-04-22 00:21:42 +00:00
|
|
|
fn profile_override_hierarchy() {
|
|
|
|
// Test that the precedence rules are correct for different types.
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-04-22 00:21:42 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["m1", "m2", "m3"]
|
|
|
|
|
|
|
|
[profile.dev]
|
|
|
|
codegen-units = 1
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package.m2]
|
2018-04-22 00:21:42 +00:00
|
|
|
codegen-units = 2
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package."*"]
|
2018-04-22 00:21:42 +00:00
|
|
|
codegen-units = 3
|
|
|
|
|
|
|
|
[profile.dev.build-override]
|
|
|
|
codegen-units = 4
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-04-22 00:21:42 +00:00
|
|
|
// m1
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"m1/Cargo.toml",
|
2018-04-22 00:21:42 +00:00
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "m1"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
m2 = { path = "../m2" }
|
|
|
|
dep = { path = "../../dep" }
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("m1/src/lib.rs", "extern crate m2; extern crate dep;")
|
|
|
|
.file("m1/build.rs", "fn main() {}")
|
2018-04-22 00:21:42 +00:00
|
|
|
// m2
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"m2/Cargo.toml",
|
2018-04-22 00:21:42 +00:00
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "m2"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
m3 = { path = "../m3" }
|
|
|
|
|
|
|
|
[build-dependencies]
|
|
|
|
m3 = { path = "../m3" }
|
|
|
|
dep = { path = "../../dep" }
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("m2/src/lib.rs", "extern crate m3;")
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"m2/build.rs",
|
|
|
|
"extern crate m3; extern crate dep; fn main() {}",
|
|
|
|
)
|
2018-04-22 00:21:42 +00:00
|
|
|
// m3
|
|
|
|
.file("m3/Cargo.toml", &basic_lib_manifest("m3"))
|
|
|
|
.file("m3/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// dep (outside of workspace)
|
2018-08-28 09:20:03 +00:00
|
|
|
let _dep = project()
|
|
|
|
.at("dep")
|
2018-04-22 00:21:42 +00:00
|
|
|
.file("Cargo.toml", &basic_lib_manifest("dep"))
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
// Profiles should be:
|
|
|
|
// m3: 4 (as build.rs dependency)
|
|
|
|
// m3: 1 (as [profile.dev] as workspace member)
|
2019-10-10 21:39:30 +00:00
|
|
|
// dep: 3 (as [profile.dev.package."*"] as non-workspace member)
|
2018-04-22 00:21:42 +00:00
|
|
|
// m1 build.rs: 4 (as [profile.dev.build-override])
|
2019-10-10 21:39:30 +00:00
|
|
|
// m2 build.rs: 2 (as [profile.dev.package.m2])
|
|
|
|
// m2: 2 (as [profile.dev.package.m2])
|
2018-04-22 00:21:42 +00:00
|
|
|
// m1: 1 (as [profile.dev])
|
|
|
|
|
2019-11-15 00:48:41 +00:00
|
|
|
p.cargo("build -v").with_stderr_unordered("\
|
2018-04-22 00:21:42 +00:00
|
|
|
[COMPILING] m3 [..]
|
|
|
|
[COMPILING] dep [..]
|
2020-04-01 18:41:27 +00:00
|
|
|
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=4 [..]
|
|
|
|
[RUNNING] `rustc --crate-name dep [..]dep/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=3 [..]
|
|
|
|
[RUNNING] `rustc --crate-name m3 m3/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
|
|
|
|
[RUNNING] `rustc --crate-name build_script_build m1/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=4 [..]
|
2018-04-22 00:21:42 +00:00
|
|
|
[COMPILING] m2 [..]
|
2020-04-01 18:41:27 +00:00
|
|
|
[RUNNING] `rustc --crate-name build_script_build m2/build.rs [..] --crate-type bin --emit=[..]link[..]-C codegen-units=2 [..]
|
2018-08-02 09:18:48 +00:00
|
|
|
[RUNNING] `[..]/m1-[..]/build-script-build`
|
|
|
|
[RUNNING] `[..]/m2-[..]/build-script-build`
|
2020-04-01 18:41:27 +00:00
|
|
|
[RUNNING] `rustc --crate-name m2 m2/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=2 [..]
|
2018-04-22 00:21:42 +00:00
|
|
|
[COMPILING] m1 [..]
|
2020-04-01 18:41:27 +00:00
|
|
|
[RUNNING] `rustc --crate-name m1 m1/src/lib.rs [..] --crate-type lib --emit=[..]link[..]-C codegen-units=1 [..]
|
2018-04-22 00:21:42 +00:00
|
|
|
[FINISHED] dev [unoptimized + debuginfo] [..]
|
|
|
|
",
|
2018-08-28 09:20:03 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-04-22 00:21:42 +00:00
|
|
|
}
|
2018-05-05 23:13:09 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-05 23:13:09 +00:00
|
|
|
fn profile_override_spec_multiple() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-05-05 23:13:09 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package.bar]
|
2018-05-05 23:13:09 +00:00
|
|
|
opt-level = 3
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package."bar:0.5.0"]
|
2018-05-05 23:13:09 +00:00
|
|
|
opt-level = 3
|
|
|
|
"#,
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
2018-05-05 23:13:09 +00:00
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check -v")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_status(101)
|
|
|
|
.with_stderr_contains(
|
2018-05-05 23:13:09 +00:00
|
|
|
"\
|
2019-10-10 21:39:30 +00:00
|
|
|
[ERROR] multiple package overrides in profile `dev` match package `bar v0.5.0 ([..])`
|
2022-04-19 21:00:15 +00:00
|
|
|
found package specs: bar, bar@0.5.0",
|
2018-12-08 11:19:47 +00:00
|
|
|
)
|
|
|
|
.run();
|
2018-05-05 23:13:09 +00:00
|
|
|
}
|
|
|
|
|
2023-09-01 20:07:05 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn profile_override_spec_with_version() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[profile.dev.package."bar:0.5.0"]
|
|
|
|
codegen-units = 2
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn profile_override_spec_with_partial_version() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar" }
|
|
|
|
|
|
|
|
[profile.dev.package."bar:0.5"]
|
|
|
|
codegen-units = 2
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.file("bar/Cargo.toml", &basic_lib_manifest("bar"))
|
|
|
|
.file("bar/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
2023-09-01 18:30:58 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]bar/src/lib.rs [..] -C codegen-units=2 [..]")
|
2023-09-01 20:07:05 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2018-05-05 23:13:09 +00:00
|
|
|
fn profile_override_spec() {
|
2018-07-20 11:47:47 +00:00
|
|
|
let p = project()
|
2018-05-05 23:13:09 +00:00
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["m1", "m2"]
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package."dep:1.0.0"]
|
2018-05-05 23:13:09 +00:00
|
|
|
codegen-units = 1
|
|
|
|
|
2019-10-10 21:39:30 +00:00
|
|
|
[profile.dev.package."dep:2.0.0"]
|
2018-05-05 23:13:09 +00:00
|
|
|
codegen-units = 2
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-05-05 23:13:09 +00:00
|
|
|
// m1
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"m1/Cargo.toml",
|
2018-05-05 23:13:09 +00:00
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "m1"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = { path = "../../dep1" }
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("m1/src/lib.rs", "extern crate dep;")
|
2018-05-05 23:13:09 +00:00
|
|
|
// m2
|
2018-12-08 11:19:47 +00:00
|
|
|
.file(
|
|
|
|
"m2/Cargo.toml",
|
2018-05-05 23:13:09 +00:00
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "m2"
|
|
|
|
version = "0.0.1"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
dep = {path = "../../dep2" }
|
2018-12-08 11:19:47 +00:00
|
|
|
"#,
|
|
|
|
)
|
2018-07-25 00:30:32 +00:00
|
|
|
.file("m2/src/lib.rs", "extern crate dep;")
|
2018-05-05 23:13:09 +00:00
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
project()
|
|
|
|
.at("dep1")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("dep", "1.0.0"))
|
2018-05-05 23:13:09 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2018-08-28 09:20:03 +00:00
|
|
|
project()
|
|
|
|
.at("dep2")
|
2018-07-24 22:35:01 +00:00
|
|
|
.file("Cargo.toml", &basic_manifest("dep", "2.0.0"))
|
2018-05-05 23:13:09 +00:00
|
|
|
.file("src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check -v")
|
2018-08-28 09:20:03 +00:00
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]dep1/src/lib.rs [..] -C codegen-units=1 [..]")
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]dep2/src/lib.rs [..] -C codegen-units=2 [..]")
|
|
|
|
.run();
|
2018-05-05 23:13:09 +00:00
|
|
|
}
|
2019-04-01 23:03:35 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2019-04-01 23:03:35 +00:00
|
|
|
fn override_proc_macro() {
|
|
|
|
Package::new("shared", "1.0.0").publish();
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
shared = "1.0"
|
|
|
|
pm = {path = "pm"}
|
|
|
|
|
|
|
|
[profile.dev.build-override]
|
|
|
|
codegen-units = 4
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", r#"pm::eat!{}"#)
|
|
|
|
.file(
|
|
|
|
"pm/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "pm"
|
|
|
|
version = "0.1.0"
|
|
|
|
|
|
|
|
[lib]
|
|
|
|
proc-macro = true
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
shared = "1.0"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"pm/src/lib.rs",
|
|
|
|
r#"
|
|
|
|
extern crate proc_macro;
|
|
|
|
use proc_macro::TokenStream;
|
|
|
|
|
|
|
|
#[proc_macro]
|
|
|
|
pub fn eat(_item: TokenStream) -> TokenStream {
|
|
|
|
"".parse().unwrap()
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check -v")
|
2019-04-01 23:03:35 +00:00
|
|
|
// Shared built for the proc-macro.
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]--crate-name shared [..]-C codegen-units=4[..]")
|
|
|
|
// Shared built for the library.
|
|
|
|
.with_stderr_line_without(
|
|
|
|
&["[RUNNING] `rustc --crate-name shared"],
|
|
|
|
&["-C codegen-units"],
|
|
|
|
)
|
|
|
|
.with_stderr_contains("[RUNNING] `rustc [..]--crate-name pm [..]-C codegen-units=4[..]")
|
|
|
|
.with_stderr_line_without(
|
|
|
|
&["[RUNNING] `rustc [..]--crate-name foo"],
|
|
|
|
&["-C codegen-units"],
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2019-10-10 21:39:30 +00:00
|
|
|
|
2019-10-23 18:24:24 +00:00
|
|
|
#[cargo_test]
|
|
|
|
fn no_warning_ws() {
|
|
|
|
// https://github.com/rust-lang/cargo/issues/7378, avoid warnings in a workspace.
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["a", "b"]
|
|
|
|
|
|
|
|
[profile.dev.package.a]
|
|
|
|
codegen-units = 3
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
|
|
|
|
.file("a/src/lib.rs", "")
|
|
|
|
.file("b/Cargo.toml", &basic_manifest("b", "0.1.0"))
|
|
|
|
.file("b/src/lib.rs", "")
|
|
|
|
.build();
|
|
|
|
|
2023-02-16 02:35:08 +00:00
|
|
|
p.cargo("check -p b")
|
2019-10-23 18:24:24 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
2023-02-16 02:35:08 +00:00
|
|
|
[CHECKING] b [..]
|
2019-10-23 18:24:24 +00:00
|
|
|
[FINISHED] [..]
|
|
|
|
",
|
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
2020-02-01 19:38:05 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn build_override_shared() {
|
|
|
|
// A dependency with a build script that is shared with a build
|
|
|
|
// dependency, using different profile settings. That is:
|
|
|
|
//
|
|
|
|
// foo DEBUG=2
|
|
|
|
// ├── common DEBUG=2
|
|
|
|
// │ └── common Run build.rs DEBUG=2
|
|
|
|
// │ └── common build.rs DEBUG=0 (build_override)
|
|
|
|
// └── foo Run build.rs DEBUG=2
|
|
|
|
// └── foo build.rs DEBUG=0 (build_override)
|
|
|
|
// └── common DEBUG=0 (build_override)
|
|
|
|
// └── common Run build.rs DEBUG=0 (build_override)
|
|
|
|
// └── common build.rs DEBUG=0 (build_override)
|
|
|
|
//
|
|
|
|
// The key part here is that `common` RunCustomBuild is run twice, once
|
|
|
|
// with DEBUG=2 (as a dependency of foo) and once with DEBUG=0 (as a
|
|
|
|
// build-dependency of foo's build script).
|
|
|
|
Package::new("common", "1.0.0")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
if std::env::var("DEBUG").unwrap() != "false" {
|
2023-06-11 08:02:03 +00:00
|
|
|
println!("cargo::rustc-cfg=foo_debug");
|
2020-02-01 19:38:05 +00:00
|
|
|
} else {
|
2023-06-11 08:02:03 +00:00
|
|
|
println!("cargo::rustc-cfg=foo_release");
|
2020-02-01 19:38:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
pub fn foo() -> u32 {
|
|
|
|
if cfg!(foo_debug) {
|
|
|
|
assert!(cfg!(debug_assertions));
|
|
|
|
1
|
|
|
|
} else if cfg!(foo_release) {
|
|
|
|
assert!(!cfg!(debug_assertions));
|
|
|
|
2
|
|
|
|
} else {
|
|
|
|
panic!("not set");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.publish();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2018"
|
|
|
|
|
|
|
|
[build-dependencies]
|
|
|
|
common = "1.0"
|
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
common = "1.0"
|
|
|
|
|
|
|
|
[profile.dev.build-override]
|
|
|
|
debug = 0
|
|
|
|
debug-assertions = false
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(common::foo(), 2);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/main.rs",
|
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
assert_eq!(common::foo(), 1);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("run").run();
|
|
|
|
}
|