Skip to content

Commit 629c819

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

File tree

4 files changed

+81
-8
lines changed

4 files changed

+81
-8
lines changed

.github/workflows/committer_and_os_cli_push.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,21 @@ jobs:
6565
COMMIT_SHA: ${{ github.event.after }}
6666
run: echo "SHORT_HASH=${COMMIT_SHA:0:7}" >> $GITHUB_ENV
6767

68+
# Setup pypy and link to the location expected by .cargo/config.toml.
69+
# Python + requirements are needed to compile the OS.
70+
- uses: actions/setup-python@v5
71+
id: setup-pypy
72+
with:
73+
python-version: "pypy3.9"
74+
cache: 'pip'
75+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
76+
- env:
77+
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
78+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
79+
- run: pip install -r scripts/requirements.txt
80+
6881
- name: Build CLI binary
69-
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
82+
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
7083

7184
- id: auth
7285
uses: "google-github-actions/auth@v2"

.github/workflows/committer_ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ 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+
# Python + requirements are needed to compile the OS.
42+
- uses: actions/setup-python@v5
43+
id: setup-pypy
44+
with:
45+
python-version: "pypy3.9"
46+
cache: 'pip'
47+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
48+
- env:
49+
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
50+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
51+
- run: pip install -r scripts/requirements.txt
52+
53+
# Bootstrap.
3954
- uses: ./.github/actions/bootstrap
4055
with:
4156
github_token: ${{ secrets.GITHUB_TOKEN }}
@@ -57,6 +72,21 @@ jobs:
5772
- uses: actions/checkout@v4
5873
with:
5974
ref: ${{ github.base_ref }}
75+
76+
# Setup pypy and link to the location expected by .cargo/config.toml.
77+
# Python + requirements are needed to compile the OS.
78+
- uses: actions/setup-python@v5
79+
id: setup-pypy
80+
with:
81+
python-version: "pypy3.9"
82+
cache: 'pip'
83+
- run: ln -s '${{ steps.setup-pypy.outputs.python-path }}' /usr/local/bin/pypy3.9
84+
- env:
85+
LD_LIBRARY_PATH: ${{ env.Python3_ROOT_DIR }}/bin
86+
run: echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH}" >> $GITHUB_ENV
87+
- run: pip install -r scripts/requirements.txt
88+
89+
# Bootstrap.
6090
- uses: ./.github/actions/bootstrap
6191
with:
6292
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)