diff --git a/scarb/src/compiler/compilers/lib.rs b/scarb/src/compiler/compilers/lib.rs index 948969022..7e364255e 100644 --- a/scarb/src/compiler/compilers/lib.rs +++ b/scarb/src/compiler/compilers/lib.rs @@ -56,10 +56,10 @@ impl Compiler for LibCompiler { let target_dir = unit.target_dir(ws); - let compiler_config = build_compiler_config(&unit, ws); - let main_crate_ids = collect_main_crate_ids(&unit, db); + let compiler_config = build_compiler_config(&unit, &main_crate_ids, ws); + validate_compiler_config(db, &compiler_config, &unit, ws); let sierra_program: VersionedProgram = { diff --git a/scarb/src/compiler/compilers/starknet_contract.rs b/scarb/src/compiler/compilers/starknet_contract.rs index 1e626a7cf..dfa6de2aa 100644 --- a/scarb/src/compiler/compilers/starknet_contract.rs +++ b/scarb/src/compiler/compilers/starknet_contract.rs @@ -227,10 +227,10 @@ impl Compiler for StarknetContractCompiler { let target_dir = unit.target_dir(ws); - let compiler_config = build_compiler_config(&unit, ws); - let main_crate_ids = collect_main_crate_ids(&unit, db); + let compiler_config = build_compiler_config(&unit, &main_crate_ids, ws); + let contracts = find_project_contracts( db.upcast_mut(), ws.config().ui(), diff --git a/scarb/src/compiler/compilers/test.rs b/scarb/src/compiler/compilers/test.rs index 423b4ba3c..1b718222a 100644 --- a/scarb/src/compiler/compilers/test.rs +++ b/scarb/src/compiler/compilers/test.rs @@ -32,7 +32,8 @@ impl Compiler for TestCompiler { && plugin.package.id.source_id == SourceId::for_std() }); - let diagnostics_reporter = build_compiler_config(&unit, ws).diagnostics_reporter; + let diagnostics_reporter = + build_compiler_config(&unit, &main_crate_ids, ws).diagnostics_reporter; diagnostics_reporter .with_crates(&main_crate_ids) diff --git a/scarb/src/compiler/helpers.rs b/scarb/src/compiler/helpers.rs index 899d0d43a..40436f1f9 100644 --- a/scarb/src/compiler/helpers.rs +++ b/scarb/src/compiler/helpers.rs @@ -16,6 +16,7 @@ use crate::flock::Filesystem; pub fn build_compiler_config<'c>( unit: &CairoCompilationUnit, + main_crate_ids: &[CrateId], ws: &Workspace<'c>, ) -> CompilerConfig<'c> { let diagnostics_reporter = DiagnosticsReporter::callback({ @@ -43,7 +44,8 @@ pub fn build_compiler_config<'c>( } }; } - }); + }) + .with_crates(main_crate_ids); CompilerConfig { diagnostics_reporter: if unit.compiler_config.allow_warnings { diagnostics_reporter.allow_warnings() diff --git a/scarb/src/ops/compile.rs b/scarb/src/ops/compile.rs index 01aeb1648..83f6ed6a8 100644 --- a/scarb/src/ops/compile.rs +++ b/scarb/src/ops/compile.rs @@ -11,7 +11,7 @@ use scarb_ui::components::Status; use scarb_ui::HumanDuration; use crate::compiler::db::{build_scarb_root_database, has_starknet_plugin, ScarbDatabase}; -use crate::compiler::helpers::build_compiler_config; +use crate::compiler::helpers::{build_compiler_config, collect_main_crate_ids}; use crate::compiler::plugin::proc_macro; use crate::compiler::{CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes}; use crate::core::{ @@ -193,8 +193,9 @@ fn check_unit(unit: CompilationUnit, ws: &Workspace<'_>) -> Result<()> { CompilationUnit::ProcMacro(unit) => proc_macro::check_unit(unit, ws), CompilationUnit::Cairo(unit) => { let ScarbDatabase { db, .. } = build_scarb_root_database(&unit, ws)?; + let main_crate_ids = collect_main_crate_ids(&unit, &db); check_starknet_dependency(&unit, ws, &db, &package_name); - let mut compiler_config = build_compiler_config(&unit, ws); + let mut compiler_config = build_compiler_config(&unit, &main_crate_ids, ws); compiler_config .diagnostics_reporter .ensure(&db) diff --git a/scarb/src/ops/expand.rs b/scarb/src/ops/expand.rs index dad0c228e..3ecd0b5ad 100644 --- a/scarb/src/ops/expand.rs +++ b/scarb/src/ops/expand.rs @@ -158,12 +158,12 @@ fn do_expand( ws: &Workspace<'_>, ) -> Result<()> { let ScarbDatabase { db, .. } = build_scarb_root_database(compilation_unit, ws)?; - let mut compiler_config = build_compiler_config(compilation_unit, ws); - // Report diagnostics, but do not fail. - let _ = compiler_config.diagnostics_reporter.check(&db); let main_crate_id = db.intern_crate(CrateLongId::Real( compilation_unit.main_component().cairo_package_name(), )); + let mut compiler_config = build_compiler_config(compilation_unit, &[main_crate_id], ws); + // Report diagnostics, but do not fail. + let _ = compiler_config.diagnostics_reporter.check(&db); let main_module = ModuleId::CrateRoot(main_crate_id); let module_file = db .module_main_file(main_module) diff --git a/scarb/tests/build.rs b/scarb/tests/build.rs index 67633a073..39bbd76f8 100644 --- a/scarb/tests/build.rs +++ b/scarb/tests/build.rs @@ -862,6 +862,57 @@ fn warnings_can_be_disallowed() { "#}); } +#[test] +fn does_not_show_warnings_from_deps() { + let t = TempDir::new().unwrap(); + let first = t.child("first"); + let second = t.child("second"); + ProjectBuilder::start() + .name("first") + .lib_cairo(indoc! {r#" + fn hello() -> felt252 { + let a = 41; + let b = 42; + b + } + "#}) + .manifest_extra(indoc! {r#" + [cairo] + allow-warnings = false + "#}) + .build(&first); + ProjectBuilder::start() + .name("second") + .lib_cairo(indoc! {r#" + fn hello() -> felt252 { 42 } + "#}) + .dep("first", &first) + .manifest_extra(indoc! {r#" + [cairo] + allow-warnings = false + "#}) + .build(&second); + Scarb::quick_snapbox() + .arg("build") + .current_dir(&first) + .assert() + .failure() + .stdout_matches(indoc! {r#" + [..] Compiling [..] v1.0.0 ([..]Scarb.toml) + warn[E0001]: Unused variable. Consider ignoring by prefixing with `_`. + --> [..]lib.cairo:2:9 + let a = 41; + ^ + + error: could not compile [..] due to previous error + "#}); + Scarb::quick_snapbox() + .arg("build") + .current_dir(&second) + .assert() + .success(); +} + #[test] fn error_codes_shown_in_json_output() { let t = TempDir::new().unwrap();