Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(dojo-lang): output debug info conditionally #2411

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions bin/sozo/src/commands/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@
/// Specify packages to build.
#[command(flatten)]
pub packages: Option<PackagesFilter>,

#[arg(long)]
#[arg(help = "Output the Sierra debug information for the compiled contracts.")]
pub output_debug_info: bool,

Check warning on line 53 in bin/sozo/src/commands/build.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/build.rs#L53

Added line #L53 was not covered by tests
}

impl BuildArgs {
Expand Down Expand Up @@ -167,6 +171,7 @@
bindings_output: "bindings".to_string(),
stats: false,
packages: None,
output_debug_info: false,

Check warning on line 174 in bin/sozo/src/commands/build.rs

View check run for this annotation

Codecov / codecov/patch

bin/sozo/src/commands/build.rs#L174

Added line #L174 was not covered by tests
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions bin/sozo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,16 @@ fn cli_main(args: SozoArgs) -> Result<()> {
let cairo_plugins = CairoPluginRepository::default();

match &args.command {
Commands::Build(_) | Commands::Dev(_) | Commands::Migrate(_) => {
Commands::Build(args) => {
trace!("Adding DojoCompiler to compiler repository.");
compilers.add(Box::new(DojoCompiler)).unwrap()
compilers.add(Box::new(DojoCompiler::new(args.output_debug_info))).unwrap()
}

Commands::Dev(_) | Commands::Migrate(_) => {
trace!("Adding DojoCompiler to compiler repository.");
compilers.add(Box::new(DojoCompiler::default())).unwrap()
}

_ => {}
}

Expand Down
21 changes: 16 additions & 5 deletions crates/dojo-lang/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,21 @@ pub(crate) const LOG_TARGET: &str = "dojo_lang::compiler";
#[path = "compiler_test.rs"]
mod test;

#[derive(Debug)]
pub struct DojoCompiler;
#[derive(Debug, Default)]
pub struct DojoCompiler {
/// Output the debug information of the compiled Sierra contracts.
///
/// Mainly used for the Walnut debugger integration. It is used
/// internally by Walnut to build the Dojo project with the Sierra
/// debug information. This flag has no use outside of that.
output_debug_info: bool,
}

impl DojoCompiler {
pub fn new(output_debug_info: bool) -> Self {
Self { output_debug_info }
}
}

#[derive(Debug, Default, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -143,9 +156,7 @@ impl Compiler for DojoCompiler {
compile_prepared_db(db, &contracts, compiler_config)?
};

// TODO: get the debug flag from the `dojo_<profile>.toml` file.
let with_debug_info = true;
let debug_info_classes: Vec<Option<SierraToCairoDebugInfo>> = if with_debug_info {
let debug_info_classes: Vec<Option<SierraToCairoDebugInfo>> = if self.output_debug_info {
let debug_classes =
crate::scarb_internal::debug::compile_prepared_db_to_debug_info(db, &contracts)?;

Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-test-utils/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ pub fn copy_project_temp(
/// * `profile` - The profile to use for the config.
pub fn build_test_config(path: &str, profile: Profile) -> anyhow::Result<Config> {
let mut compilers = CompilerRepository::empty();
compilers.add(Box::new(DojoCompiler)).unwrap();
compilers.add(Box::new(DojoCompiler::default())).unwrap();

let cairo_plugins = CairoPluginRepository::default();

Expand Down
Loading