Skip to content

Commit

Permalink
Add rust_version field to Package.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Oct 24, 2021
1 parent 409729e commit 1ca3f6c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use std::process::Command;
use std::str::from_utf8;

pub use camino;
pub use semver::Version;
pub use semver::{Version, VersionReq};

pub use dependency::{Dependency, DependencyKind};
use diagnostic::Diagnostic;
Expand Down Expand Up @@ -349,6 +349,10 @@ pub struct Package {
///
/// This is always `None` if running with a version of Cargo older than 1.55.
pub default_run: Option<String>,
/// The minimum supported Rust version of this package.
///
/// This is always `None` if running with a version of Cargo older than 1.58.
pub rust_version: Option<VersionReq>,
}

impl Package {
Expand Down
1 change: 1 addition & 0 deletions tests/all/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ documentation = "https://docs.rs/cargo_metadata/"
links = "foo"
publish = false
default-run = "otherbin"
rust-version = "1.56"

[package.metadata.docs.rs]
all-features = true
Expand Down
12 changes: 10 additions & 2 deletions tests/test_samples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ fn old_minimal() {
assert_eq!(pkg.license, None);
assert_eq!(pkg.license_file, None);
assert_eq!(pkg.default_run, None);
assert_eq!(pkg.rust_version, None);
assert_eq!(pkg.dependencies.len(), 1);
let dep = &pkg.dependencies[0];
assert_eq!(dep.name, "somedep");
Expand Down Expand Up @@ -157,10 +158,10 @@ struct TestObject {

#[test]
fn all_the_fields() {
// All the fields currently generated as of 1.55. This tries to exercise as
// All the fields currently generated as of 1.58. This tries to exercise as
// much as possible.
let ver = cargo_version();
let minimum = semver::Version::parse("1.55.0").unwrap();
let minimum = semver::Version::parse("1.56.0").unwrap();
if ver < minimum {
// edition added in 1.30
// rename added in 1.31
Expand All @@ -174,6 +175,7 @@ fn all_the_fields() {
// doc added in 1.50
// path added in 1.51
// default_run added in 1.55
// rust_version added in 1.58
eprintln!("Skipping all_the_fields test, cargo {} is too old.", ver);
return;
}
Expand Down Expand Up @@ -205,6 +207,12 @@ fn all_the_fields() {
assert_eq!(all.publish, Some(vec![]));
assert_eq!(all.links, Some("foo".to_string()));
assert_eq!(all.default_run, Some("otherbin".to_string()));
if ver >= semver::Version::parse("1.58.0").unwrap() {
assert_eq!(
all.rust_version,
Some(semver::VersionReq::parse("1.56").unwrap())
);
}

assert_eq!(all.dependencies.len(), 8);
let bitflags = all
Expand Down

0 comments on commit 1ca3f6c

Please sign in to comment.