Skip to content

Commit

Permalink
bootloader build on project build
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Apr 19, 2024
1 parent 97db7cb commit 46206b0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[env]
RUST_LOG = "info"
RUST_LOG = "info"
CAIRO_PATH = "cairo"
BOOTLOADER_PATH = "bootloader/recursive_with_poseidon/simple_bootloader.cairo"
BOOTLOADER_OUT_NAME = "bootloader.json"
24 changes: 10 additions & 14 deletions crates/prover/src/stone_prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,16 @@ impl ProverController for StoneProver {
let cpu_air_params = NamedTempFile::new()?; // TODO implement default config and getting info from integrity verifier

let task = Command::new("cpu_air_prover")
.args(["--out_file", out_file.path().to_string_lossy().as_ref()])
.args([
"--air_private_input",
job_trace.air_private_input.path().to_string_lossy().as_ref(),
])
.args([
"--air_public_input",
job_trace.air_public_input.path().to_string_lossy().as_ref(),
])
.args([
"--cpu_air_prover_config",
cpu_air_prover_config.path().to_string_lossy().as_ref(),
])
.args(["--cpu_air_params", cpu_air_params.path().to_string_lossy().as_ref()])
.arg("--out_file")
.arg(out_file.path())
.arg("--air_private_input")
.arg(job_trace.air_private_input.path())
.arg("--air_public_input")
.arg(job_trace.air_public_input.path())
.arg("--cpu_air_prover_config")
.arg(cpu_air_prover_config.path())
.arg("--cpu_air_params")
.arg(cpu_air_params.path())
.arg("--generate_annotations")
.spawn()?;

Expand Down
38 changes: 32 additions & 6 deletions crates/runner/build.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
use std::env;
use std::path::PathBuf;
use std::process::Command;

fn main() {
// Check if cairo-run command is present
Command::new("cairo-run")
.arg("--version")
.output()
.expect("Failed to execute cairo-run command");
check_command("cairo-run");

// Check if cairo-compile command is present
check_command("cairo-compile");

let workspace_root =
PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR env not present"))
.join("../../");
let out_dir =
PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR env not present")).join("../../../../");
let cairo_path = PathBuf::from(env::var("CAIRO_PATH").expect("CAIRO_PATH env not present"));
let bootloader_path =
PathBuf::from(env::var("BOOTLOADER_PATH").expect("BOOTLOADER_PATH env not present"));
let bootloader_out_name = PathBuf::from(
env::var("BOOTLOADER_OUT_NAME").expect("BOOTLOADER_OUT_NAME env not present"),
);

// Compile Bootloader
Command::new("cairo-compile")
.arg("--version")
.arg("--cairo_path")
.arg(&workspace_root.join(&cairo_path))
.arg(&workspace_root.join(&cairo_path).join(&bootloader_path))
.arg("--output")
.arg(&out_dir.join(&bootloader_out_name))
.arg("--proof_mode")
.output()
.expect("Failed to execute cairo-compile command");
.expect("bootloader compile failed");
}

fn check_command(cmd: &str) {
match Command::new(cmd).arg("--version").output() {
Ok(_) => println!("{} command found", cmd),
Err(e) => panic!("Failed to execute {} command: {}", cmd, e),
}
}
31 changes: 22 additions & 9 deletions crates/runner/src/cairo_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use crate::{
},
};
use sharp_p2p_common::{hash, job::Job, job_trace::JobTrace};
use std::io::Write;
use std::{
collections::HashMap,
hash::{DefaultHasher, Hash, Hasher},
};
use std::{env, io::Write, path::PathBuf};
use tempfile::NamedTempFile;
use tokio::process::{Child, Command};
use tracing::{debug, trace};
Expand All @@ -28,7 +28,13 @@ impl Runner for CairoRunner {

impl RunnerController for CairoRunner {
async fn run(&mut self, job: Job) -> Result<JobTrace, RunnerControllerError> {
let program = NamedTempFile::new()?;
let cargo_target_dir =
PathBuf::from(env::var("CARGO_TARGET_DIR").expect("CARGO_TARGET_DIR env not present"));
let bootloader_out_name = PathBuf::from(
env::var("BOOTLOADER_OUT_NAME").expect("BOOTLOADER_OUT_NAME env not present"),
);

let program = cargo_target_dir.join(&bootloader_out_name);
let layout: &str = Layout::RecursiveWithPoseidon.into();

let mut cairo_pie = NamedTempFile::new()?;
Expand All @@ -49,13 +55,20 @@ impl RunnerController for CairoRunner {
let memory = NamedTempFile::new()?;

let task = Command::new("cairo-run")
.args(["--program", program.path().to_string_lossy().as_ref()])
.args(["--layout", layout])
.args(["--program_input", program_input.path().to_string_lossy().as_ref()])
.args(["--air_public_input", air_public_input.path().to_string_lossy().as_ref()])
.args(["--air_private_input", air_private_input.path().to_string_lossy().as_ref()])
.args(["--trace_file", trace.path().to_string_lossy().as_ref()])
.args(["--memory_file", memory.path().to_string_lossy().as_ref()])
.arg("--program")
.arg(program.as_path())
.arg("--layout")
.arg(layout)
.arg("--program_input")
.arg(program_input.path())
.arg("--air_public_input")
.arg(air_public_input.path())
.arg("--air_private_input")
.arg(air_private_input.path())
.arg("--trace_file")
.arg(trace.path())
.arg("--memory_file")
.arg(memory.path())
.arg("--proof_mode")
.arg("--print_output")
.spawn()?;
Expand Down

0 comments on commit 46206b0

Please sign in to comment.