Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize the rust-version field #9732

Merged
merged 3 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

### Added

- Added support for the [`rust-version`](https://doc.rust-lang.org/nightly/cargo/reference/manifest.html#the-rust-version-field)
field in a crate's metadata and the `--ignore-rust-version` command line option.
- Build scripts can now pass additional linker arguments for binaries or all
linkable targets. [docs](https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#outputs-of-the-build-script)
[#9557](https://github.com/rust-lang/cargo/pull/9557)
Expand Down
5 changes: 2 additions & 3 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ impl Edition {
match self {
Edition2015 => None,
Edition2018 => Some(semver::Version::new(1, 31, 0)),
// FIXME: This will likely be 1.56, update when that seems more likely.
Edition2021 => Some(semver::Version::new(1, 62, 0)),
Edition2021 => Some(semver::Version::new(1, 56, 0)),
}
}

Expand Down Expand Up @@ -396,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"),
djc marked this conversation as resolved.
Show resolved Hide resolved
(stable, rust_version, "1.56", "reference/manifest.html#the-rust-version-field"),

// Support for 2021 edition.
(unstable, edition2021, "", "reference/unstable.html#edition-2021"),
Expand Down
8 changes: 1 addition & 7 deletions src/cargo/util/command_prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
))
}

Expand Down Expand Up @@ -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") {
Expand Down
55 changes: 17 additions & 38 deletions src/cargo/util/toml/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
);
}
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,
)
}
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
};
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ target.

{{> options-target-triple }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ they have `required-features` that are missing.

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ they have `required-features` that are missing.

{{> options-profile }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ flag and will always document the given target.

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ When no target selection options are given, `cargo fix` will fix all targets

{{> options-profile }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Run the specified example.

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ binary and library targets of the selected package.

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-rustdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ if its name is the same as the lib target. Binaries are skipped if they have

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
2 changes: 2 additions & 0 deletions src/doc/man/cargo-test.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ target options.

{{> options-release }}

{{> options-ignore-rust-version }}

{{/options}}

### Output Options
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-bench.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ OPTIONS
<https://doc.rust-lang.org/cargo/guide/build-cache.html>
documentation for more details.

--ignore-rust-version
Benchmark the target even if the selected Rust compiler is older
than the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ OPTIONS
Build optimized artifacts with the release profile. See the PROFILES
section for details on how this affects profile selection.

--ignore-rust-version
Build the target even if the selected Rust compiler is older than
the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-check.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ OPTIONS
have it check unit tests which are usually excluded via the cfg
attribute. This does not change the actual profile used.

--ignore-rust-version
Check the target even if the selected Rust compiler is older than
the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ OPTIONS
Document optimized artifacts with the release profile. See the
PROFILES section for details on how this affects profile selection.

--ignore-rust-version
Document the target even if the selected Rust compiler is older than
the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-fix.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ OPTIONS
it fix unit tests which are usually excluded via the cfg attribute.
This does not change the actual profile used.

--ignore-rust-version
Fix the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's rust-version
field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-run.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ OPTIONS
Run optimized artifacts with the release profile. See the PROFILES
section for details on how this affects profile selection.

--ignore-rust-version
Run the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's rust-version
field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-rustc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ OPTIONS
Build optimized artifacts with the release profile. See the PROFILES
section for details on how this affects profile selection.

--ignore-rust-version
Build the target even if the selected Rust compiler is older than
the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-rustdoc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ OPTIONS
Document optimized artifacts with the release profile. See the
PROFILES section for details on how this affects profile selection.

--ignore-rust-version
Document the target even if the selected Rust compiler is older than
the required Rust version as configured in the project's
rust-version field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
5 changes: 5 additions & 0 deletions src/doc/man/generated_txt/cargo-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ OPTIONS
Test optimized artifacts with the release profile. See the PROFILES
section for details on how this affects profile selection.

--ignore-rust-version
Test the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's rust-version
field.

Output Options
--target-dir directory
Directory for all generated artifacts and intermediate files. May
Expand Down
4 changes: 4 additions & 0 deletions src/doc/man/includes/options-ignore-rust-version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{#option "`--ignore-rust-version`"}}
{{actionverb}} the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's `rust-version` field.
{{/option}}
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-bench.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ target artifacts are placed in a separate directory. See the



<dt class="option-term" id="option-cargo-bench---ignore-rust-version"><a class="option-anchor" href="#option-cargo-bench---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Benchmark the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ selection.</dd>



<dt class="option-term" id="option-cargo-build---ignore-rust-version"><a class="option-anchor" href="#option-cargo-build---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Build the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ used.</dd>



<dt class="option-term" id="option-cargo-check---ignore-rust-version"><a class="option-anchor" href="#option-cargo-check---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Check the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ selection.</dd>



<dt class="option-term" id="option-cargo-doc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-doc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Document the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,12 @@ used.</dd>



<dt class="option-term" id="option-cargo-fix---ignore-rust-version"><a class="option-anchor" href="#option-cargo-fix---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Fix the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-run.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ selection.</dd>



<dt class="option-term" id="option-cargo-run---ignore-rust-version"><a class="option-anchor" href="#option-cargo-run---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Run the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
6 changes: 6 additions & 0 deletions src/doc/src/commands/cargo-rustc.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ selection.</dd>



<dt class="option-term" id="option-cargo-rustc---ignore-rust-version"><a class="option-anchor" href="#option-cargo-rustc---ignore-rust-version"></a><code>--ignore-rust-version</code></dt>
<dd class="option-desc">Build the target even if the selected Rust compiler is older than the
required Rust version as configured in the project's <code>rust-version</code> field.</dd>



</dl>

### Output Options
Expand Down
Loading