Skip to content

Commit

Permalink
Treat Cairo plugins as package dependencies
Browse files Browse the repository at this point in the history
commit-id:52f11b96
  • Loading branch information
integraledelebesgue committed Jan 22, 2025
1 parent db30b3f commit f4deb31
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
3 changes: 3 additions & 0 deletions scarb-metadata/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CompilationUnitComponentId>,

/// Whether Scarb will attempt to load prebuilt binaries associated with this plugin.
pub prebuilt_allowed: Option<bool>,

Expand Down
2 changes: 2 additions & 0 deletions scarb/src/compiler/compilation_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 11 additions & 3 deletions scarb/src/compiler/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,23 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result<ProjectConfig> {
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();

Expand Down
1 change: 1 addition & 0 deletions scarb/src/ops/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 16 additions & 0 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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::<Vec<_>>()
};

dependencies.extend(plugin_dependencies);
dependencies
}

Expand Down

0 comments on commit f4deb31

Please sign in to comment.