Skip to content

Commit

Permalink
Add builtin prop on cairo plugin target definition (#1059)
Browse files Browse the repository at this point in the history
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.*
  • Loading branch information
maciektr authored Feb 5, 2024
1 parent 8f7c40f commit 43da779
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions scarb/scarblib/starknet/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ name = "starknet"
version = "{{ CAIRO_VERSION }}"

[cairo-plugin]
builtin = true
1 change: 1 addition & 0 deletions scarb/scarblib/test_plugin/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ version = "{{ CAIRO_VERSION }}"
no-core = true

[cairo-plugin]
builtin = true
4 changes: 3 additions & 1 deletion scarb/src/compiler/compilation_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 20 additions & 2 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -262,6 +263,15 @@ fn generate_cairo_compilation_units(
.collect::<Result<Vec<CompilationUnit>>>()
}

/// 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,
Expand Down Expand Up @@ -342,8 +352,16 @@ impl<'a> PackageSolutionCollector<'a> {

let cairo_plugins = cairo_plugins
.into_iter()
.map(|package| CompilationUnitCairoPlugin { package })
.collect::<Vec<_>>();
.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::<Result<Vec<_>>>()?;

Ok((packages, cairo_plugins))
}
Expand Down

0 comments on commit 43da779

Please sign in to comment.