From 43da7793411d8ea671fc3a2d4024632e4f840a09 Mon Sep 17 00:00:00 2001 From: maciektr Date: Mon, 5 Feb 2024 20:49:57 +0100 Subject: [PATCH] Add builtin prop on cairo plugin target definition (#1059) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit-id:350fe920 --- **Stack**: - #1100 - #1110 - #1093 - #1092 - #1091 - #1060 - #1059 ⬅ ⚠️ *Part of a stack created by [spr](https://github.com/ejoffe/spr). Do not merge manually using the UI - doing so may have unexpected results.* --- scarb/scarblib/starknet/Scarb.toml | 1 + scarb/scarblib/test_plugin/Scarb.toml | 1 + scarb/src/compiler/compilation_unit.rs | 4 +++- scarb/src/ops/resolve.rs | 22 ++++++++++++++++++++-- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/scarb/scarblib/starknet/Scarb.toml b/scarb/scarblib/starknet/Scarb.toml index cc24a5776..2e6a1a38f 100644 --- a/scarb/scarblib/starknet/Scarb.toml +++ b/scarb/scarblib/starknet/Scarb.toml @@ -3,3 +3,4 @@ name = "starknet" version = "{{ CAIRO_VERSION }}" [cairo-plugin] +builtin = true diff --git a/scarb/scarblib/test_plugin/Scarb.toml b/scarb/scarblib/test_plugin/Scarb.toml index 517afec7d..e2de28fd5 100644 --- a/scarb/scarblib/test_plugin/Scarb.toml +++ b/scarb/scarblib/test_plugin/Scarb.toml @@ -5,3 +5,4 @@ version = "{{ CAIRO_VERSION }}" no-core = true [cairo-plugin] +builtin = true diff --git a/scarb/src/compiler/compilation_unit.rs b/scarb/src/compiler/compilation_unit.rs index 68114c548..772ce8203 100644 --- a/scarb/src/compiler/compilation_unit.rs +++ b/scarb/src/compiler/compilation_unit.rs @@ -3,6 +3,7 @@ use std::hash::{Hash, Hasher}; use cairo_lang_filesystem::cfg::CfgSet; use smol_str::SmolStr; +use typed_builder::TypedBuilder; use crate::compiler::Profile; use crate::core::{ManifestCompilerConfig, Package, PackageId, Target, Workspace}; @@ -51,11 +52,12 @@ pub struct CompilationUnitComponent { } /// Information about a single package that is a compiler plugin to load for [`CompilationUnit`]. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, TypedBuilder)] #[non_exhaustive] pub struct CompilationUnitCairoPlugin { /// The Scarb plugin [`Package`] to load. pub package: Package, + pub builtin: bool, } impl CompilationUnit { diff --git a/scarb/src/ops/resolve.rs b/scarb/src/ops/resolve.rs index 7b510d93c..fedfaab95 100644 --- a/scarb/src/ops/resolve.rs +++ b/scarb/src/ops/resolve.rs @@ -5,6 +5,7 @@ use cairo_lang_filesystem::cfg::{Cfg, CfgSet}; use futures::TryFutureExt; use indoc::formatdoc; use itertools::Itertools; +use serde::{Deserialize, Serialize}; use crate::compiler::{CompilationUnit, CompilationUnitCairoPlugin, CompilationUnitComponent}; use crate::core::lockfile::Lockfile; @@ -262,6 +263,15 @@ fn generate_cairo_compilation_units( .collect::>>() } +/// Properties that can be defined on Cairo plugin target. +#[derive(Debug, Serialize, Deserialize, Default)] +#[serde(rename_all = "kebab-case")] +struct CairoPluginProps { + /// Mark this macro plugin as builtin. + /// Builtin plugins are assumed to be available in `CairoPluginRepository` for the whole Scarb execution. + pub builtin: bool, +} + pub struct PackageSolutionCollector<'a> { member: &'a Package, resolve: &'a WorkspaceResolve, @@ -342,8 +352,16 @@ impl<'a> PackageSolutionCollector<'a> { let cairo_plugins = cairo_plugins .into_iter() - .map(|package| CompilationUnitCairoPlugin { package }) - .collect::>(); + .map(|package| { + // We can safely unwrap as all packages with `PackageClass::CairoPlugin` must define plugin target. + let target = package.target(&TargetKind::CAIRO_PLUGIN).unwrap(); + let props: CairoPluginProps = target.props()?; + Ok(CompilationUnitCairoPlugin::builder() + .package(package) + .builtin(props.builtin) + .build()) + }) + .collect::>>()?; Ok((packages, cairo_plugins)) }