diff --git a/Cargo.lock b/Cargo.lock index 08c5fa45c..9d74c0109 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4198,7 +4198,7 @@ dependencies = [ [[package]] name = "pubgrub" version = "0.2.1" -source = "git+https://github.com/pubgrub-rs/pubgrub.git?branch=dev#df8395771231be4d3bf6fba80e8fd9658c634c2c" +source = "git+https://github.com/maciektr/pubgrub.git?branch=dev#6e12ee740000e367984d8b965c8d9d574e6bee7d" dependencies = [ "indexmap 2.2.6", "log", diff --git a/Cargo.toml b/Cargo.toml index ea9a63090..f46d64745 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,7 @@ pathdiff = { version = "0.2", features = ["camino"] } petgraph = "0.6" predicates = "3" proc-macro2 = "1" -pubgrub = { git = "https://github.com/pubgrub-rs/pubgrub.git", branch = "dev" } +pubgrub = { git = "https://github.com/maciektr/pubgrub.git", branch = "dev" } quote = "1" ra_ap_toolchain = "0.0.218" rayon = "1.10" @@ -141,6 +141,9 @@ xxhash-rust = { version = "0.8", features = ["xxh3"] } zip = { version = "0.6", default-features = false, features = ["deflate"] } zstd = "0.13" +[patch.'https://github.com/pubgrub-rs/pubgrub.git'] +pubgrub = { git = 'https://github.com/maciektr/pubgrub.git', branch = 'dev' } + [profile.release] lto = true diff --git a/scarb/src/resolver/algorithm/mod.rs b/scarb/src/resolver/algorithm/mod.rs index e15e5dfc9..dad1ebe1c 100644 --- a/scarb/src/resolver/algorithm/mod.rs +++ b/scarb/src/resolver/algorithm/mod.rs @@ -5,7 +5,9 @@ use crate::resolver::algorithm::provider::{PubGrubDependencyProvider, PubGrubPac use crate::resolver::algorithm::solution::build_resolve; use anyhow::bail; use indoc::indoc; +use itertools::Itertools; use pubgrub::type_aliases::SelectedDependencies; +use pubgrub::{Incompatibility, State}; use std::collections::{HashMap, HashSet}; use tokio::runtime::Handle; use tokio::task::block_in_place; @@ -24,12 +26,34 @@ pub async fn resolve<'c>( let main_package_ids: HashSet = HashSet::from_iter(summaries.iter().map(|sum| sum.package_id)); block_in_place(|| { - let summary = summaries.iter().next().unwrap(); - let package: PubGrubPackage = summary.into(); - let version = summary.package_id.version.clone(); - let provider = PubGrubDependencyProvider::new(registry, handle, main_package_ids.clone()); + let provider = PubGrubDependencyProvider::new(registry, handle, main_package_ids); - let solution = pubgrub::solver::resolve(&provider, package, version) + // Init state + let main_package_ids = provider + .main_package_ids() + .clone() + .into_iter() + .collect_vec(); + let Some((first, rest)) = main_package_ids.split_first() else { + bail!("empty summaries"); + }; + let package: PubGrubPackage = (*first).into(); + let version = first.version.clone(); + let mut state = State::init(package.clone(), version); + state + .unit_propagation(package.clone()) + .map_err(|err| anyhow::format_err!("unit propagation failed: {:?}", err))?; + for package_id in rest { + let package: PubGrubPackage = (*package_id).into(); + let version = package_id.version.clone(); + state.add_incompatibility(Incompatibility::not_root(package.clone(), version.clone())); + state + .unit_propagation(package) + .map_err(|err| anyhow::format_err!("unit propagation failed: {:?}", err))? + } + + // Resolve requirements + let solution = pubgrub::solver::resolve_state(&provider, &mut state, package) .map_err(|err| anyhow::format_err!("failed to resolve: {:?}", err))?; dbg!(&solution);