Skip to content

Commit

Permalink
Add all root summaries to state
Browse files Browse the repository at this point in the history
commit-id:53bd5870
  • Loading branch information
maciektr committed Jul 17, 2024
1 parent 6ac7666 commit 331893e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Expand Down
34 changes: 29 additions & 5 deletions scarb/src/resolver/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,12 +26,34 @@ pub async fn resolve<'c>(
let main_package_ids: HashSet<PackageId> =
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);
Expand Down

0 comments on commit 331893e

Please sign in to comment.