Skip to content
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
18 changes: 14 additions & 4 deletions crates/cairo-lang-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ pub struct CompilerConfig<'a> {
/// Replaces Sierra IDs with human-readable ones.
pub replace_ids: bool,

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

/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
/// [cairo_lang_sierra::debug_info::Annotations] in [cairo_lang_sierra::debug_info::DebugInfo].
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage)
/// to [Annotations] in [DebugInfo].
pub add_statements_code_locations: bool,

/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger)
/// to [Annotations] in [DebugInfo] in the compiled tests.
pub add_functions_debug_info: bool,
}

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

if compiler_config.add_functions_debug_info {
annotations.extend(Annotations::from(
sierra_program_with_debug.debug_info.functions_info.extract_serializable_debug_info(db),
))
}

let debug_info = DebugInfo {
type_names: Default::default(),
libfunc_names: Default::default(),
Expand Down
6 changes: 6 additions & 0 deletions crates/cairo-lang-starknet/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ fn compile_contract_with_prepared_and_checked_db<'db>(
annotations.extend(Annotations::from(statements_functions))
};

if compiler_config.add_functions_debug_info {
annotations.extend(Annotations::from(
debug_info.functions_info.extract_serializable_debug_info(db),
))
}

let abi_builder: Option<AbiBuilder<'db>> =
AbiBuilder::from_submodule(db, contract.submodule_id, Default::default()).ok();
let finalized_abi =
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-starknet/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn get_test_contract(example_file_name: &str) -> ContractClass {
diagnostics_reporter,
add_statements_functions: false,
add_statements_code_locations: false,
add_functions_debug_info: false,
},
)
.expect("compile_path failed")
Expand Down
18 changes: 14 additions & 4 deletions crates/cairo-lang-test-plugin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,17 @@ pub struct TestsCompilationConfig<'db> {
/// If not defined, test crates will be searched.
pub executable_crate_ids: Option<Vec<CrateId<'db>>>,

/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler) to
/// [Annotations] in [DebugInfo] in the compiled tests.
/// Adds a mapping used by [cairo-profiler](https://github.com/software-mansion/cairo-profiler)
/// to [Annotations] in [DebugInfo] in the compiled tests.
pub add_statements_functions: bool,

/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage) to
/// [Annotations] in [DebugInfo] in the compiled tests.
/// Adds a mapping used by [cairo-coverage](https://github.com/software-mansion/cairo-coverage)
/// to [Annotations] in [DebugInfo] in the compiled tests.
pub add_statements_code_locations: bool,

/// Adds a mapping used by [cairo-debugger](https://github.com/software-mansion-labs/cairo-debugger)
/// to [Annotations] in [DebugInfo] in the compiled tests.
pub add_functions_debug_info: bool,
}

/// Runs Cairo compiler.
Expand Down Expand Up @@ -172,6 +176,12 @@ pub fn compile_test_prepared_db<'db>(
))
}

if tests_compilation_config.add_functions_debug_info {
annotations.extend(Annotations::from(
debug_info.functions_info.extract_serializable_debug_info(db),
))
}

let executables = collect_executables(db, executable_functions, &sierra_program);
let named_tests = all_tests
.into_iter()
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-test-runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ impl<'db> TestRunner<'db> {
contract_declarations: None,
contract_crate_ids: None,
executable_crate_ids: None,
add_functions_debug_info: false,
},
)?;
Ok(Self { compiler, config, custom_hint_processor_factory: None })
Expand Down
1 change: 1 addition & 0 deletions crates/cairo-lang-test-runner/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn test_compiled_serialization() {
starknet: true,
add_statements_functions: false,
add_statements_code_locations: false,
add_functions_debug_info: false,
contract_declarations: None,
contract_crate_ids: None,
executable_crate_ids: None,
Expand Down