Skip to content

Commit e33ac04

Browse files
fix(ci): allow service CLI access to cairo-compile
Signed-off-by: Dori Medini <dori@starkware.co>
1 parent 9ba7bc7 commit e33ac04

4 files changed

Lines changed: 66 additions & 8 deletions

File tree

.github/workflows/committer_and_os_cli_push.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565
run: echo "SHORT_HASH=${COMMIT_SHA:0:7}" >> $GITHUB_ENV
6666

6767
- name: Build CLI binary
68-
run: ./build_native_in_docker.sh rustup toolchain install && cargo build -p starknet_committer_and_os_cli -r --bin starknet_committer_and_os_cli --target-dir CLI_TARGET
68+
run: ./build_native_in_docker.sh cargo build -p starknet_committer_and_os_cli -r --bin starknet_committer_and_os_cli --target-dir CLI_TARGET
6969

7070
- id: auth
7171
uses: "google-github-actions/auth@v2"

.github/workflows/committer_ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@ jobs:
3636
if: ${{ github.event_name == 'pull_request' }}
3737
steps:
3838
- uses: actions/checkout@v4
39+
40+
# Setup pypy and link to the location expected by .cargo/config.toml.
41+
- uses: actions/setup-python@v5
42+
id: setup-pypy
43+
with:
44+
python-version: "pypy3.9"
45+
cache: 'pip'
46+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
47+
- env:
48+
LD_LIBRARY_PATH: ${{ steps.setup-pypy.outputs.pythonLocation }}/bin
49+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
50+
- run: pip install -r scripts/requirements.txt
51+
52+
# Bootstrap.
3953
- uses: ./.github/actions/bootstrap
4054
with:
4155
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -57,6 +71,20 @@ jobs:
5771
- uses: actions/checkout@v4
5872
with:
5973
ref: ${{ github.base_ref }}
74+
75+
# Setup pypy and link to the location expected by .cargo/config.toml.
76+
- uses: actions/setup-python@v5
77+
id: setup-pypy
78+
with:
79+
python-version: "pypy3.9"
80+
cache: 'pip'
81+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
82+
- env:
83+
LD_LIBRARY_PATH: ${{ steps.setup-pypy.outputs.pythonLocation }}/bin
84+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
85+
- run: pip install -r scripts/requirements.txt
86+
87+
# Bootstrap.
6088
- uses: ./.github/actions/bootstrap
6189
with:
6290
github_token: ${{ secrets.GITHUB_TOKEN }}

crates/starknet_committer_and_os_cli/src/os_cli/commands.rs

Lines changed: 13 additions & 4 deletions
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, OS_PROGRAM_BYTES};
4+
use apollo_starknet_os_program::{CAIRO_FILES_MAP, OS_PROGRAM_BYTES, PROGRAM_HASH};
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;
@@ -14,7 +14,7 @@ use starknet_os::io::os_output::StarknetOsRunnerOutput;
1414
use starknet_os::runner::run_os_stateless;
1515
use tracing::info;
1616

17-
use super::run_os_cli::OsCliOutput;
17+
use crate::os_cli::run_os_cli::{OsCliOutput, ProgramToDump};
1818
use crate::shared_utils::read::{load_input, write_to_file};
1919

2020
#[derive(Deserialize, Debug)]
@@ -107,8 +107,17 @@ pub(crate) fn dump_source_files(output_path: String) {
107107
write_to_file(&output_path, &*CAIRO_FILES_MAP);
108108
}
109109

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)
110+
pub(crate) fn dump_program(output_path: String, program: ProgramToDump) {
111+
let bytes = match program {
112+
ProgramToDump::Os => OS_PROGRAM_BYTES,
113+
};
114+
// Dumping the `Program` struct won't work - it is not deserializable via cairo-lang's Program
115+
// class. JSONify the raw bytes instead.
116+
let os_program_json = serde_json::from_slice::<serde_json::Value>(bytes)
112117
.expect("OS bytes are JSON-serializable.");
113118
write_to_file(&output_path, &os_program_json);
114119
}
120+
121+
pub(crate) fn dump_program_hash(output_path: String) {
122+
write_to_file(&output_path, &*PROGRAM_HASH);
123+
}

crates/starknet_committer_and_os_cli/src/os_cli/run_os_cli.rs

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

12-
use crate::os_cli::commands::{dump_os_program, dump_source_files, parse_and_run_os};
12+
use crate::os_cli::commands::{
13+
dump_program,
14+
dump_program_hash,
15+
dump_source_files,
16+
parse_and_run_os,
17+
};
1318
use crate::os_cli::tests::python_tests::OsPythonTestRunner;
1419
use crate::shared_utils::types::{run_python_test, IoArgs, PythonTestArg};
1520

@@ -19,9 +24,24 @@ pub struct OsCliCommand {
1924
command: Command,
2025
}
2126

27+
#[derive(clap::ValueEnum, Clone, Debug, Serialize)]
28+
#[serde(rename_all = "kebab-case")]
29+
pub enum ProgramToDump {
30+
Os,
31+
}
32+
2233
#[derive(Debug, Subcommand)]
2334
enum Command {
24-
DumpOsProgram {
35+
DumpProgram {
36+
/// File path to output.
37+
#[clap(long, short = 'o', default_value = "stdout")]
38+
output_path: String,
39+
40+
/// Program to dump.
41+
#[clap(long, value_enum)]
42+
program: ProgramToDump,
43+
},
44+
DumpProgramHash {
2545
/// File path to output.
2646
#[clap(long, short = 'o', default_value = "stdout")]
2747
output_path: String,
@@ -44,7 +64,8 @@ pub async fn run_os_cli(
4464
) {
4565
info!("Starting starknet-os-cli with command: \n{:?}", os_command);
4666
match os_command.command {
47-
Command::DumpOsProgram { output_path } => dump_os_program(output_path),
67+
Command::DumpProgram { output_path, program } => dump_program(output_path, program),
68+
Command::DumpProgramHash { output_path } => dump_program_hash(output_path),
4869
Command::DumpSourceFiles { output_path } => dump_source_files(output_path),
4970
Command::PythonTest(python_test_arg) => {
5071
run_python_test::<OsPythonTestRunner>(python_test_arg).await;

0 commit comments

Comments
 (0)