mirror of
https://github.com/rust-lang/cargo
synced 2024-08-25 10:35:53 +00:00
Stabilize rust-version
This commit is contained in:
parent
db3776cfef
commit
d783456598
|
@ -395,7 +395,7 @@ features! {
|
|||
(unstable, strip, "", "reference/unstable.html#profile-strip-option"),
|
||||
|
||||
// Specifying a minimal 'rust-version' attribute for crates
|
||||
(unstable, rust_version, "", "reference/unstable.html#rust-version"),
|
||||
(stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"),
|
||||
|
||||
// Support for 2021 edition.
|
||||
(unstable, edition2021, "", "reference/unstable.html#edition-2021"),
|
||||
|
|
|
@ -218,7 +218,7 @@ pub trait AppExt: Sized {
|
|||
fn arg_ignore_rust_version(self) -> Self {
|
||||
self._arg(opt(
|
||||
"ignore-rust-version",
|
||||
"Ignore `rust-version` specification in packages (unstable)",
|
||||
"Ignore `rust-version` specification in packages",
|
||||
))
|
||||
}
|
||||
|
||||
|
@ -533,12 +533,6 @@ pub trait ArgMatchesExt {
|
|||
honor_rust_version: !self._is_present("ignore-rust-version"),
|
||||
};
|
||||
|
||||
if !opts.honor_rust_version {
|
||||
config
|
||||
.cli_unstable()
|
||||
.fail_if_stable_opt("--ignore-rust-version", 8072)?;
|
||||
}
|
||||
|
||||
if let Some(ws) = workspace {
|
||||
self.check_optional_opts(ws, &opts)?;
|
||||
} else if self.is_present_with_zero_values("package") {
|
||||
|
|
|
@ -1122,46 +1122,25 @@ impl TomlManifest {
|
|||
}
|
||||
|
||||
let rust_version = if let Some(rust_version) = &project.rust_version {
|
||||
if features.require(Feature::rust_version()).is_err() {
|
||||
let mut msg =
|
||||
"`rust-version` is not supported on this version of Cargo and will be ignored"
|
||||
.to_string();
|
||||
if config.nightly_features_allowed {
|
||||
msg.push_str(
|
||||
"\n\n\
|
||||
consider adding `cargo-features = [\"rust-version\"]` to the manifest",
|
||||
);
|
||||
} else {
|
||||
msg.push_str(
|
||||
"\n\n\
|
||||
this Cargo does not support nightly features, but if you\n\
|
||||
switch to nightly channel you can add\n\
|
||||
`cargo-features = [\"rust-version\"]` to enable this feature",
|
||||
);
|
||||
let req = match semver::VersionReq::parse(rust_version) {
|
||||
// Exclude semver operators like `^` and pre-release identifiers
|
||||
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
|
||||
_ => bail!("`rust-version` must be a value like \"1.32\""),
|
||||
};
|
||||
if let Some(first_version) = edition.first_version() {
|
||||
let unsupported =
|
||||
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
|
||||
if req.matches(&unsupported) {
|
||||
bail!(
|
||||
"rust-version {} is older than first version ({}) required by \
|
||||
the specified edition ({})",
|
||||
rust_version,
|
||||
first_version,
|
||||
edition,
|
||||
)
|
||||
}
|
||||
warnings.push(msg);
|
||||
None
|
||||
} else {
|
||||
let req = match semver::VersionReq::parse(rust_version) {
|
||||
// Exclude semver operators like `^` and pre-release identifiers
|
||||
Ok(req) if rust_version.chars().all(|c| c.is_ascii_digit() || c == '.') => req,
|
||||
_ => bail!("`rust-version` must be a value like \"1.32\""),
|
||||
};
|
||||
if let Some(first_version) = edition.first_version() {
|
||||
let unsupported =
|
||||
semver::Version::new(first_version.major, first_version.minor - 1, 9999);
|
||||
if req.matches(&unsupported) {
|
||||
bail!(
|
||||
"rust-version {} is older than first version ({}) required by \
|
||||
the specified edition ({})",
|
||||
rust_version,
|
||||
first_version,
|
||||
edition,
|
||||
)
|
||||
}
|
||||
}
|
||||
Some(rust_version.clone())
|
||||
}
|
||||
Some(rust_version.clone())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
|
|
@ -89,7 +89,6 @@ Each new feature described below should explain how to use it.
|
|||
* [Custom named profiles](#custom-named-profiles) — Adds custom named profiles in addition to the standard names.
|
||||
* [Profile `strip` option](#profile-strip-option) — Forces the removal of debug information and symbols from executables.
|
||||
* [per-package-target](#per-package-target) — Sets the `--target` to use for each individual package.
|
||||
* [rust-version](#rust-version) — Allows to declare the minimum supported Rust version.
|
||||
* [Edition 2021](#edition-2021) — Adds support for the 2021 Edition.
|
||||
* Information and metadata
|
||||
* [Build-plan](#build-plan) — Emits JSON information on which commands will be run.
|
||||
|
@ -1170,25 +1169,6 @@ cargo logout -Z credential-process
|
|||
[crates.io]: https://crates.io/
|
||||
[config file]: config.md
|
||||
|
||||
### rust-version
|
||||
* RFC: [#2495](https://github.com/rust-lang/rfcs/blob/master/text/2495-min-rust-version.md)
|
||||
* rustc Tracking Issue: [#65262](https://github.com/rust-lang/rust/issues/65262)
|
||||
|
||||
The `-Z rust-version` flag enables the reading of the `rust-version` field in the
|
||||
Cargo manifest `package` section. This can be used by a package to state a minimal
|
||||
version of the compiler required to build the package. An error is generated if
|
||||
the version of rustc is older than the stated `rust-version`. The
|
||||
`--ignore-rust-version` flag can be used to override the check.
|
||||
|
||||
```toml
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[package]
|
||||
name = "mypackage"
|
||||
version = "0.0.1"
|
||||
rust-version = "1.42"
|
||||
```
|
||||
|
||||
### edition 2021
|
||||
* Tracking Issue: [rust-lang/rust#85811](https://github.com/rust-lang/rust/issues/85811)
|
||||
|
||||
|
|
|
@ -2,58 +2,12 @@
|
|||
|
||||
use cargo_test_support::{project, registry::Package};
|
||||
|
||||
#[cargo_test]
|
||||
fn rust_version_gated() {
|
||||
project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
rust-version = "1.9999"
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_stderr_contains(
|
||||
"warning: `rust-version` is not supported on this version of Cargo and will be ignored\
|
||||
\n\nconsider adding `cargo-features = [\"rust-version\"]` to the manifest",
|
||||
)
|
||||
.run();
|
||||
|
||||
project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
[package]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
rust-version = "1.9999"
|
||||
"#,
|
||||
)
|
||||
.file("src/lib.rs", "")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.with_stderr_contains(
|
||||
"warning: `rust-version` is not supported on this version of Cargo and will be ignored\
|
||||
\n\nthis Cargo does not support nightly features, but if you\n\
|
||||
switch to nightly channel you can add\n\
|
||||
`cargo-features = [\"rust-version\"]` to enable this feature",
|
||||
)
|
||||
.run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn rust_version_satisfied() {
|
||||
let p = project()
|
||||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -66,10 +20,8 @@ fn rust_version_satisfied() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build();
|
||||
|
||||
p.cargo("build").masquerade_as_nightly_cargo().run();
|
||||
p.cargo("build --ignore-rust-version -Zunstable-options")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.run();
|
||||
p.cargo("build").run();
|
||||
p.cargo("build --ignore-rust-version").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
@ -78,8 +30,6 @@ fn rust_version_bad_caret() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -92,7 +42,6 @@ fn rust_version_bad_caret() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"error: failed to parse manifest at `[..]`\n\n\
|
||||
|
@ -107,8 +56,6 @@ fn rust_version_bad_pre_release() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -121,7 +68,6 @@ fn rust_version_bad_pre_release() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"error: failed to parse manifest at `[..]`\n\n\
|
||||
|
@ -136,8 +82,6 @@ fn rust_version_bad_nonsense() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -150,7 +94,6 @@ fn rust_version_bad_nonsense() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"error: failed to parse manifest at `[..]`\n\n\
|
||||
|
@ -165,8 +108,6 @@ fn rust_version_too_high() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -180,22 +121,18 @@ fn rust_version_too_high() {
|
|||
.build();
|
||||
|
||||
p.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
"error: package `foo v0.0.1 ([..])` cannot be built because it requires \
|
||||
rustc 1.9876.0 or newer, while the currently active rustc version is [..]",
|
||||
)
|
||||
.run();
|
||||
p.cargo("build --ignore-rust-version -Zunstable-options")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.run();
|
||||
p.cargo("build --ignore-rust-version").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
fn rust_version_dependency_fails() {
|
||||
Package::new("bar", "0.0.1")
|
||||
.cargo_feature("rust-version")
|
||||
.rust_version("1.2345.0")
|
||||
.file("src/lib.rs", "fn other_stuff() {}")
|
||||
.publish();
|
||||
|
@ -216,7 +153,6 @@ fn rust_version_dependency_fails() {
|
|||
.build();
|
||||
|
||||
p.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr(
|
||||
" Updating `[..]` index\n \
|
||||
|
@ -226,9 +162,7 @@ fn rust_version_dependency_fails() {
|
|||
rustc 1.2345.0 or newer, while the currently active rustc version is [..]",
|
||||
)
|
||||
.run();
|
||||
p.cargo("build --ignore-rust-version -Zunstable-options")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.run();
|
||||
p.cargo("build --ignore-rust-version").run();
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
@ -237,8 +171,6 @@ fn rust_version_older_than_edition() {
|
|||
.file(
|
||||
"Cargo.toml",
|
||||
r#"
|
||||
cargo-features = ["rust-version"]
|
||||
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.0.1"
|
||||
|
@ -252,7 +184,6 @@ fn rust_version_older_than_edition() {
|
|||
.file("src/main.rs", "fn main() {}")
|
||||
.build()
|
||||
.cargo("build")
|
||||
.masquerade_as_nightly_cargo()
|
||||
.with_status(101)
|
||||
.with_stderr_contains(" rust-version 1.1 is older than first version (1.31.0) required by the specified edition (2018)",
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue