Skip to content

Commit

Permalink
Check SKIP_GUEST_BUILD value (#997)
Browse files Browse the repository at this point in the history
* Don't skip if SKIP_GUEST_BUILD=false

* Exhaustive check
  • Loading branch information
jfldde authored Aug 16, 2024
1 parent fe4cadd commit e2d7e4a
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions bin/citrea/provers/risc0/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,39 @@ fn main() {
println!("cargo:rerun-if-env-changed=REPR_GUEST_BUILD");
println!("cargo:rerun-if-env-changed=OUT_DIR");

if std::env::var("SKIP_GUEST_BUILD").is_ok() {
println!("cargo:warning=Skipping guest build");
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let out_dir = std::path::Path::new(&out_dir);
let methods_path = out_dir.join("methods.rs");

let elf = r#"
pub const BITCOIN_DA_ELF: &[u8] = &[];
pub const MOCK_DA_ELF: &[u8] = &[];
pub const BITCOIN_DA_ID: [u32; 8] = [0u32; 8];
pub const MOCK_DA_ID: [u32; 8] = [0u32; 8];
"#;

std::fs::write(methods_path, elf).expect("Failed to write mock rollup elf");
} else {
let guest_pkg_to_options = get_guest_options();
embed_methods_with_options(guest_pkg_to_options);
match std::env::var("SKIP_GUEST_BUILD") {
Ok(value) => match value.as_str() {
"1" | "true" => {
println!("cargo:warning=Skipping guest build");
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let out_dir = std::path::Path::new(&out_dir);
let methods_path = out_dir.join("methods.rs");

let elf = r#"
pub const BITCOIN_DA_ELF: &[u8] = &[];
pub const MOCK_DA_ELF: &[u8] = &[];
pub const BITCOIN_DA_ID: [u32; 8] = [0u32; 8];
pub const MOCK_DA_ID: [u32; 8] = [0u32; 8];
"#;

return std::fs::write(methods_path, elf).expect("Failed to write mock rollup elf");
}
"0" | "false" => {
println!("cargo:warning=Performing guest build");
}
_ => {
println!("cargo:warning=Invalid value for SKIP_GUEST_BUILD: '{}'. Expected '0', '1', 'true', or 'false'. Defaulting to performing guest build.", value);
}
},
Err(std::env::VarError::NotPresent) => {
println!("cargo:warning=SKIP_GUEST_BUILD not set. Performing guest build.");
}
Err(std::env::VarError::NotUnicode(_)) => {
println!("cargo:warning=SKIP_GUEST_BUILD contains invalid Unicode. Defaulting to performing guest build.");
}
}
let guest_pkg_to_options = get_guest_options();
embed_methods_with_options(guest_pkg_to_options);
}

fn get_guest_options() -> HashMap<&'static str, risc0_build::GuestOptions> {
Expand Down

0 comments on commit e2d7e4a

Please sign in to comment.