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

Treat Cairo plugins as package dependencies #1889

Open
wants to merge 1 commit into
base: spr/main/8452ee94
Choose a base branch
from
Open
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
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>,
Comment on lines +423 to +424
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An ID which uniquely identifies the plugin in scope of the Compilation Unit.
pub discriminator: Option<CompilationUnitComponentId>,
/// An id which uniquely identifies the plugin in scope of the compilation unit amongst other plugins and [`CompilationUnitComponent`]s. It is used to identify the plugin as a possible dependency of a [`CompilationUnitComponent`].
pub component_dependency_id: Option<CompilationUnitComponentId>,

Please check other related docs as well (e.g. docs for CompilationUnitComponent.dependencies and CompilationUnitComponent.id) and update them to reflect the new semantics


/// 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,
Comment on lines +101 to +102
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary, you don't need to keep it here. You can just use the package.id.to_serialized_string in metadata builder

/// 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;
}
Comment on lines +157 to +163
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you filter them out?


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
18 changes: 18 additions & 0 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,9 @@ impl<'a> PackageSolutionCollector<'a> {
let target = package.target(&TargetKind::CAIRO_PLUGIN).unwrap();
let props: CairoPluginProps = target.props()?;
Ok(CompilationUnitCairoPlugin::builder()
.discriminator(CompilationUnitComponentId {
package_id: package.id,
})
.package(package)
.builtin(props.builtin)
.prebuilt_allowed(prebuilt_allowed)
Expand Down Expand Up @@ -753,6 +756,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
Loading