mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00
Stabilize -Zcheck-cfg as always enabled-by-default
This commit is contained in:
parent
b861629ef6
commit
a5669e8fa3
@ -55,6 +55,11 @@ pub struct TargetInfo {
|
|||||||
pub rustflags: Vec<String>,
|
pub rustflags: Vec<String>,
|
||||||
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
|
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
|
||||||
pub rustdocflags: Vec<String>,
|
pub rustdocflags: Vec<String>,
|
||||||
|
/// Whether or not rustc (stably) supports the `--check-cfg` flag.
|
||||||
|
///
|
||||||
|
/// Can be removed once the minimum supported rustc version of Cargo is
|
||||||
|
/// at minimum 1.80.0.
|
||||||
|
pub support_check_cfg: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Kind of each file generated by a Unit, part of `FileType`.
|
/// Kind of each file generated by a Unit, part of `FileType`.
|
||||||
@ -199,6 +204,13 @@ impl TargetInfo {
|
|||||||
process.arg("--crate-type").arg(crate_type.as_str());
|
process.arg("--crate-type").arg(crate_type.as_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let support_check_cfg = rustc
|
||||||
|
.cached_output(
|
||||||
|
process.clone().arg("--check-cfg").arg("cfg()"),
|
||||||
|
extra_fingerprint,
|
||||||
|
)
|
||||||
|
.is_ok();
|
||||||
|
|
||||||
process.arg("--print=sysroot");
|
process.arg("--print=sysroot");
|
||||||
process.arg("--print=split-debuginfo");
|
process.arg("--print=split-debuginfo");
|
||||||
process.arg("--print=crate-name"); // `___` as a delimiter.
|
process.arg("--print=crate-name"); // `___` as a delimiter.
|
||||||
@ -310,6 +322,7 @@ impl TargetInfo {
|
|||||||
)?,
|
)?,
|
||||||
cfg,
|
cfg,
|
||||||
support_split_debuginfo,
|
support_split_debuginfo,
|
||||||
|
support_check_cfg,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,12 +256,9 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
|
|||||||
args.push(cfg.into());
|
args.push(cfg.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if !output.check_cfgs.is_empty() {
|
for check_cfg in &output.check_cfgs {
|
||||||
args.push("-Zunstable-options".into());
|
args.push("--check-cfg".into());
|
||||||
for check_cfg in &output.check_cfgs {
|
args.push(check_cfg.into());
|
||||||
args.push("--check-cfg".into());
|
|
||||||
args.push(check_cfg.into());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (lt, arg) in &output.linker_args {
|
for (lt, arg) in &output.linker_args {
|
||||||
|
@ -408,7 +408,11 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul
|
|||||||
paths::create_dir_all(&script_out_dir)?;
|
paths::create_dir_all(&script_out_dir)?;
|
||||||
|
|
||||||
let nightly_features_allowed = build_runner.bcx.gctx.nightly_features_allowed;
|
let nightly_features_allowed = build_runner.bcx.gctx.nightly_features_allowed;
|
||||||
let extra_check_cfg = build_runner.bcx.gctx.cli_unstable().check_cfg;
|
let extra_check_cfg = build_runner
|
||||||
|
.bcx
|
||||||
|
.target_data
|
||||||
|
.info(unit.kind)
|
||||||
|
.support_check_cfg;
|
||||||
let targets: Vec<Target> = unit.pkg.targets().to_vec();
|
let targets: Vec<Target> = unit.pkg.targets().to_vec();
|
||||||
let msrv = unit.pkg.rust_version().cloned();
|
let msrv = unit.pkg.rust_version().cloned();
|
||||||
// Need a separate copy for the fresh closure.
|
// Need a separate copy for the fresh closure.
|
||||||
@ -665,9 +669,7 @@ impl BuildOutput {
|
|||||||
///
|
///
|
||||||
/// * `pkg_descr` --- for error messages
|
/// * `pkg_descr` --- for error messages
|
||||||
/// * `library_name` --- for determining if `RUSTC_BOOTSTRAP` should be allowed
|
/// * `library_name` --- for determining if `RUSTC_BOOTSTRAP` should be allowed
|
||||||
/// * `extra_check_cfg` --- for unstable feature [`-Zcheck-cfg`]
|
/// * `extra_check_cfg` --- for `--check-cfg` (if supported)
|
||||||
///
|
|
||||||
/// [`-Zcheck-cfg`]: https://doc.rust-lang.org/cargo/reference/unstable.html#check-cfg
|
|
||||||
pub fn parse(
|
pub fn parse(
|
||||||
input: &[u8],
|
input: &[u8],
|
||||||
// Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error.
|
// Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error.
|
||||||
@ -910,8 +912,8 @@ impl BuildOutput {
|
|||||||
if extra_check_cfg {
|
if extra_check_cfg {
|
||||||
check_cfgs.push(value.to_string());
|
check_cfgs.push(value.to_string());
|
||||||
} else {
|
} else {
|
||||||
// silently ignoring the instruction to try to
|
// silently ignoring the instruction because the rustc version
|
||||||
// minimise MSRV annoyance when stabilizing -Zcheck-cfg
|
// we are using does not support --check-cfg stably
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"rustc-env" => {
|
"rustc-env" => {
|
||||||
@ -1254,7 +1256,11 @@ fn prev_build_output(
|
|||||||
&unit.pkg.to_string(),
|
&unit.pkg.to_string(),
|
||||||
&prev_script_out_dir,
|
&prev_script_out_dir,
|
||||||
&script_out_dir,
|
&script_out_dir,
|
||||||
build_runner.bcx.gctx.cli_unstable().check_cfg,
|
build_runner
|
||||||
|
.bcx
|
||||||
|
.target_data
|
||||||
|
.info(unit.kind)
|
||||||
|
.support_check_cfg,
|
||||||
build_runner.bcx.gctx.nightly_features_allowed,
|
build_runner.bcx.gctx.nightly_features_allowed,
|
||||||
unit.pkg.targets(),
|
unit.pkg.targets(),
|
||||||
&unit.pkg.rust_version().cloned(),
|
&unit.pkg.rust_version().cloned(),
|
||||||
|
@ -1454,14 +1454,7 @@ fn calculate_normal(
|
|||||||
// actually affect the output artifact so there's no need to hash it.
|
// actually affect the output artifact so there's no need to hash it.
|
||||||
path: util::hash_u64(path_args(build_runner.bcx.ws, unit).0),
|
path: util::hash_u64(path_args(build_runner.bcx.ws, unit).0),
|
||||||
features: format!("{:?}", unit.features),
|
features: format!("{:?}", unit.features),
|
||||||
// Note we curently only populate `declared_features` when `-Zcheck-cfg`
|
declared_features: format!("{declared_features:?}"),
|
||||||
// is passed since it's the only user-facing toggle that will make this
|
|
||||||
// fingerprint relevant.
|
|
||||||
declared_features: if build_runner.bcx.gctx.cli_unstable().check_cfg {
|
|
||||||
format!("{declared_features:?}")
|
|
||||||
} else {
|
|
||||||
"".to_string()
|
|
||||||
},
|
|
||||||
deps,
|
deps,
|
||||||
local: Mutex::new(local),
|
local: Mutex::new(local),
|
||||||
memoized_hash: Mutex::new(None),
|
memoized_hash: Mutex::new(None),
|
||||||
|
@ -1310,11 +1310,13 @@ fn trim_paths_args(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Generates the `--check-cfg` arguments for the `unit`.
|
/// Generates the `--check-cfg` arguments for the `unit`.
|
||||||
/// See unstable feature [`check-cfg`].
|
|
||||||
///
|
|
||||||
/// [`check-cfg`]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#check-cfg
|
|
||||||
fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec<OsString> {
|
||||||
if build_runner.bcx.gctx.cli_unstable().check_cfg {
|
if build_runner
|
||||||
|
.bcx
|
||||||
|
.target_data
|
||||||
|
.info(unit.kind)
|
||||||
|
.support_check_cfg
|
||||||
|
{
|
||||||
// The routine below generates the --check-cfg arguments. Our goals here are to
|
// The routine below generates the --check-cfg arguments. Our goals here are to
|
||||||
// enable the checking of conditionals and pass the list of declared features.
|
// enable the checking of conditionals and pass the list of declared features.
|
||||||
//
|
//
|
||||||
@ -1352,7 +1354,6 @@ fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> Vec<OsStri
|
|||||||
// Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
|
// Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs.
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
OsString::from("-Zunstable-options"),
|
|
||||||
OsString::from("--check-cfg"),
|
OsString::from("--check-cfg"),
|
||||||
OsString::from("cfg(docsrs)"),
|
OsString::from("cfg(docsrs)"),
|
||||||
OsString::from("--check-cfg"),
|
OsString::from("--check-cfg"),
|
||||||
@ -1476,11 +1477,8 @@ fn add_custom_flags(
|
|||||||
for cfg in output.cfgs.iter() {
|
for cfg in output.cfgs.iter() {
|
||||||
cmd.arg("--cfg").arg(cfg);
|
cmd.arg("--cfg").arg(cfg);
|
||||||
}
|
}
|
||||||
if !output.check_cfgs.is_empty() {
|
for check_cfg in &output.check_cfgs {
|
||||||
cmd.arg("-Zunstable-options");
|
cmd.arg("--check-cfg").arg(check_cfg);
|
||||||
for check_cfg in &output.check_cfgs {
|
|
||||||
cmd.arg("--check-cfg").arg(check_cfg);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (name, value) in output.env.iter() {
|
for (name, value) in output.env.iter() {
|
||||||
cmd.env(name, value);
|
cmd.env(name, value);
|
||||||
|
@ -753,7 +753,6 @@ unstable_cli_options!(
|
|||||||
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
|
build_std: Option<Vec<String>> = ("Enable Cargo to compile the standard library itself as part of a crate graph compilation"),
|
||||||
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
|
build_std_features: Option<Vec<String>> = ("Configure features enabled for the standard library itself when building the standard library"),
|
||||||
cargo_lints: bool = ("Enable the `[lints.cargo]` table"),
|
cargo_lints: bool = ("Enable the `[lints.cargo]` table"),
|
||||||
check_cfg: bool = ("Enable compile-time checking of `cfg` names/values/features"),
|
|
||||||
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
|
codegen_backend: bool = ("Enable the `codegen-backend` option in profiles in .cargo/config.toml file"),
|
||||||
config_include: bool = ("Enable the `include` key in config files"),
|
config_include: bool = ("Enable the `include` key in config files"),
|
||||||
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
|
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
|
||||||
@ -855,6 +854,9 @@ const STABILIZED_REGISTRY_AUTH: &str =
|
|||||||
|
|
||||||
const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
|
const STABILIZED_LINTS: &str = "The `[lints]` table is now always available.";
|
||||||
|
|
||||||
|
const STABILIZED_CHECK_CFG: &str =
|
||||||
|
"Compile-time checking of conditional (a.k.a. `-Zcheck-cfg`) is now always enabled.";
|
||||||
|
|
||||||
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
fn deserialize_build_std<'de, D>(deserializer: D) -> Result<Option<Vec<String>>, D::Error>
|
||||||
where
|
where
|
||||||
D: serde::Deserializer<'de>,
|
D: serde::Deserializer<'de>,
|
||||||
@ -1109,6 +1111,7 @@ impl CliUnstable {
|
|||||||
"credential-process" => stabilized_warn(k, "1.74", STABILIZED_CREDENTIAL_PROCESS),
|
"credential-process" => stabilized_warn(k, "1.74", STABILIZED_CREDENTIAL_PROCESS),
|
||||||
"lints" => stabilized_warn(k, "1.74", STABILIZED_LINTS),
|
"lints" => stabilized_warn(k, "1.74", STABILIZED_LINTS),
|
||||||
"registry-auth" => stabilized_warn(k, "1.74", STABILIZED_REGISTRY_AUTH),
|
"registry-auth" => stabilized_warn(k, "1.74", STABILIZED_REGISTRY_AUTH),
|
||||||
|
"check-cfg" => stabilized_warn(k, "1.80", STABILIZED_CHECK_CFG),
|
||||||
|
|
||||||
// Unstable features
|
// Unstable features
|
||||||
// Sorted alphabetically:
|
// Sorted alphabetically:
|
||||||
@ -1122,9 +1125,6 @@ impl CliUnstable {
|
|||||||
}
|
}
|
||||||
"build-std-features" => self.build_std_features = Some(parse_features(v)),
|
"build-std-features" => self.build_std_features = Some(parse_features(v)),
|
||||||
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,
|
"cargo-lints" => self.cargo_lints = parse_empty(k, v)?,
|
||||||
"check-cfg" => {
|
|
||||||
self.check_cfg = parse_empty(k, v)?;
|
|
||||||
}
|
|
||||||
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
|
"codegen-backend" => self.codegen_backend = parse_empty(k, v)?,
|
||||||
"config-include" => self.config_include = parse_empty(k, v)?,
|
"config-include" => self.config_include = parse_empty(k, v)?,
|
||||||
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
|
"direct-minimal-versions" => self.direct_minimal_versions = parse_empty(k, v)?,
|
||||||
|
@ -120,7 +120,7 @@ fn load_config_table(gctx: &GlobalContext, prefix: &str) -> CargoResult<TargetCo
|
|||||||
// Links do not support environment variables.
|
// Links do not support environment variables.
|
||||||
let target_key = ConfigKey::from_str(prefix);
|
let target_key = ConfigKey::from_str(prefix);
|
||||||
let links_overrides = match gctx.get_table(&target_key)? {
|
let links_overrides = match gctx.get_table(&target_key)? {
|
||||||
Some(links) => parse_links_overrides(&target_key, links.val, gctx)?,
|
Some(links) => parse_links_overrides(&target_key, links.val)?,
|
||||||
None => BTreeMap::new(),
|
None => BTreeMap::new(),
|
||||||
};
|
};
|
||||||
Ok(TargetConfig {
|
Ok(TargetConfig {
|
||||||
@ -135,7 +135,6 @@ fn load_config_table(gctx: &GlobalContext, prefix: &str) -> CargoResult<TargetCo
|
|||||||
fn parse_links_overrides(
|
fn parse_links_overrides(
|
||||||
target_key: &ConfigKey,
|
target_key: &ConfigKey,
|
||||||
links: HashMap<String, CV>,
|
links: HashMap<String, CV>,
|
||||||
gctx: &GlobalContext,
|
|
||||||
) -> CargoResult<BTreeMap<String, BuildOutput>> {
|
) -> CargoResult<BTreeMap<String, BuildOutput>> {
|
||||||
let mut links_overrides = BTreeMap::new();
|
let mut links_overrides = BTreeMap::new();
|
||||||
|
|
||||||
@ -204,13 +203,8 @@ fn parse_links_overrides(
|
|||||||
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
|
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||||
}
|
}
|
||||||
"rustc-check-cfg" => {
|
"rustc-check-cfg" => {
|
||||||
if gctx.cli_unstable().check_cfg {
|
let list = value.list(key)?;
|
||||||
let list = value.list(key)?;
|
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||||
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
|
|
||||||
} else {
|
|
||||||
// silently ignoring the instruction to try to
|
|
||||||
// minimise MSRV annoyance when stabilizing -Zcheck-cfg
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"rustc-env" => {
|
"rustc-env" => {
|
||||||
for (name, val) in value.table(key)?.0 {
|
for (name, val) in value.table(key)?.0 {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! Tests for -Zcheck-cfg.
|
//! Tests for Cargo usage of rustc `--check-cfg`.
|
||||||
|
|
||||||
use cargo_test_support::{basic_manifest, project};
|
use cargo_test_support::{basic_manifest, project};
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ macro_rules! x {
|
|||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features() {
|
fn features() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -48,14 +48,14 @@ fn features() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_with_deps() {
|
fn features_with_deps() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -79,14 +79,13 @@ fn features_with_deps() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_with_opt_deps() {
|
fn features_with_opt_deps() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -111,14 +110,13 @@ fn features_with_opt_deps() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_with_namespaced_features() {
|
fn features_with_namespaced_features() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -142,14 +140,13 @@ fn features_with_namespaced_features() {
|
|||||||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_fingerprint() {
|
fn features_fingerprint() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -168,14 +165,12 @@ fn features_fingerprint() {
|
|||||||
.file("src/lib.rs", "#[cfg(feature = \"f_b\")] fn entry() {}")
|
.file("src/lib.rs", "#[cfg(feature = \"f_b\")] fn entry() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
|
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_does_not_contain("[..]rustc[..]")
|
.with_stderr_does_not_contain("[..]rustc[..]")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -194,8 +189,7 @@ fn features_fingerprint() {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_does_not_contain("[..]rustc[..]")
|
.with_stderr_does_not_contain("[..]rustc[..]")
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
@ -212,8 +206,7 @@ fn features_fingerprint() {
|
|||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
// we check that the fingerprint is indeed dirty
|
// we check that the fingerprint is indeed dirty
|
||||||
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
|
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
|
||||||
// that is cause rustc to be called again with the new check-cfg args
|
// that is cause rustc to be called again with the new check-cfg args
|
||||||
@ -223,21 +216,20 @@ fn features_fingerprint() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn well_known_names_values() {
|
fn well_known_names_values() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_test() {
|
fn features_test() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -256,14 +248,13 @@ fn features_test() {
|
|||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg")
|
p.cargo("test -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_doctest() {
|
fn features_doctest() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -283,38 +274,36 @@ fn features_doctest() {
|
|||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg")
|
p.cargo("test -v --doc")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
||||||
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn well_known_names_values_test() {
|
fn well_known_names_values_test() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg")
|
p.cargo("test -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn well_known_names_values_doctest() {
|
fn well_known_names_values_doctest() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v --doc -Zcheck-cfg")
|
p.cargo("test -v --doc")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
@ -322,7 +311,7 @@ fn well_known_names_values_doctest() {
|
|||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn features_doc() {
|
fn features_doc() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -342,14 +331,14 @@ fn features_doc() {
|
|||||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("doc -v -Zcheck-cfg")
|
p.cargo("doc -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
||||||
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn build_script_feedback() {
|
fn build_script_feedback() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -370,14 +359,14 @@ fn build_script_feedback() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn build_script_doc() {
|
fn build_script_doc() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -398,7 +387,7 @@ fn build_script_doc() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("doc -v -Zcheck-cfg")
|
p.cargo("doc -v")
|
||||||
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||||
.with_stderr(
|
.with_stderr(
|
||||||
@ -412,11 +401,10 @@ fn build_script_doc() {
|
|||||||
[GENERATED] [CWD]/target/doc/foo/index.html
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
||||||
",
|
",
|
||||||
)
|
)
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn build_script_override() {
|
fn build_script_override() {
|
||||||
let target = cargo_test_support::rustc_host();
|
let target = cargo_test_support::rustc_host();
|
||||||
|
|
||||||
@ -447,49 +435,14 @@ fn build_script_override() {
|
|||||||
)
|
)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("check -v -Zcheck-cfg")
|
p.cargo("check -v")
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cargo_test]
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||||
fn build_script_override_feature_gate() {
|
|
||||||
let target = cargo_test_support::rustc_host();
|
|
||||||
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2015"
|
|
||||||
links = "a"
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.file("build.rs", "fn main() {}")
|
|
||||||
.file(
|
|
||||||
".cargo/config.toml",
|
|
||||||
&format!(
|
|
||||||
r#"
|
|
||||||
[target.{}.a]
|
|
||||||
rustc-check-cfg = ["cfg(foo)"]
|
|
||||||
"#,
|
|
||||||
target
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check")
|
|
||||||
.with_stderr_does_not_contain("warning: [..]rustc-check-cfg[..]")
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn build_script_test() {
|
fn build_script_test() {
|
||||||
let p = project()
|
let p = project()
|
||||||
.file(
|
.file(
|
||||||
@ -535,133 +488,11 @@ fn build_script_test() {
|
|||||||
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
p.cargo("test -v -Zcheck-cfg")
|
p.cargo("test -v")
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||||
.with_stdout_contains("test test_foo ... ok")
|
.with_stdout_contains("test test_foo ... ok")
|
||||||
.with_stdout_contains("test test_bar ... ok")
|
.with_stdout_contains("test test_bar ... ok")
|
||||||
.with_stdout_contains_n("test [..] ... ok", 3)
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test]
|
|
||||||
fn build_script_feature_gate() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.0.1"
|
|
||||||
edition = "2015"
|
|
||||||
build = "build.rs"
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file(
|
|
||||||
"build.rs",
|
|
||||||
r#"fn main() {
|
|
||||||
println!("cargo::rustc-check-cfg=cfg(foo)");
|
|
||||||
println!("cargo::rustc-cfg=foo");
|
|
||||||
}"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check")
|
|
||||||
.with_stderr_does_not_contain("warning: [..]rustc-check-cfg[..]")
|
|
||||||
.with_status(0)
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn config_valid() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2015"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
f_a = []
|
|
||||||
f_b = []
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.file(
|
|
||||||
".cargo/config.toml",
|
|
||||||
r#"
|
|
||||||
[unstable]
|
|
||||||
check-cfg = true
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
|
||||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test(nightly, reason = "--check-cfg is unstable")]
|
|
||||||
fn config_invalid() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2015"
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.file(
|
|
||||||
".cargo/config.toml",
|
|
||||||
r#"
|
|
||||||
[unstable]
|
|
||||||
check-cfg = ["va"]
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check")
|
|
||||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
|
||||||
.with_stderr_contains("error:[..]`unstable.check-cfg` expected true/false[..]")
|
|
||||||
.with_status(101)
|
|
||||||
.run();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cargo_test]
|
|
||||||
fn config_feature_gate() {
|
|
||||||
let p = project()
|
|
||||||
.file(
|
|
||||||
"Cargo.toml",
|
|
||||||
r#"
|
|
||||||
[package]
|
|
||||||
name = "foo"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2015"
|
|
||||||
|
|
||||||
[features]
|
|
||||||
f_a = []
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.file("src/main.rs", "fn main() {}")
|
|
||||||
.file(
|
|
||||||
".cargo/config.toml",
|
|
||||||
r#"
|
|
||||||
[unstable]
|
|
||||||
check-cfg = true
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
p.cargo("check -v")
|
|
||||||
.with_stderr_does_not_contain("--check-cfg")
|
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user