Skip to content

Commit

Permalink
fix: additional guards on entrypoint macro
Browse files Browse the repository at this point in the history
These additional checks ensure attempting to run an sp1 program on a non-zkvm host will silently noop instead of error.
  • Loading branch information
sinasab committed Oct 22, 2024
1 parent 9121fe4 commit 9da7a8f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions crates/zkvm/entrypoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,27 @@ macro_rules! entrypoint {

use $crate::heap::SimpleAlloc;

#[cfg(target_os = "zkvm")]
#[global_allocator]
static HEAP: SimpleAlloc = SimpleAlloc;

mod zkvm_generated_main {

#[no_mangle]
fn main() {
// Link to the actual entrypoint only when compiling for zkVM. Doing this avoids
// compilation errors when building for the host target.
// Link to the actual entrypoint only when compiling for zkVM, otherwise run a
// simple noop. Doing this avoids compilation errors when building for the host
// target.
//
// Note that, however, it's generally considered wasted effort compiling zkVM
// programs against the host target. This just makes it such that doing so wouldn't
// result in an error, which can happen when building a Cargo workspace containing
// zkVM program crates.
#[cfg(target_os = "zkvm")]
super::ZKVM_ENTRY()
if cfg!(target_os = "zkvm") {
super::ZKVM_ENTRY()
} else {
println!("Not running in zkVM, skipping entrypoint");
}
}
}
};
Expand Down

0 comments on commit 9da7a8f

Please sign in to comment.