From f4deb31705d6d59a798e182890fd0e95442b7171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sm=C3=B3=C5=82ka?= Date: Thu, 16 Jan 2025 17:13:56 +0100 Subject: [PATCH] Treat Cairo plugins as package dependencies commit-id:52f11b96 --- scarb-metadata/src/lib.rs | 3 +++ scarb/src/compiler/compilation_unit.rs | 2 ++ scarb/src/compiler/db.rs | 14 +++++++++++--- scarb/src/ops/metadata.rs | 1 + scarb/src/ops/resolve.rs | 16 ++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) diff --git a/scarb-metadata/src/lib.rs b/scarb-metadata/src/lib.rs index 50f61c95e..b94358fc7 100644 --- a/scarb-metadata/src/lib.rs +++ b/scarb-metadata/src/lib.rs @@ -420,6 +420,9 @@ pub struct CompilationUnitCairoPluginMetadata { /// Package ID. pub package: PackageId, + /// An ID which uniquely identifies the plugin in scope of the Compilation Unit. + pub discriminator: Option, + /// Whether Scarb will attempt to load prebuilt binaries associated with this plugin. pub prebuilt_allowed: Option, diff --git a/scarb/src/compiler/compilation_unit.rs b/scarb/src/compiler/compilation_unit.rs index a8bf9fb7d..92285de45 100644 --- a/scarb/src/compiler/compilation_unit.rs +++ b/scarb/src/compiler/compilation_unit.rs @@ -98,6 +98,8 @@ pub struct CompilationUnitComponent { #[derive(Clone, Debug, TypedBuilder)] #[non_exhaustive] pub struct CompilationUnitCairoPlugin { + /// The ID of the [`CompilationUnitComponent`] the plugin is represented by in the [`CairoCompilationUnit`]. + pub discriminator: CompilationUnitComponentId, /// The Scarb plugin [`Package`] to load. pub package: Package, /// Indicate whether the plugin is built into Scarb, or compiled from source. diff --git a/scarb/src/compiler/db.rs b/scarb/src/compiler/db.rs index 702ef43c0..84f3574aa 100644 --- a/scarb/src/compiler/db.rs +++ b/scarb/src/compiler/db.rs @@ -153,15 +153,23 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { let dependencies = component .dependencies .iter() - .map(|compilation_unit_component_id| { + .filter_map(|compilation_unit_component_id| { + if unit.cairo_plugins + .iter() + .find(|plugin| plugin.discriminator == *compilation_unit_component_id) + .map(|plugin| (plugin.package.id.name.to_string(), plugin.discriminator.clone())) + .is_some() { + return None; + } + let compilation_unit_component = unit.components.iter().find(|component| component.id == *compilation_unit_component_id) .expect("dependency of a component is guaranteed to exist in compilation unit components"); - ( + Some(( compilation_unit_component.cairo_package_name().to_string(), DependencySettings { discriminator: compilation_unit_component.id.to_discriminator() }, - ) + )) }) .collect(); diff --git a/scarb/src/ops/metadata.rs b/scarb/src/ops/metadata.rs index f4d4ccc43..76bd88f14 100644 --- a/scarb/src/ops/metadata.rs +++ b/scarb/src/ops/metadata.rs @@ -243,6 +243,7 @@ fn collect_cairo_compilation_unit_metadata( .map(|c| { m::CompilationUnitCairoPluginMetadataBuilder::default() .package(wrap_package_id(c.package.id)) + .discriminator(c.discriminator.to_metadata_component_id()) .prebuilt_allowed(c.prebuilt_allowed) .build() .unwrap() diff --git a/scarb/src/ops/resolve.rs b/scarb/src/ops/resolve.rs index 742ba2c29..6d56212fc 100644 --- a/scarb/src/ops/resolve.rs +++ b/scarb/src/ops/resolve.rs @@ -706,6 +706,7 @@ impl<'a> PackageSolutionCollector<'a> { let target = package.target(&TargetKind::CAIRO_PLUGIN).unwrap(); let props: CairoPluginProps = target.props()?; Ok(CompilationUnitCairoPlugin::builder() + .discriminator(CompilationUnitComponentId::Plugin(package.id)) .package(package) .builtin(props.builtin) .prebuilt_allowed(prebuilt_allowed) @@ -753,6 +754,21 @@ impl<'a> PackageSolutionCollector<'a> { dependencies.push(component.id.clone()); } + let plugin_dependencies = if self + .target_kind + .as_ref() + .is_some_and(|kind| kind == &TargetKind::CAIRO_PLUGIN) + { + vec![] + } else { + self.resolve + .package_dependencies(package_id, &TargetKind::CAIRO_PLUGIN) + .into_iter() + .map(|package| CompilationUnitComponentId::Plugin(package.id)) + .collect::>() + }; + + dependencies.extend(plugin_dependencies); dependencies }