Skip to content

Commit e94a773

Browse files
feat(starknet_committer_and_os_cli): add command to dump the OS compiled program to file
1 parent 62086e7 commit e94a773

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

crates/apollo_starknet_os_program/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ pub static CAIRO_FILES_MAP: LazyLock<HashMap<String, String>> = LazyLock::new(||
1414
.unwrap_or_else(|error| panic!("Failed to deserialize cairo_files_map.json: {error:?}."))
1515
});
1616

17+
pub const OS_PROGRAM_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/starknet_os_bytes"));
18+
1719
pub static OS_PROGRAM: LazyLock<Program> = LazyLock::new(|| {
18-
Program::from_bytes(
19-
include_bytes!(concat!(env!("OUT_DIR"), "/starknet_os_bytes")),
20-
Some("main"),
21-
)
22-
.expect("Failed to load the OS bytes.")
20+
Program::from_bytes(OS_PROGRAM_BYTES, Some("main")).expect("Failed to load the OS bytes.")
2321
});
2422

2523
pub static PROGRAM_HASH: LazyLock<ProgramHash> = LazyLock::new(|| {

crates/starknet_committer_and_os_cli/src/os_cli/commands.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs;
22
use std::path::Path;
33

4-
use apollo_starknet_os_program::CAIRO_FILES_MAP;
4+
use apollo_starknet_os_program::{CAIRO_FILES_MAP, OS_PROGRAM_BYTES};
55
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
66
use cairo_vm::types::layout_name::LayoutName;
77
use cairo_vm::vm::runners::cairo_pie::CairoPie;
@@ -106,3 +106,9 @@ pub(crate) fn serialize_os_runner_output(
106106
pub(crate) fn dump_source_files(output_path: String) {
107107
write_to_file(&output_path, &*CAIRO_FILES_MAP);
108108
}
109+
110+
pub(crate) fn dump_os_program(output_path: String) {
111+
let os_program_json = serde_json::from_slice::<serde_json::Value>(OS_PROGRAM_BYTES)
112+
.expect("OS bytes are JSON-serializable.");
113+
write_to_file(&output_path, &os_program_json);
114+
}

crates/starknet_committer_and_os_cli/src/os_cli/run_os_cli.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use tracing::level_filters::LevelFilter;
99
use tracing_subscriber::reload::Handle;
1010
use tracing_subscriber::Registry;
1111

12-
use crate::os_cli::commands::{dump_source_files, parse_and_run_os};
12+
use crate::os_cli::commands::{dump_os_program, dump_source_files, parse_and_run_os};
1313
use crate::os_cli::tests::python_tests::OsPythonTestRunner;
1414
use crate::shared_utils::types::{run_python_test, IoArgs, PythonTestArg};
1515

@@ -21,6 +21,11 @@ pub struct OsCliCommand {
2121

2222
#[derive(Debug, Subcommand)]
2323
enum Command {
24+
DumpOsProgram {
25+
/// File path to output.
26+
#[clap(long, short = 'o', default_value = "stdout")]
27+
output_path: String,
28+
},
2429
DumpSourceFiles {
2530
/// File path to output.
2631
#[clap(long, short = 'o')]
@@ -39,6 +44,7 @@ pub async fn run_os_cli(
3944
) {
4045
info!("Starting starknet-os-cli with command: \n{:?}", os_command);
4146
match os_command.command {
47+
Command::DumpOsProgram { output_path } => dump_os_program(output_path),
4248
Command::DumpSourceFiles { output_path } => dump_source_files(output_path),
4349
Command::PythonTest(python_test_arg) => {
4450
run_python_test::<OsPythonTestRunner>(python_test_arg).await;

0 commit comments

Comments
 (0)