Skip to content

Commit 8e075c9

Browse files
committed
Auto merge of #8037 - djc:rfc-2495, r=ehuss
Implement support for rust-version field in project metadata Needs a bunch more work, but I'd like some early feedback! Remaining work: - [x] Bikeshedding name (picked `rust-version` here over `msrv` or `min-rust-version`) - [x] Failing test for local dependency with unsatisfied MSRV - [x] Requirement cannot be smaller than 1.27 - [x] Requirement cannot be smaller than initial release of edition used - [x] Check for `run`, `verify` and `publish` subcommands - [x] More tests (would love feedback on this) - [x] Handle pre-release identifiers - [x] Disallow semver range operators - [x] Feature gate it - [x] Add documentation for unstable feature Minimal version of `@moxian's` earlier take in #7801. cc rust-lang/rust#65262
2 parents c524fa4 + c221fec commit 8e075c9

File tree

22 files changed

+447
-8
lines changed

22 files changed

+447
-8
lines changed

crates/cargo-test-support/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ lazy_static = "1.0"
1919
remove_dir_all = "0.5"
2020
serde_json = "1.0"
2121
tar = { version = "0.4.18", default-features = false }
22+
toml = "0.5.7"
2223
url = "2.0"

crates/cargo-test-support/src/registry.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ pub struct Package {
146146
invalid_json: bool,
147147
proc_macro: bool,
148148
links: Option<String>,
149+
rust_version: Option<String>,
150+
cargo_features: Vec<String>,
149151
}
150152

151153
#[derive(Clone)]
@@ -247,6 +249,8 @@ impl Package {
247249
invalid_json: false,
248250
proc_macro: false,
249251
links: None,
252+
rust_version: None,
253+
cargo_features: Vec::new(),
250254
}
251255
}
252256

@@ -363,6 +367,12 @@ impl Package {
363367
self
364368
}
365369

370+
/// Specify a minimal Rust version.
371+
pub fn rust_version(&mut self, rust_version: &str) -> &mut Package {
372+
self.rust_version = Some(rust_version.into());
373+
self
374+
}
375+
366376
/// Causes the JSON line emitted in the index to be invalid, presumably
367377
/// causing Cargo to skip over this version.
368378
pub fn invalid_json(&mut self, invalid: bool) -> &mut Package {
@@ -375,6 +385,11 @@ impl Package {
375385
self
376386
}
377387

388+
pub fn cargo_feature(&mut self, feature: &str) -> &mut Package {
389+
self.cargo_features.push(feature.to_owned());
390+
self
391+
}
392+
378393
/// Creates the package and place it in the registry.
379394
///
380395
/// This does not actually use Cargo's publishing system, but instead
@@ -502,15 +517,29 @@ impl Package {
502517
}
503518

504519
fn append_manifest<W: Write>(&self, ar: &mut Builder<W>) {
505-
let mut manifest = format!(
520+
let mut manifest = String::new();
521+
522+
if !self.cargo_features.is_empty() {
523+
manifest.push_str(&format!(
524+
"cargo-features = {}\n\n",
525+
toml::to_string(&self.cargo_features).unwrap()
526+
));
527+
}
528+
529+
manifest.push_str(&format!(
506530
r#"
507531
[package]
508532
name = "{}"
509533
version = "{}"
510534
authors = []
511535
"#,
512536
self.name, self.vers
513-
);
537+
));
538+
539+
if let Some(version) = &self.rust_version {
540+
manifest.push_str(&format!("rust-version = \"{}\"", version));
541+
}
542+
514543
for dep in self.deps.iter() {
515544
let target = match dep.target {
516545
None => String::new(),

src/bin/cargo/commands/bench.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn cli() -> App {
3939
.arg_target_triple("Build for the target triple")
4040
.arg_target_dir()
4141
.arg_manifest_path()
42+
.arg_ignore_rust_version()
4243
.arg_message_format()
4344
.arg(opt(
4445
"no-fail-fast",

src/bin/cargo/commands/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub fn cli() -> App {
3939
.value_name("PATH"),
4040
)
4141
.arg_manifest_path()
42+
.arg_ignore_rust_version()
4243
.arg_message_format()
4344
.arg_build_plan()
4445
.arg_unit_graph()

src/bin/cargo/commands/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub fn cli() -> App {
3232
.arg_target_triple("Check for the target triple")
3333
.arg_target_dir()
3434
.arg_manifest_path()
35+
.arg_ignore_rust_version()
3536
.arg_message_format()
3637
.arg_unit_graph()
3738
.after_help("Run `cargo help check` for more detailed information.\n")

src/bin/cargo/commands/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn cli() -> App {
3030
.arg_target_dir()
3131
.arg_manifest_path()
3232
.arg_message_format()
33+
.arg_ignore_rust_version()
3334
.arg_unit_graph()
3435
.after_help("Run `cargo help doc` for more detailed information.\n")
3536
}

src/bin/cargo/commands/fix.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn cli() -> App {
7272
.long("allow-staged")
7373
.help("Fix code even if the working directory has staged changes"),
7474
)
75+
.arg_ignore_rust_version()
7576
.after_help("Run `cargo help fix` for more detailed information.\n")
7677
}
7778

src/bin/cargo/commands/run.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn cli() -> App {
2626
.arg_manifest_path()
2727
.arg_message_format()
2828
.arg_unit_graph()
29+
.arg_ignore_rust_version()
2930
.after_help("Run `cargo help run` for more detailed information.\n")
3031
}
3132

src/bin/cargo/commands/rustc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub fn cli() -> App {
3030
.arg_manifest_path()
3131
.arg_message_format()
3232
.arg_unit_graph()
33+
.arg_ignore_rust_version()
3334
.after_help("Run `cargo help rustc` for more detailed information.\n")
3435
}
3536

src/bin/cargo/commands/rustdoc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ pub fn cli() -> App {
3434
.arg_manifest_path()
3535
.arg_message_format()
3636
.arg_unit_graph()
37+
.arg_ignore_rust_version()
3738
.after_help("Run `cargo help rustdoc` for more detailed information.\n")
3839
}
3940

0 commit comments

Comments
 (0)