diff --git a/bin/sozo/src/commands/test.rs b/bin/sozo/src/commands/test.rs index 26ca29708c..f2ec499041 100644 --- a/bin/sozo/src/commands/test.rs +++ b/bin/sozo/src/commands/test.rs @@ -90,19 +90,18 @@ impl TestArgs { opts.include_target_kinds.is_empty() || opts.include_target_kinds.contains(&cu.main_component().target_kind()) }) - // TODOL: Need to find how to filter from packages with the compilation unit. We need something - // implementing PackagesSource trait. .collect::>(); for unit in compilation_units { - tracing::trace!(unit = %unit.name(), "Adding unit to test runner."); - let unit = if let CompilationUnit::Cairo(unit) = unit { unit } else { continue; }; + // Injecting the cfg_set for the unit makes compiler panics. + // We rely then on the default namespace for testing...? + let props: Props = unit.main_component().target_props()?; let db = build_root_database(&unit)?; @@ -162,10 +161,10 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { let crate_roots = unit .components .iter() - .filter(|model| !model.package.id.is_core()) + .filter(|c| !c.package.id.is_core()) // NOTE: We're taking the first target of each compilation unit, which should always be the // main package source root due to the order maintained by scarb. - .map(|model| (model.cairo_package_name(), model.targets[0].source_root().into())) + .map(|c| (c.cairo_package_name(), c.targets[0].source_root().into())) .collect(); let corelib = diff --git a/crates/dojo-core/Scarb.lock b/crates/dojo-core/Scarb.lock index ecaaf70855..8300b4910d 100644 --- a/crates/dojo-core/Scarb.lock +++ b/crates/dojo-core/Scarb.lock @@ -11,4 +11,4 @@ dependencies = [ [[package]] name = "dojo_plugin" version = "0.7.3" -source = "git+https://github.com/dojoengine/dojo?rev=d90b52b#d90b52b89749ac8af82f352dc08aa0b1378cfae6" +source = "git+https://github.com/dojoengine/dojo?rev=71b1f1a4#71b1f1a467534cbeeb901356f41e612ed4187bd1" diff --git a/crates/dojo-core/Scarb.toml b/crates/dojo-core/Scarb.toml index 93f1602bcd..562a957280 100644 --- a/crates/dojo-core/Scarb.toml +++ b/crates/dojo-core/Scarb.toml @@ -8,7 +8,7 @@ version = "0.7.3" [dependencies] # Rev points to support for Cairo 2.7.0-rc.3 without any tag yet. Should be # updated once a release is cut with `2.7.0-rc.3` support in it. -dojo_plugin = { git = "https://github.com/dojoengine/dojo", rev = "d90b52b" } +dojo_plugin = { git = "https://github.com/dojoengine/dojo", rev = "71b1f1a4" } starknet = "=2.7.0-rc.3" [lib] diff --git a/crates/dojo-lang/src/plugin.rs b/crates/dojo-lang/src/plugin.rs index 8245a42d67..6abf100c19 100644 --- a/crates/dojo-lang/src/plugin.rs +++ b/crates/dojo-lang/src/plugin.rs @@ -7,6 +7,7 @@ use cairo_lang_defs::plugin::{ PluginDiagnostic, PluginGeneratedFile, PluginResult, }; use cairo_lang_diagnostics::Severity; +use cairo_lang_filesystem::cfg::Cfg; use cairo_lang_semantic::plugin::PluginSuite; use cairo_lang_starknet::plugin::aux_data::StarkNetEventAuxData; use cairo_lang_syntax::attribute::structured::{AttributeArgVariant, AttributeStructurize}; @@ -37,6 +38,7 @@ use crate::interface::DojoInterface; use crate::introspect::{handle_introspect_enum, handle_introspect_struct}; use crate::model::handle_model_struct; use crate::print::{handle_print_enum, handle_print_struct}; +use crate::utils; pub const DOJO_CONTRACT_ATTR: &str = "dojo::contract"; pub const DOJO_INTERFACE_ATTR: &str = "dojo::interface"; @@ -348,17 +350,37 @@ impl MacroPlugin for BuiltinDojoPlugin { item_ast: ast::ModuleItem, metadata: &MacroPluginMetadata<'_>, ) -> PluginResult { - // Metadata gives information from the crates from where `item_ast` was parsed. - // During the compilation phase, we inject namespace information into the `CfgSet` - // so that it can be used here. - let namespace_config: NamespaceConfig = metadata.cfg_set.into(); + let namespace_config: NamespaceConfig = if db.cfg_set().contains(&Cfg::kv("target", "test")) + { + // In test mode, we can't inject namespace information into the `CfgSet` + // as the compiler panics. + match utils::get_namespace_config(db) { + Ok(config) => config, + Err(e) => { + return PluginResult { + code: Option::None, + diagnostics: vec![PluginDiagnostic { + stable_ptr: item_ast.stable_ptr().0, + message: format!("{e}"), + severity: Severity::Error, + }], + remove_original_item: false, + }; + } + } + } else { + // Metadata gives information from the crates from where `item_ast` was parsed. + // During the compilation phase, we inject namespace information into the `CfgSet` + // so that it can be used here. + metadata.cfg_set.into() + }; // Avoid the whole plugin checks if there is no default namespace. // The compiler already checked for invalid package configuration, // so empty default namespace can be skipped. - if namespace_config.default.is_empty() { - return PluginResult::default(); - } + // if namespace_config.default.is_empty() { + // return PluginResult::default(); + // } match item_ast { ast::ModuleItem::Module(module_ast) => { diff --git a/crates/dojo-lang/src/scarb_internal/mod.rs b/crates/dojo-lang/src/scarb_internal/mod.rs index 81a2547540..9e72d835e7 100644 --- a/crates/dojo-lang/src/scarb_internal/mod.rs +++ b/crates/dojo-lang/src/scarb_internal/mod.rs @@ -201,7 +201,7 @@ fn build_project_config(unit: &CairoCompilationUnit) -> Result { } #[derive(Debug)] -struct PackageData { +pub struct PackageData { pub namespace_config: Option, } @@ -280,7 +280,7 @@ fn namespace_config_from_toml( Ok(None) } -fn cfg_set_from_component( +pub fn cfg_set_from_component( c: &CompilationUnitComponent, root_package_data: &PackageData, ui: &Ui, diff --git a/crates/dojo-lang/src/utils.rs b/crates/dojo-lang/src/utils.rs index 18f81a5cbe..1927a28585 100644 --- a/crates/dojo-lang/src/utils.rs +++ b/crates/dojo-lang/src/utils.rs @@ -18,16 +18,6 @@ pub fn get_namespace_config(db: &dyn SyntaxGroup) -> Result { // Super verbose print, but useful to get the CfgSet. // debug!(cfg_set = ?db.cfg_set(), crates = ?db.crates(), "Retrieving namespace // configuration."); - - if !db.cfg_set().contains(&cairo_lang_filesystem::cfg::Cfg { - key: "target".into(), - value: Some("dojo".into()), - }) { - // When a [lib] is compiled without the target "dojo", we shouldn't care about - // the namespace being retrieved. - return Ok(NamespaceConfig { default: "ignored_namespace".into(), mappings: None }); - } - let crates = db.crates(); if crates.is_empty() {