mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
Auto merge of #13571 - Urgau:stabilize-check-cfg, r=weihanglo
Stabilize `-Zcheck-cfg` as always enabled This PR stabilize the `-Zcheck-cfg` option as always enabled. ~~Waiting on https://github.com/rust-lang/rust/issues/82450#issuecomment-1965328542 to complete, but is otherwise ready to be reviewed (in particular the documentation changes).~~ (https://github.com/rust-lang/rust/pull/123501) Fixes https://github.com/rust-lang/cargo/issues/10554
This commit is contained in:
commit
7ebc065673
|
@ -55,6 +55,11 @@ pub struct TargetInfo {
|
|||
pub rustflags: Vec<String>,
|
||||
/// Extra flags to pass to `rustdoc`, see [`extra_args`].
|
||||
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`.
|
||||
|
@ -199,6 +204,13 @@ 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.
|
||||
|
@ -310,6 +322,7 @@ impl TargetInfo {
|
|||
)?,
|
||||
cfg,
|
||||
support_split_debuginfo,
|
||||
support_check_cfg,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -256,12 +256,9 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
|
|||
args.push(cfg.into());
|
||||
}
|
||||
|
||||
if !output.check_cfgs.is_empty() {
|
||||
args.push("-Zunstable-options".into());
|
||||
for check_cfg in &output.check_cfgs {
|
||||
args.push("--check-cfg".into());
|
||||
args.push(check_cfg.into());
|
||||
}
|
||||
for check_cfg in &output.check_cfgs {
|
||||
args.push("--check-cfg".into());
|
||||
args.push(check_cfg.into());
|
||||
}
|
||||
|
||||
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)?;
|
||||
|
||||
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 msrv = unit.pkg.rust_version().cloned();
|
||||
// Need a separate copy for the fresh closure.
|
||||
|
@ -665,9 +669,7 @@ impl BuildOutput {
|
|||
///
|
||||
/// * `pkg_descr` --- for error messages
|
||||
/// * `library_name` --- for determining if `RUSTC_BOOTSTRAP` should be allowed
|
||||
/// * `extra_check_cfg` --- for unstable feature [`-Zcheck-cfg`]
|
||||
///
|
||||
/// [`-Zcheck-cfg`]: https://doc.rust-lang.org/cargo/reference/unstable.html#check-cfg
|
||||
/// * `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.
|
||||
|
@ -910,8 +912,8 @@ impl BuildOutput {
|
|||
if extra_check_cfg {
|
||||
check_cfgs.push(value.to_string());
|
||||
} else {
|
||||
// silently ignoring the instruction to try to
|
||||
// minimise MSRV annoyance when stabilizing -Zcheck-cfg
|
||||
// silently ignoring the instruction because the rustc version
|
||||
// we are using does not support --check-cfg stably
|
||||
}
|
||||
}
|
||||
"rustc-env" => {
|
||||
|
@ -1254,7 +1256,11 @@ fn prev_build_output(
|
|||
&unit.pkg.to_string(),
|
||||
&prev_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,
|
||||
unit.pkg.targets(),
|
||||
&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.
|
||||
path: util::hash_u64(path_args(build_runner.bcx.ws, unit).0),
|
||||
features: format!("{:?}", unit.features),
|
||||
// Note we curently only populate `declared_features` when `-Zcheck-cfg`
|
||||
// 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()
|
||||
},
|
||||
declared_features: format!("{declared_features:?}"),
|
||||
deps,
|
||||
local: Mutex::new(local),
|
||||
memoized_hash: Mutex::new(None),
|
||||
|
|
|
@ -1310,11 +1310,13 @@ fn trim_paths_args(
|
|||
}
|
||||
|
||||
/// 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> {
|
||||
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
|
||||
// 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.
|
||||
|
||||
vec![
|
||||
OsString::from("-Zunstable-options"),
|
||||
OsString::from("--check-cfg"),
|
||||
OsString::from("cfg(docsrs)"),
|
||||
OsString::from("--check-cfg"),
|
||||
|
@ -1476,11 +1477,8 @@ fn add_custom_flags(
|
|||
for cfg in output.cfgs.iter() {
|
||||
cmd.arg("--cfg").arg(cfg);
|
||||
}
|
||||
if !output.check_cfgs.is_empty() {
|
||||
cmd.arg("-Zunstable-options");
|
||||
for check_cfg in &output.check_cfgs {
|
||||
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() {
|
||||
cmd.env(name, value);
|
||||
|
|
|
@ -758,7 +758,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_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"),
|
||||
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"),
|
||||
config_include: bool = ("Enable the `include` key in config files"),
|
||||
direct_minimal_versions: bool = ("Resolve minimal dependency versions instead of maximum (direct dependencies only)"),
|
||||
|
@ -860,6 +859,9 @@ const STABILIZED_REGISTRY_AUTH: &str =
|
|||
|
||||
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>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
|
@ -1114,6 +1116,7 @@ impl CliUnstable {
|
|||
"credential-process" => stabilized_warn(k, "1.74", STABILIZED_CREDENTIAL_PROCESS),
|
||||
"lints" => stabilized_warn(k, "1.74", STABILIZED_LINTS),
|
||||
"registry-auth" => stabilized_warn(k, "1.74", STABILIZED_REGISTRY_AUTH),
|
||||
"check-cfg" => stabilized_warn(k, "1.80", STABILIZED_CHECK_CFG),
|
||||
|
||||
// Unstable features
|
||||
// Sorted alphabetically:
|
||||
|
@ -1127,9 +1130,6 @@ impl CliUnstable {
|
|||
}
|
||||
"build-std-features" => self.build_std_features = Some(parse_features(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)?,
|
||||
"config-include" => self.config_include = 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.
|
||||
let target_key = ConfigKey::from_str(prefix);
|
||||
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(),
|
||||
};
|
||||
Ok(TargetConfig {
|
||||
|
@ -135,7 +135,6 @@ fn load_config_table(gctx: &GlobalContext, prefix: &str) -> CargoResult<TargetCo
|
|||
fn parse_links_overrides(
|
||||
target_key: &ConfigKey,
|
||||
links: HashMap<String, CV>,
|
||||
gctx: &GlobalContext,
|
||||
) -> CargoResult<BTreeMap<String, BuildOutput>> {
|
||||
let mut links_overrides = BTreeMap::new();
|
||||
|
||||
|
@ -204,13 +203,8 @@ fn parse_links_overrides(
|
|||
output.cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||
}
|
||||
"rustc-check-cfg" => {
|
||||
if gctx.cli_unstable().check_cfg {
|
||||
let list = value.list(key)?;
|
||||
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
|
||||
}
|
||||
let list = value.list(key)?;
|
||||
output.check_cfgs.extend(list.iter().map(|v| v.0.clone()));
|
||||
}
|
||||
"rustc-env" => {
|
||||
for (name, val) in value.table(key)?.0 {
|
||||
|
|
|
@ -456,6 +456,9 @@ values](https://github.com/sfackler/rust-openssl/blob/dc72a8e2c429e46c275e528b61
|
|||
```rust,ignore
|
||||
// (portion of build.rs)
|
||||
|
||||
println!("cargo::rustc-check-cfg=cfg(ossl101,ossl102)");
|
||||
println!("cargo::rustc-check-cfg=cfg(ossl110,ossl110g,ossl111)");
|
||||
|
||||
if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") {
|
||||
let version = u64::from_str_radix(&version, 16).unwrap();
|
||||
|
||||
|
|
|
@ -130,6 +130,8 @@ one detailed below.
|
|||
compiler.
|
||||
* [`cargo::rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg`
|
||||
settings.
|
||||
* [`cargo::rustc-check-cfg=CHECK_CFG`](#rustc-check-cfg) -- Register custom `cfg`s as
|
||||
expected for compile-time checking of configs.
|
||||
* [`cargo::rustc-env=VAR=VALUE`](#rustc-env) --- Sets an environment variable.
|
||||
* [`cargo::rustc-cdylib-link-arg=FLAG`](#rustc-cdylib-link-arg) --- Passes custom
|
||||
flags to a linker for cdylib crates.
|
||||
|
@ -233,7 +235,10 @@ equivalent to using [`rustc-link-lib`](#rustc-link-lib) and
|
|||
|
||||
The `rustc-cfg` instruction tells Cargo to pass the given value to the
|
||||
[`--cfg` flag][option-cfg] to the compiler. This may be used for compile-time
|
||||
detection of features to enable [conditional compilation].
|
||||
detection of features to enable [conditional compilation]. Custom cfgs
|
||||
must either be expected using the [`cargo::rustc-check-cfg`](#rustc-check-cfg)
|
||||
instruction or usage will need to allow the [`unexpected_cfgs`][unexpected-cfgs]
|
||||
lint to avoid unexpected cfgs warnings.
|
||||
|
||||
Note that this does *not* affect Cargo's dependency resolution. This cannot be
|
||||
used to enable an optional dependency, or enable other Cargo features.
|
||||
|
@ -249,6 +254,41 @@ identifier, the value should be a string.
|
|||
[cargo features]: features.md
|
||||
[conditional compilation]: ../../reference/conditional-compilation.md
|
||||
[option-cfg]: ../../rustc/command-line-arguments.md#option-cfg
|
||||
[unexpected-cfgs]: ../../rustc/lints/listing/warn-by-default.md#unexpected-cfgs
|
||||
|
||||
### `cargo::rustc-check-cfg=CHECK_CFG` {#rustc-check-cfg}
|
||||
|
||||
Add to the list of expected config names and values that is used when checking
|
||||
the _reachable_ cfg expressions.
|
||||
|
||||
For details on the syntax of `CHECK_CFG`, see `rustc` [`--check-cfg` flag][option-check-cfg].
|
||||
See also the [`unexpected_cfgs`][unexpected-cfgs] lint.
|
||||
|
||||
The instruction can be used like this:
|
||||
|
||||
```rust,no_run
|
||||
// build.rs
|
||||
println!("cargo::rustc-check-cfg=cfg(foo, values(\"bar\"))");
|
||||
```
|
||||
|
||||
Note that all possible cfgs should be defined, regardless of which cfgs are
|
||||
currently enabled. This includes all possible values of a given cfg name.
|
||||
|
||||
It is recommended to group the `cargo::rustc-check-cfg` and
|
||||
[`cargo::rustc-cfg`][option-cfg] instructions as closely as possible in order to
|
||||
avoid typos, missing check-cfg, stalled cfgs...
|
||||
|
||||
#### Example of using `cargo::rustc-check-cfg` and `cargo::rustc-cfg` together
|
||||
|
||||
```rust,no_run
|
||||
// build.rs
|
||||
println!("cargo::rustc-check-cfg=cfg(foo, values(\"bar\"))");
|
||||
if foo_bar_condition {
|
||||
println!("cargo::rustc-cfg=foo=\"bar\"");
|
||||
}
|
||||
```
|
||||
|
||||
[option-check-cfg]: ../../rustc/command-line-arguments.md#option-check-cfg
|
||||
|
||||
### `cargo::rustc-env=VAR=VALUE` {#rustc-env}
|
||||
|
||||
|
|
|
@ -83,7 +83,6 @@ For the latest nightly, see the [nightly version] of this page.
|
|||
* [build-std-features](#build-std-features) --- Sets features to use with the standard library.
|
||||
* [binary-dep-depinfo](#binary-dep-depinfo) --- Causes the dep-info file to track binary dependencies.
|
||||
* [panic-abort-tests](#panic-abort-tests) --- Allows running tests with the "abort" panic strategy.
|
||||
* [check-cfg](#check-cfg) --- Compile-time validation of `cfg` expressions.
|
||||
* [host-config](#host-config) --- Allows setting `[target]`-like configuration settings for host build targets.
|
||||
* [target-applies-to-host](#target-applies-to-host) --- Alters whether certain flags will be passed to host build targets.
|
||||
* [gc](#gc) --- Global cache garbage collection.
|
||||
|
@ -1154,44 +1153,6 @@ You can use the flag like this:
|
|||
cargo rustdoc -Z unstable-options --output-format json
|
||||
```
|
||||
|
||||
## check-cfg
|
||||
|
||||
* RFC: [#3013](https://github.com/rust-lang/rfcs/pull/3013)
|
||||
* Tracking Issue: [#10554](https://github.com/rust-lang/cargo/issues/10554)
|
||||
|
||||
`-Z check-cfg` command line enables compile time checking of Cargo features as well as `rustc`
|
||||
well known names and values in `#[cfg]`, `cfg!`, `#[link]` and `#[cfg_attr]` with the `rustc`
|
||||
and `rustdoc` unstable `--check-cfg` command line.
|
||||
|
||||
You can use the flag like this:
|
||||
|
||||
```
|
||||
cargo check -Z unstable-options -Z check-cfg
|
||||
```
|
||||
|
||||
### `cargo::rustc-check-cfg=CHECK_CFG`
|
||||
|
||||
The `rustc-check-cfg` instruction tells Cargo to pass the given value to the
|
||||
`--check-cfg` flag to the compiler. This may be used for compile-time
|
||||
detection of unexpected conditional compilation name and/or values.
|
||||
|
||||
This can only be used in combination with `-Zcheck-cfg` otherwise it is ignored
|
||||
with a warning.
|
||||
|
||||
If you want to integrate with Cargo features, only use `-Zcheck-cfg` instead of
|
||||
trying to do it manually with this option.
|
||||
|
||||
You can use the instruction like this:
|
||||
|
||||
```rust,no_run
|
||||
// build.rs
|
||||
println!("cargo::rustc-check-cfg=cfg(foo, bar)");
|
||||
```
|
||||
|
||||
```
|
||||
cargo check -Z unstable-options -Z check-cfg
|
||||
```
|
||||
|
||||
## codegen-backend
|
||||
|
||||
The `codegen-backend` feature makes it possible to select the codegen backend used by rustc using a profile.
|
||||
|
@ -1798,3 +1759,11 @@ The `-Z registry-auth` feature has been stabilized in the 1.74 release with the
|
|||
requirement that a credential-provider is configured.
|
||||
|
||||
See [Registry Authentication](registry-authentication.md) documentation for details.
|
||||
|
||||
## check-cfg
|
||||
|
||||
The `-Z check-cfg` feature has been stabilized in the 1.80 release by making it the
|
||||
default behavior.
|
||||
|
||||
See the [build script documentation](build-scripts.md#rustc-check-cfg) for informations
|
||||
about specifying custom cfgs.
|
||||
|
|
|
@ -2609,7 +2609,10 @@ fn cfg_test() {
|
|||
)
|
||||
.file(
|
||||
"build.rs",
|
||||
r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#,
|
||||
r#"fn main() {
|
||||
println!("cargo::rustc-cfg=foo");
|
||||
println!("cargo::rustc-check-cfg=cfg(foo)");
|
||||
}"#,
|
||||
)
|
||||
.file(
|
||||
"src/lib.rs",
|
||||
|
@ -2714,6 +2717,9 @@ fn cfg_override_test() {
|
|||
authors = []
|
||||
build = "build.rs"
|
||||
links = "a"
|
||||
|
||||
[lints.rust]
|
||||
unexpected_cfgs = "allow" # bc of override, stable/nightly, tests
|
||||
"#,
|
||||
)
|
||||
.file("build.rs", "")
|
||||
|
@ -5590,9 +5596,10 @@ fn build_script_rerun_when_target_rustflags_change() {
|
|||
use std::env;
|
||||
|
||||
fn main() {
|
||||
println!("cargo::rustc-check-cfg=cfg(enable)");
|
||||
if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") {
|
||||
if !rustflags.is_empty() {
|
||||
println!("cargo::rustc-cfg=enable")
|
||||
println!("cargo::rustc-cfg=enable");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<svg width="1230px" height="722px" xmlns="http://www.w3.org/2000/svg">
|
||||
<svg width="1230px" height="704px" xmlns="http://www.w3.org/2000/svg">
|
||||
<style>
|
||||
.fg { fill: #AAAAAA }
|
||||
.bg { background: #000000 }
|
||||
|
@ -39,63 +39,61 @@
|
|||
</tspan>
|
||||
<tspan x="10px" y="190px"><tspan> </tspan><tspan class="fg-cyan bold">-Z cargo-lints </tspan><tspan> Enable the `[lints.cargo]` table</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-cyan bold">-Z check-cfg </tspan><tspan> Enable compile-time checking of `cfg` names/values/features</tspan>
|
||||
<tspan x="10px" y="208px"><tspan> </tspan><tspan class="fg-cyan bold">-Z codegen-backend </tspan><tspan> Enable the `codegen-backend` option in profiles in .cargo/config.toml file</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-cyan bold">-Z codegen-backend </tspan><tspan> Enable the `codegen-backend` option in profiles in .cargo/config.toml file</tspan>
|
||||
<tspan x="10px" y="226px"><tspan> </tspan><tspan class="fg-cyan bold">-Z config-include </tspan><tspan> Enable the `include` key in config files</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="244px"><tspan> </tspan><tspan class="fg-cyan bold">-Z config-include </tspan><tspan> Enable the `include` key in config files</tspan>
|
||||
<tspan x="10px" y="244px"><tspan> </tspan><tspan class="fg-cyan bold">-Z direct-minimal-versions</tspan><tspan> Resolve minimal dependency versions instead of maximum (direct dependencies only)</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">-Z direct-minimal-versions</tspan><tspan> Resolve minimal dependency versions instead of maximum (direct dependencies only)</tspan>
|
||||
<tspan x="10px" y="262px"><tspan> </tspan><tspan class="fg-cyan bold">-Z doctest-xcompile </tspan><tspan> Compile and run doctests for non-host target using runner config</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">-Z doctest-xcompile </tspan><tspan> Compile and run doctests for non-host target using runner config</tspan>
|
||||
<tspan x="10px" y="280px"><tspan> </tspan><tspan class="fg-cyan bold">-Z dual-proc-macros </tspan><tspan> Build proc-macros for both the host and the target</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">-Z dual-proc-macros </tspan><tspan> Build proc-macros for both the host and the target</tspan>
|
||||
<tspan x="10px" y="298px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gc </tspan><tspan> Track cache usage and "garbage collect" unused files</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gc </tspan><tspan> Track cache usage and "garbage collect" unused files</tspan>
|
||||
<tspan x="10px" y="316px"><tspan> </tspan><tspan class="fg-cyan bold">-Z git </tspan><tspan> Enable support for shallow git fetch operations</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-Z git </tspan><tspan> Enable support for shallow git fetch operations</tspan>
|
||||
<tspan x="10px" y="334px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gitoxide </tspan><tspan> Use gitoxide for the given git interactions, or all of them if no argument is given</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">-Z gitoxide </tspan><tspan> Use gitoxide for the given git interactions, or all of them if no argument is given</tspan>
|
||||
<tspan x="10px" y="352px"><tspan> </tspan><tspan class="fg-cyan bold">-Z host-config </tspan><tspan> Enable the `[host]` section in the .cargo/config.toml file</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">-Z host-config </tspan><tspan> Enable the `[host]` section in the .cargo/config.toml file</tspan>
|
||||
<tspan x="10px" y="370px"><tspan> </tspan><tspan class="fg-cyan bold">-Z minimal-versions </tspan><tspan> Resolve minimal dependency versions instead of maximum</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">-Z minimal-versions </tspan><tspan> Resolve minimal dependency versions instead of maximum</tspan>
|
||||
<tspan x="10px" y="388px"><tspan> </tspan><tspan class="fg-cyan bold">-Z msrv-policy </tspan><tspan> Enable rust-version aware policy within cargo</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-Z msrv-policy </tspan><tspan> Enable rust-version aware policy within cargo</tspan>
|
||||
<tspan x="10px" y="406px"><tspan> </tspan><tspan class="fg-cyan bold">-Z mtime-on-use </tspan><tspan> Configure Cargo to update the mtime of used files</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">-Z mtime-on-use </tspan><tspan> Configure Cargo to update the mtime of used files</tspan>
|
||||
<tspan x="10px" y="424px"><tspan> </tspan><tspan class="fg-cyan bold">-Z no-index-update </tspan><tspan> Do not update the registry index even if the cache is outdated</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">-Z no-index-update </tspan><tspan> Do not update the registry index even if the cache is outdated</tspan>
|
||||
<tspan x="10px" y="442px"><tspan> </tspan><tspan class="fg-cyan bold">-Z panic-abort-tests </tspan><tspan> Enable support to run tests with -Cpanic=abort</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">-Z panic-abort-tests </tspan><tspan> Enable support to run tests with -Cpanic=abort</tspan>
|
||||
<tspan x="10px" y="460px"><tspan> </tspan><tspan class="fg-cyan bold">-Z profile-rustflags </tspan><tspan> Enable the `rustflags` option in profiles in .cargo/config.toml file</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">-Z profile-rustflags </tspan><tspan> Enable the `rustflags` option in profiles in .cargo/config.toml file</tspan>
|
||||
<tspan x="10px" y="478px"><tspan> </tspan><tspan class="fg-cyan bold">-Z public-dependency </tspan><tspan> Respect a dependency's `public` field in Cargo.toml to control public/private dependencies</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">-Z public-dependency </tspan><tspan> Respect a dependency's `public` field in Cargo.toml to control public/private dependencies</tspan>
|
||||
<tspan x="10px" y="496px"><tspan> </tspan><tspan class="fg-cyan bold">-Z publish-timeout </tspan><tspan> Enable the `publish.timeout` key in .cargo/config.toml file</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="514px"><tspan> </tspan><tspan class="fg-cyan bold">-Z publish-timeout </tspan><tspan> Enable the `publish.timeout` key in .cargo/config.toml file</tspan>
|
||||
<tspan x="10px" y="514px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-map </tspan><tspan> Allow passing external documentation mappings to rustdoc</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="532px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-map </tspan><tspan> Allow passing external documentation mappings to rustdoc</tspan>
|
||||
<tspan x="10px" y="532px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-scrape-examples</tspan><tspan> Allows Rustdoc to scrape code examples from reverse-dependencies</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="550px"><tspan> </tspan><tspan class="fg-cyan bold">-Z rustdoc-scrape-examples</tspan><tspan> Allows Rustdoc to scrape code examples from reverse-dependencies</tspan>
|
||||
<tspan x="10px" y="550px"><tspan> </tspan><tspan class="fg-cyan bold">-Z script </tspan><tspan> Enable support for single-file, `.rs` packages</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">-Z script </tspan><tspan> Enable support for single-file, `.rs` packages</tspan>
|
||||
<tspan x="10px" y="568px"><tspan> </tspan><tspan class="fg-cyan bold">-Z target-applies-to-host </tspan><tspan> Enable the `target-applies-to-host` key in the .cargo/config.toml file</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">-Z target-applies-to-host </tspan><tspan> Enable the `target-applies-to-host` key in the .cargo/config.toml file</tspan>
|
||||
<tspan x="10px" y="586px"><tspan> </tspan><tspan class="fg-cyan bold">-Z trim-paths </tspan><tspan> Enable the `trim-paths` option in profiles</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="604px"><tspan> </tspan><tspan class="fg-cyan bold">-Z trim-paths </tspan><tspan> Enable the `trim-paths` option in profiles</tspan>
|
||||
<tspan x="10px" y="604px"><tspan> </tspan><tspan class="fg-cyan bold">-Z unstable-options </tspan><tspan> Allow the usage of unstable options</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="622px"><tspan> </tspan><tspan class="fg-cyan bold">-Z unstable-options </tspan><tspan> Allow the usage of unstable options</tspan>
|
||||
<tspan x="10px" y="622px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="640px">
|
||||
<tspan x="10px" y="640px"><tspan>Run with `</tspan><tspan class="fg-cyan bold">cargo -Z</tspan><tspan> </tspan><tspan class="fg-cyan">[FLAG] [COMMAND]</tspan><tspan>`</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="658px"><tspan>Run with `</tspan><tspan class="fg-cyan bold">cargo -Z</tspan><tspan> </tspan><tspan class="fg-cyan">[FLAG] [COMMAND]</tspan><tspan>`</tspan>
|
||||
<tspan x="10px" y="658px">
|
||||
</tspan>
|
||||
<tspan x="10px" y="676px">
|
||||
<tspan x="10px" y="676px"><tspan>See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information about these flags.</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="694px"><tspan>See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html for more information about these flags.</tspan>
|
||||
</tspan>
|
||||
<tspan x="10px" y="712px">
|
||||
<tspan x="10px" y="694px">
|
||||
</tspan>
|
||||
</text>
|
||||
|
||||
|
|
Before Width: | Height: | Size: 7.3 KiB After Width: | Height: | Size: 7.2 KiB |
|
@ -1,4 +1,4 @@
|
|||
//! Tests for -Zcheck-cfg.
|
||||
//! Tests for Cargo usage of rustc `--check-cfg`.
|
||||
|
||||
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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -48,14 +48,14 @@ fn features() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -79,14 +79,13 @@ fn features_with_deps() {
|
|||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.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")]
|
||||
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||
fn features_with_opt_deps() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -111,14 +110,13 @@ fn features_with_opt_deps() {
|
|||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -142,14 +140,13 @@ fn features_with_namespaced_features() {
|
|||
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.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")]
|
||||
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||
fn features_fingerprint() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -168,14 +165,12 @@ fn features_fingerprint() {
|
|||
.file("src/lib.rs", "#[cfg(feature = \"f_b\")] fn entry() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
||||
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
|
||||
.run();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_does_not_contain("[..]rustc[..]")
|
||||
.run();
|
||||
|
||||
|
@ -194,8 +189,7 @@ fn features_fingerprint() {
|
|||
"#,
|
||||
);
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_does_not_contain("[..]rustc[..]")
|
||||
.run();
|
||||
|
||||
|
@ -212,8 +206,7 @@ fn features_fingerprint() {
|
|||
"#,
|
||||
);
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
// we check that the fingerprint is indeed dirty
|
||||
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
|
||||
// that is cause rustc to be called again with the new check-cfg args
|
||||
|
@ -223,21 +216,20 @@ fn features_fingerprint() {
|
|||
.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() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -256,14 +248,13 @@ fn features_test() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("test -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("test -v")
|
||||
.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")]
|
||||
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||
fn features_doctest() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -283,38 +274,36 @@ fn features_doctest() {
|
|||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("test -v --doc -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("test -v --doc")
|
||||
.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!("rustc" => "cfg" of "docsrs"))
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
||||
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||
.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() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("test -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("test -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.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() {
|
||||
let p = project()
|
||||
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
||||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("test -v --doc -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("test -v --doc")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
|
@ -322,7 +311,7 @@ fn well_known_names_values_doctest() {
|
|||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -342,14 +331,14 @@ fn features_doc() {
|
|||
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("doc -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("doc -v")
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
||||
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -370,14 +359,14 @@ fn build_script_feedback() {
|
|||
)
|
||||
.build();
|
||||
|
||||
p.cargo("check -v -Zcheck-cfg")
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
p.cargo("check -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
||||
.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() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -398,7 +387,7 @@ fn build_script_doc() {
|
|||
)
|
||||
.build();
|
||||
|
||||
p.cargo("doc -v -Zcheck-cfg")
|
||||
p.cargo("doc -v")
|
||||
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||
.with_stderr(
|
||||
|
@ -412,11 +401,10 @@ fn build_script_doc() {
|
|||
[GENERATED] [CWD]/target/doc/foo/index.html
|
||||
",
|
||||
)
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
.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() {
|
||||
let target = cargo_test_support::rustc_host();
|
||||
|
||||
|
@ -447,49 +435,14 @@ fn build_script_override() {
|
|||
)
|
||||
.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 "feature" with))
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
||||
.masquerade_as_nightly_cargo(&["check-cfg"])
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
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")]
|
||||
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
||||
fn build_script_test() {
|
||||
let p = project()
|
||||
.file(
|
||||
|
@ -535,133 +488,11 @@ fn build_script_test() {
|
|||
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("test -v -Zcheck-cfg")
|
||||
p.cargo("test -v")
|
||||
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
||||
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
||||
.with_stdout_contains("test test_foo ... ok")
|
||||
.with_stdout_contains("test test_bar ... ok")
|
||||
.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();
|
||||
}
|
||||
|
|
|
@ -377,6 +377,7 @@ fn no_implicit_feature() {
|
|||
r#"
|
||||
fn main() {
|
||||
if cfg!(feature = "regex") { println!("regex"); }
|
||||
#[allow(unexpected_cfgs)]
|
||||
if cfg!(feature = "lazy_static") { println!("lazy_static"); }
|
||||
}
|
||||
"#,
|
||||
|
|
|
@ -189,9 +189,9 @@ fn virtual_with_specific() {
|
|||
.file(
|
||||
"a/src/lib.rs",
|
||||
r#"
|
||||
#[cfg(not_feature = "f1")]
|
||||
#[cfg(not(feature = "f1"))]
|
||||
compile_error!{"f1 is missing"}
|
||||
#[cfg(not_feature = "f2")]
|
||||
#[cfg(not(feature = "f2"))]
|
||||
compile_error!{"f2 is missing"}
|
||||
"#,
|
||||
)
|
||||
|
@ -211,9 +211,9 @@ fn virtual_with_specific() {
|
|||
.file(
|
||||
"b/src/lib.rs",
|
||||
r#"
|
||||
#[cfg(not_feature = "f2")]
|
||||
#[cfg(not(feature = "f2"))]
|
||||
compile_error!{"f2 is missing"}
|
||||
#[cfg(not_feature = "f3")]
|
||||
#[cfg(not(feature = "f3"))]
|
||||
compile_error!{"f3 is missing"}
|
||||
"#,
|
||||
)
|
||||
|
|
|
@ -32,7 +32,7 @@ fn profile_overrides() {
|
|||
[RUNNING] `rustc --crate-name test --edition=2015 src/lib.rs [..]--crate-type lib \
|
||||
--emit=[..]link[..]\
|
||||
-C opt-level=1[..]\
|
||||
-C debug-assertions=on \
|
||||
-C debug-assertions=on[..] \
|
||||
-C metadata=[..] \
|
||||
-C rpath \
|
||||
--out-dir [..] \
|
||||
|
@ -141,7 +141,7 @@ fn check_opt_level_override(profile_level: &str, rustc_level: &str) {
|
|||
--emit=[..]link \
|
||||
-C opt-level={level}[..]\
|
||||
-C debuginfo=2 [..]\
|
||||
-C debug-assertions=on \
|
||||
-C debug-assertions=on[..] \
|
||||
-C metadata=[..] \
|
||||
--out-dir [..] \
|
||||
-L dependency=[CWD]/target/debug/deps`
|
||||
|
|
|
@ -41,7 +41,7 @@ fn lib() {
|
|||
[COMPILING] foo v0.0.1 ([CWD])
|
||||
[RUNNING] `rustc --crate-name foo --edition=2015 src/lib.rs [..]--crate-type lib \
|
||||
--emit=[..]link[..]-C debuginfo=2 [..]\
|
||||
-C debug-assertions=off \
|
||||
-C debug-assertions=off[..]\
|
||||
-C metadata=[..] \
|
||||
--out-dir [..] \
|
||||
-L dependency=[CWD]/target/debug/deps`
|
||||
|
@ -69,7 +69,7 @@ fn build_main_and_allow_unstable_options() {
|
|||
-L dependency=[CWD]/target/debug/deps`
|
||||
[RUNNING] `rustc --crate-name {name} --edition=2015 src/main.rs [..]--crate-type bin \
|
||||
--emit=[..]link[..]-C debuginfo=2 [..]\
|
||||
-C debug-assertions \
|
||||
-C debug-assertions[..]\
|
||||
-C metadata=[..] \
|
||||
--out-dir [..] \
|
||||
-L dependency=[CWD]/target/debug/deps \
|
||||
|
|
|
@ -1530,6 +1530,7 @@ fn two_matching_in_config() {
|
|||
.file(
|
||||
"src/main.rs",
|
||||
r#"
|
||||
#![allow(unexpected_cfgs)]
|
||||
fn main() {
|
||||
if cfg!(foo = "a") {
|
||||
println!("a");
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::fmt::Write;
|
|||
// Helper to create lib.rs files that check features.
|
||||
fn require(enabled_features: &[&str], disabled_features: &[&str]) -> String {
|
||||
let mut s = String::new();
|
||||
writeln!(s, "#![allow(unexpected_cfgs)]").unwrap();
|
||||
for feature in enabled_features {
|
||||
writeln!(s, "#[cfg(not(feature=\"{feature}\"))] compile_error!(\"expected feature {feature} to be enabled\");",
|
||||
feature=feature).unwrap();
|
||||
|
|
Loading…
Reference in a new issue