Skip to content

Commit

Permalink
feat: executable plugin
Browse files Browse the repository at this point in the history
commit-id:eefec831
  • Loading branch information
FroyaTheHen committed Dec 13, 2024
1 parent 328062c commit 364e06a
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cairo-lang-compiler = "*"
cairo-lang-defs = "*"
cairo-lang-diagnostics = "*"
cairo-lang-doc = "*"
cairo-lang-executable = "*"
cairo-lang-filesystem = "*"
cairo-lang-formatter = "*"
cairo-lang-lowering = "*"
Expand Down
1 change: 1 addition & 0 deletions scarb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ async-trait.workspace = true
cairo-lang-compiler.workspace = true
cairo-lang-defs.workspace = true
cairo-lang-diagnostics.workspace = true
cairo-lang-executable.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-formatter.workspace = true
cairo-lang-lowering.workspace = true
Expand Down
6 changes: 6 additions & 0 deletions scarb/scarblib/cairo_execute/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[package]
name = "cairo_execute"
version = "{{ CAIRO_VERSION }}"

[cairo-plugin]
builtin = true
Empty file.
23 changes: 23 additions & 0 deletions scarb/src/compiler/plugin/builtin.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::Result;
use cairo_lang_defs::plugin::{MacroPlugin, MacroPluginMetadata, PluginResult};
use cairo_lang_executable::plugin::executable_plugin_suite;
use cairo_lang_semantic::plugin::PluginSuite;
use cairo_lang_starknet::starknet_plugin_suite;
use cairo_lang_syntax::node::ast::ModuleItem;
Expand Down Expand Up @@ -32,6 +33,28 @@ impl CairoPluginInstance for BuiltinStarkNetPluginInstance {
}
}

pub struct BuiltinExecutablePlugin;
impl CairoPlugin for BuiltinExecutablePlugin {
fn id(&self) -> PackageId {
PackageId::new(
PackageName::EXECUTABLE,
crate::version::get().cairo.version.to_version().unwrap(),
SourceId::for_std(),
)
}

fn instantiate(&self) -> Result<Box<dyn CairoPluginInstance>> {
Ok(Box::new(BuiltinExecutablePluginInstance))
}
}

struct BuiltinExecutablePluginInstance;
impl CairoPluginInstance for BuiltinExecutablePluginInstance {
fn plugin_suite(&self) -> PluginSuite {
executable_plugin_suite()
}
}

pub struct BuiltinTestPlugin;

impl CairoPlugin for BuiltinTestPlugin {
Expand Down
3 changes: 2 additions & 1 deletion scarb/src/compiler/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::fmt;

use crate::compiler::plugin::builtin::BuiltinTestAssertsPlugin;
use crate::compiler::plugin::builtin::{BuiltinExecutablePlugin, BuiltinTestAssertsPlugin};
use anyhow::{anyhow, bail, Result};
use cairo_lang_semantic::plugin::PluginSuite;
use itertools::Itertools;
Expand Down Expand Up @@ -63,6 +63,7 @@ impl CairoPluginRepository {
// `starknet` package which makes it a dependency. This way we can deliver Starknet Cairo
// library code to users etc.
repo.add(Box::new(BuiltinStarkNetPlugin)).unwrap();
repo.add(Box::new(BuiltinExecutablePlugin)).unwrap();
repo.add(Box::new(BuiltinTestPlugin)).unwrap();
repo.add(Box::new(BuiltinCairoRunPlugin)).unwrap();
repo.add(Box::new(BuiltinTestAssertsPlugin)).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion scarb/src/core/package/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use crate::internal::restricted_names;
use crate::core::Package;

use crate::{
CAIRO_RUN_PLUGIN_NAME, STARKNET_PLUGIN_NAME, TEST_ASSERTS_PLUGIN_NAME, TEST_PLUGIN_NAME,
CAIRO_RUN_PLUGIN_NAME, EXECUTABLE_PLUGIN_NAME, STARKNET_PLUGIN_NAME, TEST_ASSERTS_PLUGIN_NAME,
TEST_PLUGIN_NAME,
};

/// A [`String`]-like type representing [`Package`] name.
Expand All @@ -33,6 +34,7 @@ pub struct PackageName(SmolStr);
impl PackageName {
pub const CORE: Self = PackageName(SmolStr::new_inline(CORELIB_CRATE_NAME));
pub const STARKNET: Self = PackageName(SmolStr::new_inline(STARKNET_PLUGIN_NAME));
pub const EXECUTABLE: Self = PackageName(SmolStr::new_inline(EXECUTABLE_PLUGIN_NAME));
pub const TEST_PLUGIN: Self = PackageName(SmolStr::new_inline(TEST_PLUGIN_NAME));
pub const CAIRO_RUN_PLUGIN: Self = PackageName(SmolStr::new_inline(CAIRO_RUN_PLUGIN_NAME));
pub const TEST_ASSERTS_PLUGIN: Self =
Expand Down
1 change: 1 addition & 0 deletions scarb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ pub const TEST_ASSERTS_PLUGIN_NAME: &str = "assert_macros";
pub const CAIRO_RUN_PLUGIN_NAME: &str = "cairo_run";
pub const CARGO_MANIFEST_FILE_NAME: &str = "Cargo.toml";
pub const CARGO_LOCK_FILE_NAME: &str = "Cargo.lock";
pub const EXECUTABLE_PLUGIN_NAME: &str = "cairo_execute";
5 changes: 5 additions & 0 deletions scarb/src/ops/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ pub fn resolve_workspace_with_opts(
.version_req(version_req.clone())
.source_id(SourceId::for_std())
.build(),
ManifestDependency::builder()
.name(PackageName::EXECUTABLE)
.version_req(version_req.clone())
.source_id(SourceId::for_std())
.build(),
ManifestDependency::builder()
.kind(DepKind::Target(TargetKind::TEST))
.name(PackageName::TEST_PLUGIN)
Expand Down
4 changes: 4 additions & 0 deletions utils/scarb-test-support/src/project_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ impl ProjectBuilder {
self.dep_builtin("starknet")
}

pub fn dep_executable(self) -> Self {
self.dep_builtin("cairo_execute")
}

pub fn dep_cairo_test(self) -> Self {
self.dev_dep_builtin("cairo_test")
}
Expand Down

0 comments on commit 364e06a

Please sign in to comment.