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

[Ignore this] Implement min-rust-version support (in cargo build, resolver support). #7801

Closed
wants to merge 5 commits into from
Closed
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
9 changes: 9 additions & 0 deletions crates/cargo-test-support/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub struct Package {
local: bool,
alternative: bool,
invalid_json: bool,
min_rust_version: Option<String>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -242,6 +243,7 @@ impl Package {
local: false,
alternative: false,
invalid_json: false,
min_rust_version: None,
}
}

Expand Down Expand Up @@ -359,6 +361,12 @@ impl Package {
self
}

/// Sets min_rust_version.
pub fn min_rust_version(&mut self, min_rust_version: Option<String>) -> &mut Package {
self.min_rust_version = min_rust_version;
self
}

/// Creates the package and place it in the registry.
///
/// This does not actually use Cargo's publishing system, but instead
Expand Down Expand Up @@ -413,6 +421,7 @@ impl Package {
"cksum": cksum,
"features": self.features,
"yanked": self.yanked,
"min_rust_version": self.min_rust_version,
})
.to_string();

Expand Down
5 changes: 5 additions & 0 deletions crates/resolver-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ pub fn resolve_with_config_raw(
&BTreeMap::<String, Vec<String>>::new(),
None::<&String>,
false,
None,
)
.unwrap();
let opts = ResolveOpts::everything();
Expand All @@ -187,6 +188,7 @@ pub fn resolve_with_config_raw(
&HashSet::new(),
config,
true,
None,
);

// The largest test in our suite takes less then 30 sec.
Expand Down Expand Up @@ -577,6 +579,7 @@ pub fn pkg_dep<T: ToPkgId>(name: T, dep: Vec<Dependency>) -> Summary {
&BTreeMap::<String, Vec<String>>::new(),
link,
false,
None,
)
.unwrap()
}
Expand Down Expand Up @@ -605,6 +608,7 @@ pub fn pkg_loc(name: &str, loc: &str) -> Summary {
&BTreeMap::<String, Vec<String>>::new(),
link,
false,
None,
)
.unwrap()
}
Expand All @@ -619,6 +623,7 @@ pub fn remove_dep(sum: &Summary, ind: usize) -> Summary {
&BTreeMap::<String, Vec<String>>::new(),
sum.links().map(|a| a.as_str()),
sum.namespaced_features(),
sum.min_rust_version().map(|v| v.clone()),
)
.unwrap()
}
Expand Down
2 changes: 2 additions & 0 deletions crates/resolver-tests/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ proptest! {
false,
false,
false,
true,
&None,
&["minimal-versions".to_string()],
&[],
Expand Down Expand Up @@ -574,6 +575,7 @@ fn test_resolving_minimum_version_with_transitive_deps() {
false,
false,
false,
true,
&None,
&["minimal-versions".to_string()],
&[],
Expand Down
2 changes: 2 additions & 0 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ fn config_configure(
} else {
None
};
let ignore_rust_version = subcommand_args.is_present("ignore-min-rust-version");
config.configure(
args.occurrences_of("verbose") as u32,
quiet,
args.value_of("color"),
args.is_present("frozen"),
args.is_present("locked"),
args.is_present("offline"),
!ignore_rust_version,
arg_target_dir,
&args
.values_of_lossy("unstable-features")
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn cli() -> App {
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_manifest_path()
.arg_ignore_min_rust_version()
.arg_message_format()
.arg(opt(
"no-fail-fast",
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn cli() -> App {
.value_name("PATH"),
)
.arg_manifest_path()
.arg_ignore_min_rust_version()
.arg_message_format()
.arg_build_plan()
.after_help(
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn cli() -> App {
.arg_target_triple("Check for the target triple")
.arg_target_dir()
.arg_manifest_path()
.arg_ignore_min_rust_version()
.arg_message_format()
.after_help(
"\
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn cli() -> App {
.arg_target_triple("Build for the target triple")
.arg_target_dir()
.arg_manifest_path()
.arg_ignore_min_rust_version()
.arg_message_format()
.after_help(
"\
Expand Down
1 change: 1 addition & 0 deletions src/bin/cargo/commands/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn cli() -> App {
.arg_dry_run("Don't actually write the lockfile")
.arg(opt("precise", "Update a single dependency to exactly PRECISE").value_name("PRECISE"))
.arg_manifest_path()
.arg_ignore_min_rust_version()
.after_help(
"\
This command requires that a `Cargo.lock` already exists as generated by
Expand Down
16 changes: 12 additions & 4 deletions src/cargo/core/resolver/dep_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,23 @@ impl<'a> RegistryQueryer<'a> {
/// any candidates are returned which match an override then the override is
/// applied by performing a second query for what the override should
/// return.
pub fn query(&mut self, dep: &Dependency) -> CargoResult<Rc<Vec<Summary>>> {
pub fn query(
&mut self,
dep: &Dependency,
active_rust_version: Option<&semver::Version>,
) -> CargoResult<Rc<Vec<Summary>>> {
if let Some(out) = self.registry_cache.get(dep).cloned() {
return Ok(out);
}

let mut ret = Vec::new();
self.registry.query(
dep,
&mut |s| {
ret.push(s);
&mut |summary| {
if !summary.compatible_with_rust_version(active_rust_version) {
return;
}
ret.push(summary);
},
false,
)?;
Expand Down Expand Up @@ -200,6 +207,7 @@ impl<'a> RegistryQueryer<'a> {
parent: Option<PackageId>,
candidate: &Summary,
opts: &ResolveOpts,
active_rust_version: Option<&semver::Version>,
) -> ActivateResult<Rc<(HashSet<InternedString>, Rc<Vec<DepInfo>>)>> {
// if we have calculated a result before, then we can just return it,
// as it is a "pure" query of its arguments.
Expand All @@ -220,7 +228,7 @@ impl<'a> RegistryQueryer<'a> {
let mut deps = deps
.into_iter()
.map(|(dep, features)| {
let candidates = self.query(&dep)?;
let candidates = self.query(&dep, active_rust_version)?;
Ok((dep, candidates, features))
})
.collect::<CargoResult<Vec<DepInfo>>>()?;
Expand Down
Loading