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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/apollo_starknet_os_program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ thiserror.workspace = true
[build-dependencies]
apollo_infra_utils.workspace = true
serde_json.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

[dev-dependencies]
apollo_infra_utils = { workspace = true, features = ["testing"] }
Expand Down
31 changes: 19 additions & 12 deletions crates/apollo_starknet_os_program/build/compile_program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ use std::path::PathBuf;
use apollo_infra_utils::cairo0_compiler::{compile_cairo0_program, Cairo0CompilerError};
use apollo_infra_utils::compile_time_cargo_manifest_dir;

fn compile_program(path_to_main_file: PathBuf) -> Vec<u8> {
match compile_cairo0_program(path_to_main_file, cairo_root_path()) {
pub async fn compile_and_output_program(
out_dir: PathBuf,
path_to_main_file_from_cairo_root: &str,
program_name: &str,
) {
println!("cargo::warning=Compiling {program_name} program...");
let bytes = match compile_cairo0_program(
cairo_root_path().join(path_to_main_file_from_cairo_root),
cairo_root_path(),
) {
Ok(bytes) => bytes,
Err(Cairo0CompilerError::Cairo0CompilerVersion(error)) => {
panic!(
Expand All @@ -15,19 +23,18 @@ fn compile_program(path_to_main_file: PathBuf) -> Vec<u8> {
)
}
Err(other_error) => {
panic!("Failed to compile the program. Error:\n{other_error}.")
panic!("Failed to compile the {program_name} program. Error:\n{other_error}.")
}
}
};
println!(
"cargo::warning=Done compiling {program_name}. Writing compiled bytes to output directory."
);
let bytes_path = out_dir.join(format!("{program_name}_bytes"));
std::fs::write(&bytes_path, &bytes).unwrap_or_else(|error| {
panic!("Failed to write the compiled {program_name} bytes to {bytes_path:?}: {error}.")
});
}

fn cairo_root_path() -> PathBuf {
PathBuf::from(compile_time_cargo_manifest_dir!()).join("src/cairo")
}

pub fn compile_starknet_os() -> Vec<u8> {
compile_program(cairo_root_path().join("starkware/starknet/core/os/os.cairo"))
}

pub fn compile_starknet_aggregator() -> Vec<u8> {
compile_program(cairo_root_path().join("starkware/starknet/core/aggregator/main.cairo"))
}
28 changes: 14 additions & 14 deletions crates/apollo_starknet_os_program/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ mod dump_source;
/// Build script for the `apollo_starknet_os_program` crate.
/// Recompiles the OS program if the source files change.
/// Optionally, also exposes all source cairo files in a mapping from file path to contents.
fn main() {
#[tokio::main]
async fn main() {
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("OUT_DIR not set."));

#[cfg(feature = "dump_source_files")]
dump_source::dump_source_files(&out_dir.join("cairo_files_map.json"));

println!("cargo::warning=Compiling Starknet OS program...");
let starknet_os_bytes = compile_program::compile_starknet_os();
println!("cargo::warning=Done. Writing compiled bytes to output directory.");
let starknet_os_bytes_path = out_dir.join("starknet_os_bytes");
std::fs::write(&starknet_os_bytes_path, &starknet_os_bytes)
.expect("Failed to write the compiled OS bytes to the output directory.");

println!("cargo::warning=Compiling Starknet aggregator program...");
let starknet_aggregator_bytes = compile_program::compile_starknet_aggregator();
println!("cargo::warning=Done. Writing compiled bytes to output directory.");
let starknet_aggregator_bytes_path = out_dir.join("starknet_aggregator_bytes");
std::fs::write(&starknet_aggregator_bytes_path, &starknet_aggregator_bytes)
.expect("Failed to write the compiled aggregator bytes to the output directory.");
let mut task_set = tokio::task::JoinSet::new();
task_set.spawn(compile_program::compile_and_output_program(
out_dir.clone(),
"starkware/starknet/core/os/os.cairo",
"starknet_os",
));
task_set.spawn(compile_program::compile_and_output_program(
out_dir,
"starkware/starknet/core/aggregator/main.cairo",
"starknet_aggregator",
));
task_set.join_all().await;
}
Loading