Skip to content

Commit a6c1e22

Browse files
committed
Add option to extract functions debug info to configs
commit-id:c5d50d84
1 parent ae1927b commit a6c1e22

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

crates/cairo-lang-compiler/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ pub struct CompilerConfig<'a> {
4747
pub replace_ids: bool,
4848

4949
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler) to
50-
/// [cairo_lang_sierra::debug_info::Annotations] in [cairo_lang_sierra::debug_info::DebugInfo].
50+
/// [Annotations] in [DebugInfo].
5151
pub add_statements_functions: bool,
5252

5353
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
54-
/// [cairo_lang_sierra::debug_info::Annotations] in [cairo_lang_sierra::debug_info::DebugInfo].
54+
/// [Annotations] in [DebugInfo].
5555
pub add_statements_code_locations: bool,
56+
57+
/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger) to
58+
/// [Annotations] in [DebugInfo] in the compiled tests.
59+
pub add_functions_debug_info: bool,
5660
}
5761

5862
/// Compiles a Cairo project at the given path.
@@ -346,6 +350,12 @@ pub fn compile_prepared_db_program_artifact_for_functions<'db>(
346350
))
347351
};
348352

353+
if compiler_config.add_functions_debug_info {
354+
annotations.extend(Annotations::from(
355+
sierra_program_with_debug.debug_info.functions_info.extract_serializable_debug_info(db),
356+
))
357+
}
358+
349359
let debug_info = DebugInfo {
350360
type_names: Default::default(),
351361
libfunc_names: Default::default(),

crates/cairo-lang-starknet/src/compile.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ fn compile_contract_with_prepared_and_checked_db<'db>(
167167
annotations.extend(Annotations::from(statements_functions))
168168
};
169169

170+
if compiler_config.add_functions_debug_info {
171+
annotations.extend(Annotations::from(
172+
debug_info.functions_info.extract_serializable_debug_info(db),
173+
))
174+
}
175+
170176
let abi_builder: Option<AbiBuilder<'db>> =
171177
AbiBuilder::from_submodule(db, contract.submodule_id, Default::default()).ok();
172178
let finalized_abi =

crates/cairo-lang-starknet/src/test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ pub fn get_test_contract(example_file_name: &str) -> ContractClass {
8484
diagnostics_reporter,
8585
add_statements_functions: false,
8686
add_statements_code_locations: false,
87+
add_functions_debug_info: false,
8788
},
8889
)
8990
.expect("compile_path failed")

crates/cairo-lang-test-plugin/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ pub struct TestsCompilationConfig<'db> {
7272
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
7373
/// [Annotations] in [DebugInfo] in the compiled tests.
7474
pub add_statements_code_locations: bool,
75+
76+
/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger) to
77+
/// [Annotations] in [DebugInfo] in the compiled tests.
78+
pub add_functions_debug_info: bool,
7579
}
7680

7781
/// Runs Cairo compiler.
@@ -172,6 +176,12 @@ pub fn compile_test_prepared_db<'db>(
172176
))
173177
}
174178

179+
if tests_compilation_config.add_functions_debug_info {
180+
annotations.extend(Annotations::from(
181+
debug_info.functions_info.extract_serializable_debug_info(db),
182+
))
183+
}
184+
175185
let executables = collect_executables(db, executable_functions, &sierra_program);
176186
let named_tests = all_tests
177187
.into_iter()

crates/cairo-lang-test-runner/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ impl<'db> TestRunner<'db> {
7575
contract_declarations: None,
7676
contract_crate_ids: None,
7777
executable_crate_ids: None,
78+
add_functions_debug_info: false,
7879
},
7980
)?;
8081
Ok(Self { compiler, config, custom_hint_processor_factory: None })

crates/cairo-lang-test-runner/src/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn test_compiled_serialization() {
2121
starknet: true,
2222
add_statements_functions: false,
2323
add_statements_code_locations: false,
24+
add_functions_debug_info: false,
2425
contract_declarations: None,
2526
contract_crate_ids: None,
2627
executable_crate_ids: None,

0 commit comments

Comments
 (0)