diff --git a/Cargo.lock b/Cargo.lock index 40727a359..826e8c3e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -662,6 +662,31 @@ dependencies = [ "good_lp", ] +[[package]] +name = "cairo-lang-executable" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cdfebefb3d4541b5daea229f1fe0c195c1153527e14a6246491327c0f44d837" +dependencies = [ + "anyhow", + "cairo-lang-casm", + "cairo-lang-compiler", + "cairo-lang-defs", + "cairo-lang-filesystem", + "cairo-lang-lowering", + "cairo-lang-plugins", + "cairo-lang-runnable-utils", + "cairo-lang-semantic", + "cairo-lang-sierra-generator", + "cairo-lang-sierra-to-casm", + "cairo-lang-syntax", + "cairo-lang-utils", + "cairo-vm", + "indoc", + "itertools 0.12.1", + "serde", +] + [[package]] name = "cairo-lang-filesystem" version = "2.9.1" @@ -4935,6 +4960,7 @@ dependencies = [ "cairo-lang-compiler", "cairo-lang-defs", "cairo-lang-diagnostics", + "cairo-lang-executable", "cairo-lang-filesystem", "cairo-lang-formatter", "cairo-lang-lowering", diff --git a/Cargo.toml b/Cargo.toml index 0fbab768b..da5cca7ca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = "*" diff --git a/scarb/Cargo.toml b/scarb/Cargo.toml index d1d093ab7..50ad5100f 100644 --- a/scarb/Cargo.toml +++ b/scarb/Cargo.toml @@ -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 diff --git a/scarb/scarblib/cairo_execute/Scarb.toml b/scarb/scarblib/cairo_execute/Scarb.toml new file mode 100644 index 000000000..4d23c0e13 --- /dev/null +++ b/scarb/scarblib/cairo_execute/Scarb.toml @@ -0,0 +1,6 @@ +[package] +name = "cairo_execute" +version = "{{ CAIRO_VERSION }}" + +[cairo-plugin] +builtin = true diff --git a/scarb/src/compiler/compilers/executable.rs b/scarb/src/compiler/compilers/executable.rs new file mode 100644 index 000000000..e69de29bb diff --git a/scarb/src/compiler/plugin/builtin.rs b/scarb/src/compiler/plugin/builtin.rs index 32d71a816..a16eaa368 100644 --- a/scarb/src/compiler/plugin/builtin.rs +++ b/scarb/src/compiler/plugin/builtin.rs @@ -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; @@ -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> { + 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 { diff --git a/scarb/src/compiler/plugin/mod.rs b/scarb/src/compiler/plugin/mod.rs index 30838566f..86f6d153d 100644 --- a/scarb/src/compiler/plugin/mod.rs +++ b/scarb/src/compiler/plugin/mod.rs @@ -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; @@ -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(); diff --git a/scarb/src/core/package/name.rs b/scarb/src/core/package/name.rs index c84ae2c83..66529887a 100644 --- a/scarb/src/core/package/name.rs +++ b/scarb/src/core/package/name.rs @@ -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. @@ -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 = diff --git a/scarb/src/lib.rs b/scarb/src/lib.rs index 673632428..d6794a6dc 100644 --- a/scarb/src/lib.rs +++ b/scarb/src/lib.rs @@ -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"; diff --git a/scarb/src/ops/resolve.rs b/scarb/src/ops/resolve.rs index b0a822353..b0550b7da 100644 --- a/scarb/src/ops/resolve.rs +++ b/scarb/src/ops/resolve.rs @@ -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) diff --git a/utils/scarb-test-support/src/project_builder.rs b/utils/scarb-test-support/src/project_builder.rs index 2ca0dbee5..e61b83c4a 100644 --- a/utils/scarb-test-support/src/project_builder.rs +++ b/utils/scarb-test-support/src/project_builder.rs @@ -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") }