Skip to content

Commit 4061106

Browse files
feat(starknet_committer_and_os_cli): add command to dump the OS compiled program to file
1 parent c57c217 commit 4061106

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_starknet_os_program/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ use crate::program_hash::{ProgramHash, PROGRAM_HASH_PATH};
77

88
pub mod program_hash;
99

10+
pub const OS_PROGRAM_BYTES: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/starknet_os_bytes"));
11+
1012
pub const OS_PROGRAM: LazyLock<Program> = LazyLock::new(|| {
11-
Program::from_bytes(
12-
include_bytes!(concat!(env!("OUT_DIR"), "/starknet_os_bytes")),
13-
Some("main"),
14-
)
15-
.expect("Failed to load the OS bytes.")
13+
Program::from_bytes(OS_PROGRAM_BYTES, Some("main")).expect("Failed to load the OS bytes.")
1614
});
1715

1816
pub const PROGRAM_HASH: LazyLock<ProgramHash> = LazyLock::new(|| {

crates/starknet_committer_and_os_cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ tempfile.workspace = true
1818

1919
# TODO(Amos): Add `testing` feature and move Python test dependencies under it.
2020
[dependencies]
21+
apollo_starknet_os_program.workspace = true
2122
cairo-lang-starknet-classes.workspace = true
2223
cairo-vm.workspace = true # Should be moved under `testing` feature, when it exists.
2324
clap = { workspace = true, features = ["cargo", "derive"] }

crates/starknet_committer_and_os_cli/src/os_cli/commands.rs

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

4+
use apollo_starknet_os_program::OS_PROGRAM_BYTES;
45
use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
56
use cairo_vm::types::layout_name::LayoutName;
67
use rand_distr::num_traits::Zero;
@@ -73,3 +74,9 @@ pub fn parse_and_run_os(input_path: String, output_path: String) {
7374
write_to_file(&output_path, &output);
7475
info!("OS program ran successfully.");
7576
}
77+
78+
pub(crate) fn dump_os_program(output_path: String) {
79+
let os_program_json = serde_json::from_slice::<serde_json::Value>(OS_PROGRAM_BYTES)
80+
.expect("OS bytes are JSON-serializable.");
81+
write_to_file(&output_path, &os_program_json);
82+
}

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
@@ -4,7 +4,7 @@ use tracing::level_filters::LevelFilter;
44
use tracing_subscriber::reload::Handle;
55
use tracing_subscriber::Registry;
66

7-
use crate::os_cli::commands::parse_and_run_os;
7+
use crate::os_cli::commands::{dump_os_program, parse_and_run_os};
88
use crate::os_cli::tests::python_tests::OsPythonTestRunner;
99
use crate::shared_utils::types::{run_python_test, IoArgs, PythonTestArg};
1010

@@ -16,6 +16,11 @@ pub struct OsCliCommand {
1616

1717
#[derive(Debug, Subcommand)]
1818
enum Command {
19+
DumpOsProgram {
20+
/// File path to output.
21+
#[clap(long, short = 'o', default_value = "stdout")]
22+
output_path: String,
23+
},
1924
PythonTest(PythonTestArg),
2025
RunOsStateless {
2126
#[clap(flatten)]
@@ -29,6 +34,7 @@ pub async fn run_os_cli(
2934
) {
3035
info!("Starting starknet-os-cli with command: \n{:?}", os_command);
3136
match os_command.command {
37+
Command::DumpOsProgram { output_path } => dump_os_program(output_path),
3238
Command::PythonTest(python_test_arg) => {
3339
run_python_test::<OsPythonTestRunner>(python_test_arg).await;
3440
}

0 commit comments

Comments
 (0)