mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00

feat(resolver): `-Zdirect-minimal-versions` This is an alternative to `-Zminimal-versions` as discussed in #5657. Problems with `-Zminimal-versions` includes - Requires the root most dependencies to verify it and we then percolate that up the stack. This requires a massive level of cooperation to accomplish and so far there have been mixed results with it to the point that cargo's unstable documentation discourages its use. - Users expect `cargo check -Zminimal-versions` to force resolving to minimal but it doesn't as the default maximal resolve is compatible and requires `cargo update -Zminimal-versions` - Different compatible versions might be selected, breaking interop between crates, changing feature unification, and breaking `-sys` crates without bad `links` `-Zdirect-minimal-versions` instead only applies this rule to your direct dependencies, allowing anyone in the stack to immediately adopt it, independent of everyone else. Special notes - Living up to the name and the existing design, this ignores yanked crates. This makes sense for `^1.1` version requirements but might look weird for `^1.1.1` version requirements as it could select `1.1.2`. - This will error if an indirect dependency requires a newer version. Your version requirement will need to capture what you use **and** all of you dependencies. An alternative design would have tried to merge the result of minimum versions for direct dependencies and maximum versions for indirect dependencies. This would have been complex and led to weird corner cases, making it harder to predict. I also suspect the value gained would be relatively low as you can't verify that version requirement in any other way. - This also means discrepancies between `dependencies` and `dev-dependencies` are errors - The error could be improved to call out that this was from minimal versions but I felt getting this out now and starting to collect feedback was more important. One advantage of this approach over `-Zminimal-versions` is that it removes most of the problems that [cargo-minimal-versions](https://github.com/taiki-e/cargo-minimal-versions) tried to workaround. As for the implementation, this might not be the most elegant solution but it works and we can always iterate and improve on it in the future. - We keep the state as a `bool` throughout but compensate for that by explicitly creating a variable to abstract away constants - The name changes depending on the context, from `direct_minimal_version` when dealing with the unstable flag to `first_minimal_version` when the concept of "direct" is lost to `first_version` when we split off the ordering concept into a separate variable - Packages that respect `direct_minimal_versions` are determined by whether they are the top-level `summaries` that get past into `resolve` ### What does this PR try to resolve? The primary use case is verifying version requirements to avoid depending on something newer than might be available in a dependent For this to help the MSRV use case, the crate author must directly depend on all indirect dependencies where their latest release has too new of an MSRV but at least they can do so with the `^` operator, rather than `<` and breaking the ecosystem. ### How should we test and review this PR? The first two commits add tests using `-Zminimal-versions`. The commit that adds `-Zdirect-minimal-versions` updates the tests, highlighting the differences in behavior. ### Additional information Potential areas of conversation for stablization - Flag name - Handling of yanked (pick first non-yanked, pick yanked, error) - Quality of error message - Should the package have a "memory" of this flag being set by writing it to the lockfile? Potential future work - Stablize this - Remove `-Zminimal-versions` - Update `cargo publish`s `--verify` step to use this. - The challenge is this won't be using the packaged `Cargo.lock` which probably should also be verified.
195 lines
3.9 KiB
Rust
195 lines
3.9 KiB
Rust
// See src/cargo/lib.rs for notes on these lint settings.
|
|
#![warn(rust_2018_idioms)]
|
|
#![allow(clippy::all)]
|
|
|
|
#[macro_use]
|
|
extern crate cargo_test_macro;
|
|
|
|
mod advanced_env;
|
|
mod alt_registry;
|
|
mod artifact_dep;
|
|
mod bad_config;
|
|
mod bad_manifest_path;
|
|
mod bench;
|
|
mod binary_name;
|
|
mod build;
|
|
mod build_plan;
|
|
mod build_script;
|
|
mod build_script_env;
|
|
mod build_script_extra_link_arg;
|
|
mod cache_messages;
|
|
mod cargo_add;
|
|
mod cargo_alias_config;
|
|
mod cargo_command;
|
|
mod cargo_config;
|
|
mod cargo_env_config;
|
|
mod cargo_features;
|
|
mod cargo_remove;
|
|
mod cargo_targets;
|
|
mod cfg;
|
|
mod check;
|
|
mod check_cfg;
|
|
mod clean;
|
|
mod collisions;
|
|
mod concurrent;
|
|
mod config;
|
|
mod config_cli;
|
|
mod config_include;
|
|
mod corrupt_git;
|
|
mod credential_process;
|
|
mod cross_compile;
|
|
mod cross_publish;
|
|
mod custom_target;
|
|
mod death;
|
|
mod dep_info;
|
|
mod direct_minimal_versions;
|
|
mod directory;
|
|
mod doc;
|
|
mod docscrape;
|
|
mod edition;
|
|
mod error;
|
|
mod features;
|
|
mod features2;
|
|
mod features_namespaced;
|
|
mod fetch;
|
|
mod fix;
|
|
mod freshness;
|
|
mod future_incompat_report;
|
|
mod generate_lockfile;
|
|
mod git;
|
|
mod git_auth;
|
|
mod git_gc;
|
|
mod glob_targets;
|
|
mod help;
|
|
mod https;
|
|
mod inheritable_workspace_fields;
|
|
mod init;
|
|
mod install;
|
|
mod install_upgrade;
|
|
mod jobserver;
|
|
mod list_availables;
|
|
mod local_registry;
|
|
mod locate_project;
|
|
mod lockfile_compat;
|
|
mod login;
|
|
mod logout;
|
|
mod lto;
|
|
mod member_discovery;
|
|
mod member_errors;
|
|
mod message_format;
|
|
mod messages;
|
|
mod metabuild;
|
|
mod metadata;
|
|
mod minimal_versions;
|
|
mod multitarget;
|
|
mod net_config;
|
|
mod new;
|
|
mod offline;
|
|
mod old_cargos;
|
|
mod out_dir;
|
|
mod owner;
|
|
mod package;
|
|
mod package_features;
|
|
mod patch;
|
|
mod path;
|
|
mod paths;
|
|
mod pkgid;
|
|
mod plugins;
|
|
mod proc_macro;
|
|
mod profile_config;
|
|
mod profile_custom;
|
|
mod profile_overrides;
|
|
mod profile_targets;
|
|
mod profiles;
|
|
mod progress;
|
|
mod pub_priv;
|
|
mod publish;
|
|
mod publish_lockfile;
|
|
mod read_manifest;
|
|
mod registry;
|
|
mod registry_auth;
|
|
mod rename_deps;
|
|
mod replace;
|
|
mod required_features;
|
|
mod run;
|
|
mod rust_version;
|
|
mod rustc;
|
|
mod rustc_info_cache;
|
|
mod rustdoc;
|
|
mod rustdoc_extern_html;
|
|
mod rustdocflags;
|
|
mod rustflags;
|
|
mod search;
|
|
mod shell_quoting;
|
|
mod source_replacement;
|
|
mod ssh;
|
|
mod standard_lib;
|
|
mod test;
|
|
mod timings;
|
|
mod tool_paths;
|
|
mod tree;
|
|
mod tree_graph_features;
|
|
mod unit_graph;
|
|
mod update;
|
|
mod vendor;
|
|
mod verify_project;
|
|
mod version;
|
|
mod warn_on_failure;
|
|
mod weak_dep_features;
|
|
mod workspaces;
|
|
mod yank;
|
|
|
|
#[cargo_test]
|
|
fn aaa_trigger_cross_compile_disabled_check() {
|
|
// This triggers the cross compile disabled check to run ASAP, see #5141
|
|
cargo_test_support::cross_compile::disabled();
|
|
}
|
|
|
|
// This is placed here as running tests in `cargo-test-support` would rebuild it
|
|
#[cargo_test]
|
|
fn check_test_dir() {
|
|
let tests = vec![
|
|
(
|
|
"tests/testsuite/workspaces.rs",
|
|
"workspace_in_git",
|
|
"testsuite/workspaces/workspace_in_git",
|
|
),
|
|
(
|
|
"tests/testsuite/cargo_remove/invalid_arg/mod.rs",
|
|
"case",
|
|
"testsuite/cargo_remove/invalid_arg/case",
|
|
),
|
|
(
|
|
"tests/build-std/main.rs",
|
|
"cross_custom",
|
|
"build-std/main/cross_custom",
|
|
),
|
|
(
|
|
"src/tools/cargo/tests/testsuite/build.rs",
|
|
"cargo_compile_simple",
|
|
"src/tools/cargo/testsuite/build/cargo_compile_simple",
|
|
),
|
|
(
|
|
"src/tools/cargo/tests/testsuite/cargo_add/add_basic/mod.rs",
|
|
"case",
|
|
"src/tools/cargo/testsuite/cargo_add/add_basic/case",
|
|
),
|
|
(
|
|
"src/tools/cargo/tests/build-std/main.rs",
|
|
"cross_custom",
|
|
"src/tools/cargo/build-std/main/cross_custom",
|
|
),
|
|
(
|
|
"workspace/more/src/tools/cargo/tests/testsuite/build.rs",
|
|
"cargo_compile_simple",
|
|
"src/tools/cargo/testsuite/build/cargo_compile_simple",
|
|
),
|
|
];
|
|
for (path, name, expected) in tests {
|
|
assert_eq!(
|
|
cargo_test_support::paths::test_dir(path, name),
|
|
std::path::PathBuf::from(expected)
|
|
);
|
|
}
|
|
}
|