Skip to content

Commit

Permalink
Support plugin suites (#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
maciektr authored Nov 6, 2023
1 parent 4aee195 commit 4faa510
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 93 deletions.
58 changes: 29 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ anyhow = "1"
assert_fs = "1"
async-trait = "0.1"
axum = { version = "0.6", features = ["http2"] }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "034bbf866f78535d246b86652d16d2620bd7f6b1", features = ["env_logger"] }
cairo-lang-compiler = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-defs = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-filesystem = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-formatter = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-language-server = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-runner = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-semantic = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-sierra = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-sierra-to-casm = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-starknet = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-test-plugin = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-test-runner = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf" }
cairo-lang-utils = { git = "https://github.com/starkware-libs/cairo", rev = "3530a2284637dc2365193edb0ff466715e4584cf", features = ["env_logger"] }
camino = { version = "1", features = ["serde1"] }
cargo_metadata = "0.18"
clap = { version = "4", features = ["derive", "env", "string"] }
Expand Down
7 changes: 1 addition & 6 deletions scarb/src/compiler/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ pub(crate) fn build_scarb_root_database(
let package_id = plugin_info.package.id;
let plugin = ws.config().cairo_plugins().fetch(package_id)?;
let instance = plugin.instantiate()?;
for macro_plugin in instance.macro_plugins() {
b.with_macro_plugin(macro_plugin);
}
for (name, inline_macro_plugin) in instance.inline_macro_plugins() {
b.with_inline_macro_plugin(&name, inline_macro_plugin);
}
b.with_plugin_suite(instance.plugin_suite());
}

let mut db = b.build()?;
Expand Down
48 changes: 7 additions & 41 deletions scarb/src/compiler/plugin/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,12 @@
use std::sync::Arc;

use anyhow::Result;
use cairo_lang_defs::plugin::{InlineMacroExprPlugin, MacroPlugin};
use cairo_lang_starknet::inline_macros::get_dep_component::{
GetDepComponentMacro, GetDepComponentMutMacro,
};
use cairo_lang_starknet::inline_macros::selector::SelectorMacro;
use cairo_lang_starknet::plugin::StarkNetPlugin;
use cairo_lang_test_plugin::TestPlugin;
use cairo_lang_defs::plugin::PluginSuite;
use cairo_lang_starknet::starknet_plugin_suite;
use cairo_lang_test_plugin::test_plugin_suite;

use crate::compiler::plugin::{CairoPlugin, CairoPluginInstance};
use crate::core::{PackageId, PackageName, SourceId};
use crate::internal::to_version::ToVersion;

impl CairoPluginInstance for Arc<dyn MacroPlugin> {
fn macro_plugins(&self) -> Vec<Arc<dyn MacroPlugin>> {
Vec::from_iter([self.clone()])
}

fn inline_macro_plugins(&self) -> Vec<(String, Arc<dyn InlineMacroExprPlugin>)> {
Vec::new()
}
}

pub struct BuiltinStarkNetPlugin;
impl CairoPlugin for BuiltinStarkNetPlugin {
fn id(&self) -> PackageId {
Expand All @@ -40,22 +24,8 @@ impl CairoPlugin for BuiltinStarkNetPlugin {

struct BuiltinStarkNetPluginInstance;
impl CairoPluginInstance for BuiltinStarkNetPluginInstance {
fn macro_plugins(&self) -> Vec<Arc<dyn MacroPlugin>> {
vec![Arc::new(StarkNetPlugin::default())]
}

fn inline_macro_plugins(&self) -> Vec<(String, Arc<dyn InlineMacroExprPlugin>)> {
vec![
(SelectorMacro::NAME.into(), Arc::new(SelectorMacro)),
(
GetDepComponentMacro::NAME.into(),
Arc::new(GetDepComponentMacro),
),
(
GetDepComponentMutMacro::NAME.into(),
Arc::new(GetDepComponentMutMacro),
),
]
fn plugin_suite(&self) -> PluginSuite {
starknet_plugin_suite()
}
}

Expand All @@ -78,11 +48,7 @@ impl CairoPlugin for BuiltinTestPlugin {
struct BuiltinTestPluginInstance;

impl CairoPluginInstance for BuiltinTestPluginInstance {
fn macro_plugins(&self) -> Vec<Arc<dyn MacroPlugin>> {
vec![Arc::new(TestPlugin::default())]
}

fn inline_macro_plugins(&self) -> Vec<(String, Arc<dyn InlineMacroExprPlugin>)> {
Vec::new()
fn plugin_suite(&self) -> PluginSuite {
test_plugin_suite()
}
}
Loading

0 comments on commit 4faa510

Please sign in to comment.