Skip to content

Commit

Permalink
PubGrub resolver initial implementation
Browse files Browse the repository at this point in the history
commit-id:d55b5ecb
  • Loading branch information
maciektr committed Oct 22, 2024
1 parent 7c6c170 commit 121762e
Show file tree
Hide file tree
Showing 21 changed files with 1,197 additions and 97 deletions.
72 changes: 71 additions & 1 deletion Cargo.lock

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

11 changes: 10 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ members = [
"plugins/cairo-lang-macro-attributes",
"plugins/cairo-lang-macro-stable",
"utils/create-output-dir",
"utils/once-map",
"utils/scarb-build-metadata",
"utils/scarb-stable-hash",
"utils/scarb-test-support",
Expand Down Expand Up @@ -65,6 +66,7 @@ clap = { version = "4", features = ["derive", "env", "string"] }
console = "0.15"
convert_case = "0.6.0"
darling = "0.20"
dashmap = "6"
data-encoding = "2"
deno_task_shell = ">=0.13"
derive_builder = ">=0.12"
Expand All @@ -75,7 +77,7 @@ expect-test = "1.5"
flate2 = { version = "1.0.34", default-features = false, features = ["zlib"] }
fs4 = { version = "0.7", features = ["tokio"] }
fs_extra = "1"
futures = { version = "0.3", default-features = false, features = ["std", "async-await"] }
futures = { version = "0.3", default-features = false, features = ["std", "async-await", "executor"] }
gix = ">=0.55"
gix-path = "0.10"
glob = "0.3"
Expand All @@ -93,17 +95,20 @@ ntest = "0.9"
num-bigint = { version = "0.4", features = ["rand"] }
num-traits = "0.2"
once_cell = "1"
once_map = "0.4"
pathdiff = { version = "0.2", features = ["camino"] }
petgraph = "0.6"
predicates = "3"
proc-macro2 = "1"
pubgrub = { git = "https://github.com/maciektr/pubgrub.git", branch = "dev" }
quote = "1"
ra_ap_toolchain = "0.0.218"
rayon = "1.10"
redb = "2.1.4"
reqwest = { version = "0.11", features = ["gzip", "brotli", "deflate", "json", "stream", "multipart"], default-features = false }
salsa = { package = "rust-analyzer-salsa", version = "0.17.0-pre.6" }
semver = { version = "1", features = ["serde"] }
semver-pubgrub = { git = "https://github.com/maciektr/semver-pubgrub.git" }
serde = { version = "1", features = ["serde_derive"] }
serde-untagged = "0.1"
serde-value = "0.7"
Expand All @@ -123,6 +128,7 @@ test-case = "3"
thiserror = "1"
time = "0.3"
tokio = { version = "1", features = ["macros", "io-util", "process", "rt", "rt-multi-thread", "sync"] }
tokio-stream = "0.1"
toml = "0.8"
toml_edit = { version = "0.22", features = ["serde"] }
tower-http = { version = "0.4", features = ["fs"] }
Expand All @@ -140,6 +146,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
2 changes: 1 addition & 1 deletion examples/dependencies/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = 1
[[package]]
name = "alexandria_data_structures"
version = "0.1.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#3356bf0c5c1a089167d7d3c28d543e195325e596"

[[package]]
name = "alexandria_math"
checksum = "sha256:b62fc4b9bfbd9310a47d2e595d2c8f468354266be0827aeea9b465d9984908de"
version = "0.2.0"
source = "git+https://github.com/keep-starknet-strange/alexandria.git#3356bf0c5c1a089167d7d3c28d543e195325e596"
dependencies = [
Expand Down
6 changes: 5 additions & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ directories.workspace = true
dunce.workspace = true
fs4.workspace = true
futures.workspace = true
gix.workspace = true
gix-path.workspace = true
gix.workspace = true
glob.workspace = true
ignore.workspace = true
include_dir.workspace = true
indoc.workspace = true
itertools.workspace = true
libloading.workspace = true
once_cell.workspace = true
once_map = { path = "../utils/once-map" }
pathdiff.workspace = true
petgraph.workspace = true
pubgrub.workspace = true
ra_ap_toolchain.workspace = true
redb.workspace = true
reqwest.workspace = true
scarb-build-metadata = { path = "../utils/scarb-build-metadata" }
scarb-metadata = { path = "../scarb-metadata", default-features = false, features = ["builder"] }
scarb-stable-hash = { path = "../utils/scarb-stable-hash" }
scarb-ui = { path = "../utils/scarb-ui" }
semver-pubgrub.workspace = true
semver.workspace = true
serde-untagged.workspace = true
serde-value.workspace = true
Expand All @@ -75,6 +78,7 @@ smol_str.workspace = true
tar.workspace = true
thiserror.workspace = true
tokio.workspace = true
tokio-stream.workspace = true
toml.workspace = true
toml_edit.workspace = true
tracing-subscriber.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/core/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum LockVersion {
V1 = 1,
}

#[derive(Debug, Eq, PartialEq, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Eq, PartialEq, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Lockfile {
pub version: LockVersion,
Expand Down
2 changes: 1 addition & 1 deletion scarb/src/core/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub(crate) mod mock {
let summary = Summary::builder()
.package_id(package_id)
.dependencies(dependencies)
.no_core(package_id.is_core())
.no_core(package_id.name == PackageName::CORE)
.build();

let manifest = Box::new(
Expand Down
12 changes: 10 additions & 2 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,19 @@ pub fn resolve_workspace_with_opts(
read_lockfile(ws)?
};

let resolve = resolver::resolve(&members_summaries, &patched, lockfile).await?;
let registry = Box::new(patched);
let registry: Box<dyn Registry> = Box::new(*registry);
let resolve = resolver::resolve(
&members_summaries,
&*registry,
lockfile,
ws.config().tokio_handle(),
)
.await?;

write_lockfile(Lockfile::from_resolve(&resolve), ws)?;

let packages = collect_packages_from_resolve_graph(&resolve, &patched).await?;
let packages = collect_packages_from_resolve_graph(&resolve, &*registry).await?;

packages
.values()
Expand Down
43 changes: 43 additions & 0 deletions scarb/src/resolver/algorithm/in_memory_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
use crate::core::{Package, PackageId, Summary};
use crate::resolver::algorithm::provider::PubGrubPackage;
use once_map::OnceMap;
use std::sync::Arc;

/// In-memory index of package metadata.
#[derive(Default, Clone)]
pub struct InMemoryIndex(Arc<SharedInMemoryIndex>);

#[derive(Default)]
struct SharedInMemoryIndex {
/// A map from package name to the metadata for that package and the index where the metadata
/// came from.
packages: FxOnceMap<PubGrubPackage, Arc<VersionsResponse>>,

/// A map from package ID to metadata for that distribution.
distributions: FxOnceMap<PackageId, Arc<MetadataResponse>>,
}

pub(crate) type FxOnceMap<K, V> = OnceMap<K, V>;

impl InMemoryIndex {
/// Returns a reference to the package metadata map.
pub fn packages(&self) -> &FxOnceMap<PubGrubPackage, Arc<VersionsResponse>> {
&self.0.packages
}

/// Returns a reference to the distribution metadata map.
pub fn distributions(&self) -> &FxOnceMap<PackageId, Arc<MetadataResponse>> {
&self.0.distributions
}
}

// pub struct VersionsResponse;
#[derive(Debug)]
pub enum VersionsResponse {
Found(Vec<Summary>),
}

// pub struct MetadataResponse;
pub enum MetadataResponse {
Found(Package),
}
Loading

0 comments on commit 121762e

Please sign in to comment.