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

Change resolver algorithm to always try to query for dependency candi… #358

Closed
wants to merge 4 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
13 changes: 13 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ clap = { version = "4.2.7", features = ["derive", "env", "string"] }
clap-verbosity-flag = "2.0.1"
console = "0.15.5"
data-encoding = "2.3.3"
derive_builder = "0.12.0"
deno_task_shell = "0.12.0"
derive_builder = "0.12.0"
diffy = "0.3.0"
directories = "5.0.1"
dunce = "1.0.4"
Expand Down Expand Up @@ -71,6 +71,7 @@ tracing = "0.1.37"
tracing-futures = "0.2.5"
tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
typed-builder = "0.14.0"
url = { version = "2.3.1", features = ["serde"] }
walkdir = "2.3.2"
which = "4.4.0"
Expand Down
4 changes: 3 additions & 1 deletion scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ console.workspace = true
create-output-dir = { version = "1.0.0", path = "../utils/create-output-dir" }
data-encoding.workspace = true
deno_task_shell.workspace = true
derive_builder.workspace = true
diffy.workspace = true
directories.workspace = true
dunce.workspace = true
Expand All @@ -49,15 +50,16 @@ scarb-metadata = { version = "=1.2.0", default-features = false, features = ["bu
semver.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
smol_str.workspace = true
thiserror.workspace = true
tokio.workspace = true
toml.workspace = true
toml_edit.workspace = true
tracing-futures.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
typed-builder.workspace = true
url.workspace = true
walkdir.workspace = true
which.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions scarb/scarblib/starknet/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "starknet"
version = "{{ CAIRO_VERSION }}"

[cairo-plugin]
builtin = "starknet"
5 changes: 3 additions & 2 deletions scarb/src/compiler/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ pub(crate) fn build_scarb_root_database(
b.with_project_config(build_project_config(unit)?);
b.with_cfg(unit.cfg_set.clone());

// TODO(mkaput): Pull only plugins that are dependencies of this compilation unit.
for plugin in ws.config().cairo_plugins().iter() {
for plugin_info in &unit.cairo_plugins {
let package_id = plugin_info.package.id;
let plugin = ws.config().cairo_plugins().fetch(package_id)?;
let instance = plugin.instantiate()?;
for semantic_plugin in instance.semantic_plugins() {
b.with_semantic_plugin(semantic_plugin);
Expand Down
61 changes: 58 additions & 3 deletions scarb/src/core/manifest/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::collections::BTreeMap;
use std::collections::{BTreeMap, HashSet};

use anyhow::{bail, ensure, Result};
use derive_builder::Builder;
use semver::VersionReq;
use serde::{Deserialize, Serialize};
use smol_str::SmolStr;
Expand All @@ -12,6 +14,7 @@ pub use summary::*;
pub use target::*;
pub use toml_manifest::*;

use crate::compiler::DefaultForProfile;
use crate::compiler::Profile;

mod compiler_config;
Expand All @@ -22,16 +25,21 @@ mod target;
mod toml_manifest;

/// Contains all the information about a package, as loaded from the manifest file.
///
/// Construct using [`ManifestBuilder`].
/// This is deserialized using the [`TomlManifest`] type.
#[derive(Clone, Debug)]
#[derive(Builder, Clone, Debug)]
#[builder(build_fn(error = "anyhow::Error", validate = "Self::check"))]
#[non_exhaustive]
pub struct Manifest {
pub summary: Summary,
pub targets: Vec<Target>,
#[builder(default)]
pub metadata: ManifestMetadata,
#[builder(default = "ManifestCompilerConfig::default_for_profile(&Profile::DEV)")]
pub compiler_config: ManifestCompilerConfig,
#[builder(default)]
pub scripts: BTreeMap<SmolStr, ScriptDefinition>,
#[builder(default)]
pub profiles: Vec<Profile>,
}

Expand All @@ -52,3 +60,50 @@ pub struct ManifestMetadata {
pub tool_metadata: Option<BTreeMap<SmolStr, Value>>,
pub cairo_version: Option<VersionReq>,
}

impl ManifestBuilder {
fn check(&self) -> Result<()> {
self.check_cairo_plugin_target_is_exclusive()?;
self.check_unique_targets()?;
Ok(())
}

fn check_cairo_plugin_target_is_exclusive(&self) -> Result<()> {
let Some(targets) = &self.targets else { return Ok(()); };

if targets.iter().any(Target::is_cairo_plugin) {
ensure!(
targets.len() == 1,
"target `{}` cannot be mixed with other targets",
Target::CAIRO_PLUGIN,
);
}
Ok(())
}

fn check_unique_targets(&self) -> Result<()> {
let Some(summary) = &self.summary else { return Ok(()); };
let Some(targets) = &self.targets else { return Ok(()); };

let mut used = HashSet::with_capacity(targets.len());
for target in targets {
if !used.insert((target.kind.as_str(), target.name.as_str())) {
if target.name == summary.package_id.name.as_str() {
bail!(
"manifest contains duplicate target definitions `{}`, \
consider explicitly naming targets with the `name` field",
target.kind
)
} else {
bail!(
"manifest contains duplicate target definitions `{} ({})`, \
use different target names to resolve the conflict",
target.kind,
target.name
)
}
}
}
Ok(())
}
}
63 changes: 16 additions & 47 deletions scarb/src/core/manifest/summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ use std::sync::Arc;

use once_cell::sync::Lazy;
use semver::VersionReq;
use typed_builder::TypedBuilder;

#[cfg(doc)]
use crate::core::Manifest;
use crate::core::{ManifestDependency, PackageId, PackageName, SourceId};

/// Subset of a [`Manifest`] that contains only the most important information about a package.
/// See [`SummaryInner`] for public fields reference.
/// Construct using [`Summary::builder`].
#[derive(Clone, Debug)]
pub struct Summary(Arc<SummaryInner>);

#[derive(Debug)]
#[derive(TypedBuilder, Debug)]
#[builder(builder_type(name = SummaryBuilder))]
#[builder(builder_method(vis = ""))]
#[builder(build_method(into = Summary))]
#[non_exhaustive]
pub struct SummaryInner {
pub package_id: PackageId,
#[builder(default)]
pub dependencies: Vec<ManifestDependency>,
#[builder(default = false)]
pub no_core: bool,
}

Expand All @@ -29,19 +36,16 @@ impl Deref for Summary {
}
}

impl Summary {
pub fn build(package_id: PackageId) -> SummaryBuilder {
SummaryBuilder::new(package_id)
}

pub fn minimal(package_id: PackageId, dependencies: Vec<ManifestDependency>) -> Self {
Self::build(package_id)
.with_dependencies(dependencies)
.finish()
#[doc(hidden)]
impl From<SummaryInner> for Summary {
fn from(data: SummaryInner) -> Self {
Self(Arc::new(data))
}
}

fn new(data: SummaryInner) -> Self {
Self(Arc::new(data))
impl Summary {
pub fn builder() -> SummaryBuilder {
SummaryInner::builder()
}

pub fn full_dependencies(&self) -> impl Iterator<Item = &ManifestDependency> {
Expand Down Expand Up @@ -69,38 +73,3 @@ impl Summary {
deps.into_iter()
}
}

#[derive(Debug)]
pub struct SummaryBuilder {
package_id: PackageId,
dependencies: Vec<ManifestDependency>,
no_core: bool,
}

impl SummaryBuilder {
fn new(package_id: PackageId) -> Self {
Self {
package_id,
dependencies: Vec::new(),
no_core: false,
}
}

pub fn with_dependencies(mut self, dependencies: Vec<ManifestDependency>) -> Self {
self.dependencies = dependencies;
self
}

pub fn no_core(mut self, no_core: bool) -> Self {
self.no_core = no_core;
self
}

pub fn finish(self) -> Summary {
Summary::new(SummaryInner {
package_id: self.package_id,
dependencies: self.dependencies,
no_core: self.no_core,
})
}
}
Loading