diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 219653d76c9..39e0515de36 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -54,11 +54,6 @@ pub struct TargetInfo { pub rustflags: Rc<[String]>, /// Extra flags to pass to `rustdoc`, see [`extra_args`]. pub rustdocflags: Rc<[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`. @@ -204,13 +199,6 @@ impl TargetInfo { 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=split-debuginfo"); process.arg("--print=crate-name"); // `___` as a delimiter. @@ -323,7 +311,6 @@ impl TargetInfo { .into(), cfg, support_split_debuginfo, - support_check_cfg, }); } } diff --git a/src/cargo/core/compiler/build_runner/mod.rs b/src/cargo/core/compiler/build_runner/mod.rs index 47c8219e450..f9e3cf64c3d 100644 --- a/src/cargo/core/compiler/build_runner/mod.rs +++ b/src/cargo/core/compiler/build_runner/mod.rs @@ -246,7 +246,7 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> { let mut args = compiler::extern_args(&self, unit, &mut unstable_opts)?; args.extend(compiler::lto_args(&self, unit)); args.extend(compiler::features_args(unit)); - args.extend(compiler::check_cfg_args(&self, unit)?); + args.extend(compiler::check_cfg_args(unit)?); let script_meta = self.find_build_script_metadata(unit); if let Some(meta) = script_meta { diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 98ceeb5ad73..513f9f09840 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -405,11 +405,6 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul paths::create_dir_all(&script_out_dir)?; let nightly_features_allowed = build_runner.bcx.gctx.nightly_features_allowed; - let extra_check_cfg = build_runner - .bcx - .target_data - .info(unit.kind) - .support_check_cfg; let targets: Vec = unit.pkg.targets().to_vec(); let msrv = unit.pkg.rust_version().cloned(); // Need a separate copy for the fresh closure. @@ -557,7 +552,6 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul &pkg_descr, &script_out_dir, &script_out_dir, - extra_check_cfg, nightly_features_allowed, &targets, &msrv, @@ -586,7 +580,6 @@ fn build_work(build_runner: &mut BuildRunner<'_, '_>, unit: &Unit) -> CargoResul &pkg_descr, &prev_script_out_dir, &script_out_dir, - extra_check_cfg, nightly_features_allowed, &targets_fresh, &msrv_fresh, @@ -643,7 +636,6 @@ impl BuildOutput { pkg_descr: &str, script_out_dir_when_generated: &Path, script_out_dir: &Path, - extra_check_cfg: bool, nightly_features_allowed: bool, targets: &[Target], msrv: &Option, @@ -655,7 +647,6 @@ impl BuildOutput { pkg_descr, script_out_dir_when_generated, script_out_dir, - extra_check_cfg, nightly_features_allowed, targets, msrv, @@ -666,7 +657,6 @@ impl BuildOutput { /// /// * `pkg_descr` --- for error messages /// * `library_name` --- for determining if `RUSTC_BOOTSTRAP` should be allowed - /// * `extra_check_cfg` --- for `--check-cfg` (if supported) pub fn parse( input: &[u8], // Takes String instead of InternedString so passing `unit.pkg.name()` will give a compile error. @@ -674,7 +664,6 @@ impl BuildOutput { pkg_descr: &str, script_out_dir_when_generated: &Path, script_out_dir: &Path, - extra_check_cfg: bool, nightly_features_allowed: bool, targets: &[Target], msrv: &Option, @@ -921,14 +910,7 @@ impl BuildOutput { linker_args.push((LinkArgTarget::All, value)); } "rustc-cfg" => cfgs.push(value.to_string()), - "rustc-check-cfg" => { - if extra_check_cfg { - check_cfgs.push(value.to_string()); - } else { - // silently ignoring the instruction because the rustc version - // we are using does not support --check-cfg stably - } - } + "rustc-check-cfg" => check_cfgs.push(value.to_string()), "rustc-env" => { let (key, val) = BuildOutput::parse_rustc_env(&value, &whence)?; // Build scripts aren't allowed to set RUSTC_BOOTSTRAP. @@ -1265,11 +1247,6 @@ fn prev_build_output( &unit.pkg.to_string(), &prev_script_out_dir, &script_out_dir, - build_runner - .bcx - .target_data - .info(unit.kind) - .support_check_cfg, build_runner.bcx.gctx.nightly_features_allowed, unit.pkg.targets(), &unit.pkg.rust_version().cloned(), diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index 70dfb3085d3..a7b7e7b83d9 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -732,7 +732,7 @@ fn prepare_rustdoc(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResu let doc_dir = build_runner.files().out_dir(unit); rustdoc.arg("-o").arg(&doc_dir); rustdoc.args(&features_args(unit)); - rustdoc.args(&check_cfg_args(build_runner, unit)?); + rustdoc.args(&check_cfg_args(unit)?); add_error_format_and_color(build_runner, &mut rustdoc); add_allow_features(build_runner, &mut rustdoc); @@ -1125,7 +1125,7 @@ fn build_base_args( } cmd.args(&features_args(unit)); - cmd.args(&check_cfg_args(build_runner, unit)?); + cmd.args(&check_cfg_args(unit)?); let meta = build_runner.files().metadata(unit); cmd.arg("-C").arg(&format!("metadata={}", meta)); @@ -1310,83 +1310,76 @@ fn trim_paths_args( } /// Generates the `--check-cfg` arguments for the `unit`. -fn check_cfg_args(build_runner: &BuildRunner<'_, '_>, unit: &Unit) -> CargoResult> { - 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 - // enable the checking of conditionals and pass the list of declared features. - // - // In the simplified case, it would resemble something like this: - // - // --check-cfg=cfg() --check-cfg=cfg(feature, values(...)) - // - // but having `cfg()` is redundant with the second argument (as well-known names - // and values are implicitly enabled when one or more `--check-cfg` argument is - // passed) so we don't emit it and just pass: - // - // --check-cfg=cfg(feature, values(...)) - // - // This way, even if there are no declared features, the config `feature` will - // still be expected, meaning users would get "unexpected value" instead of name. - // This wasn't always the case, see rust-lang#119930 for some details. +fn check_cfg_args(unit: &Unit) -> CargoResult> { + // 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. + // + // In the simplified case, it would resemble something like this: + // + // --check-cfg=cfg() --check-cfg=cfg(feature, values(...)) + // + // but having `cfg()` is redundant with the second argument (as well-known names + // and values are implicitly enabled when one or more `--check-cfg` argument is + // passed) so we don't emit it and just pass: + // + // --check-cfg=cfg(feature, values(...)) + // + // This way, even if there are no declared features, the config `feature` will + // still be expected, meaning users would get "unexpected value" instead of name. + // This wasn't always the case, see rust-lang#119930 for some details. - let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25; - let mut arg_feature = OsString::with_capacity(gross_cap_estimation); + let gross_cap_estimation = unit.pkg.summary().features().len() * 7 + 25; + let mut arg_feature = OsString::with_capacity(gross_cap_estimation); - arg_feature.push("cfg(feature, values("); - for (i, feature) in unit.pkg.summary().features().keys().enumerate() { - if i != 0 { - arg_feature.push(", "); - } - arg_feature.push("\""); - arg_feature.push(feature); - arg_feature.push("\""); + arg_feature.push("cfg(feature, values("); + for (i, feature) in unit.pkg.summary().features().keys().enumerate() { + if i != 0 { + arg_feature.push(", "); } - arg_feature.push("))"); - - // We also include the `docsrs` cfg from the docs.rs service. We include it here - // (in Cargo) instead of rustc, since there is a much closer relationship between - // Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use - // Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs. - - let mut args = vec![ - OsString::from("--check-cfg"), - OsString::from("cfg(docsrs)"), - OsString::from("--check-cfg"), - arg_feature, - ]; - - // Also include the custom arguments specified in `[lints.rust.unexpected_cfgs.check_cfg]` - if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() { - if let Some(rust_lints) = lints.get("rust") { - if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") { - if let Some(config) = unexpected_cfgs.config() { - if let Some(check_cfg) = config.get("check-cfg") { - if let Ok(check_cfgs) = - toml::Value::try_into::>(check_cfg.clone()) - { - for check_cfg in check_cfgs { - args.push(OsString::from("--check-cfg")); - args.push(OsString::from(check_cfg)); - } - // error about `check-cfg` not being a list-of-string - } else { - bail!("`lints.rust.unexpected_cfgs.check-cfg` must be a list of string"); + arg_feature.push("\""); + arg_feature.push(feature); + arg_feature.push("\""); + } + arg_feature.push("))"); + + // We also include the `docsrs` cfg from the docs.rs service. We include it here + // (in Cargo) instead of rustc, since there is a much closer relationship between + // Cargo and docs.rs than rustc and docs.rs. In particular, all users of docs.rs use + // Cargo, but not all users of rustc (like Rust-for-Linux) use docs.rs. + + let mut args = vec![ + OsString::from("--check-cfg"), + OsString::from("cfg(docsrs)"), + OsString::from("--check-cfg"), + arg_feature, + ]; + + // Also include the custom arguments specified in `[lints.rust.unexpected_cfgs.check_cfg]` + if let Ok(Some(lints)) = unit.pkg.manifest().resolved_toml().resolved_lints() { + if let Some(rust_lints) = lints.get("rust") { + if let Some(unexpected_cfgs) = rust_lints.get("unexpected_cfgs") { + if let Some(config) = unexpected_cfgs.config() { + if let Some(check_cfg) = config.get("check-cfg") { + if let Ok(check_cfgs) = + toml::Value::try_into::>(check_cfg.clone()) + { + for check_cfg in check_cfgs { + args.push(OsString::from("--check-cfg")); + args.push(OsString::from(check_cfg)); } + // error about `check-cfg` not being a list-of-string + } else { + bail!( + "`lints.rust.unexpected_cfgs.check-cfg` must be a list of string" + ); } } } } } - - Ok(args) - } else { - Ok(Vec::new()) } + + Ok(args) } /// Adds LTO related codegen flags.