Skip to content
Draft
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
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion benchmarks/guest/base64_json/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/bincode/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/bubblesort/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/ecrecover/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/fibonacci/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm::io::{read, reveal_u64};
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/fibonacci_iterative/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/fibonacci_recursive/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/keccak256/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/keccak256_iter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/kitchen-sink/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/pairing/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/quicksort/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/regex/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/revm_snailtracer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/revm_transfer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

//! Program to match the workload of <https://github.com/bluealloy/revm/blob/900409f134c1cbd4489d370a6b037f354afa4a5c/crates/revm/benches/bench.rs#L68>
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/rkyv/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/sha256/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/sha256_iter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/guest/sha2_bench/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/templates/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// src/main.rs
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm::io::{read, reveal_u64};
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/programs/fibonacci/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/programs/multi/calculator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use calculator::count_primes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/tests/programs/multi/string-utils/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion crates/continuations/programs/examples/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm::io::{read, reveal_u64};
Expand Down
2 changes: 1 addition & 1 deletion crates/continuations/programs/examples/multiple.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm::io::read;
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/guest/fib/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

openvm::entry!(main);
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/guest/little/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/guest/p256/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/programs/examples/fibonacci.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

use openvm::io::{read, reveal_u64};
Expand Down
2 changes: 1 addition & 1 deletion crates/sdk/programs/examples/verify-stark.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(target_os = "none", no_main)]
#![cfg_attr(any(target_os = "none", target_os = "openvm"), no_main)]
#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
Expand Down
37 changes: 22 additions & 15 deletions crates/toolchain/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ pub use self::config::GuestOptions;

mod config;

/// Custom rustc target for the openvm guest. The JSON spec lives at
/// `<RUSTC_TARGET>.json` next to this crate.
pub const RUSTC_TARGET: &str = "riscv64im-openvm-none-elf";
/// Custom rustc target for the openvm guest.
pub const RUSTC_TARGET: &str = "riscv64im-unknown-openvm-elf";

/// Directory containing the target JSON; passed to cargo as `RUST_TARGET_PATH`.
pub fn rustc_target_spec_dir() -> &'static Path {
Path::new(env!("CARGO_MANIFEST_DIR"))
}
/// The default Rust toolchain name to use if OPENVM_RUST_TOOLCHAIN is not set
pub const DEFAULT_RUSTUP_TOOLCHAIN_NAME: &str = "nightly-2026-01-18";
pub const DEFAULT_RUSTUP_TOOLCHAIN_NAME: &str = "openvm-rv64";

/// Get the Rust toolchain name from environment variable or default
pub fn get_rustup_toolchain_name() -> String {
Expand Down Expand Up @@ -251,7 +250,8 @@ fn sanitized_cmd(tool: &str) -> Command {

/// Creates a std::process::Command to execute the given cargo
/// command in an environment suitable for targeting the zkvm guest.
pub fn cargo_command(subcmd: &str, rust_flags: &[&str]) -> Command {
/// If `with_std` is true, `std` is added to the `-Zbuild-std` crate list.
pub fn cargo_command(subcmd: &str, rust_flags: &[&str], with_std: bool) -> Command {
let toolchain = format!("+{}", get_rustup_toolchain_name());

let rustc = sanitized_cmd("rustup")
Expand All @@ -271,12 +271,12 @@ pub fn cargo_command(subcmd: &str, rust_flags: &[&str]) -> Command {
args.push("--locked");
}

args.extend_from_slice(&[
"-Z",
"build-std=alloc,core,panic_abort",
"-Z",
"build-std-features=compiler-builtins-mem",
]);
let build_std = if with_std {
"build-std=alloc,core,panic_abort,std"
} else {
"build-std=alloc,core,panic_abort"
};
args.extend_from_slice(&["-Z", build_std, "-Z", "build-std-features=compiler-builtins-mem"]);

println!("Building guest package: cargo {}", args.join(" "));

Expand Down Expand Up @@ -398,16 +398,23 @@ pub fn build_generic(guest_opts: &GuestOptions) -> Result<PathBuf, Option<i32>>

// Check if the required toolchain and rust-src component are installed, and if not, install
// them. This requires that `rustup` is installed.
if let Err(code) = ensure_toolchain_installed(&get_rustup_toolchain_name(), &["rust-src"]) {
eprintln!("rustup toolchain commands failed. Please ensure rustup is installed (https://www.rust-lang.org/tools/install)");
return Err(Some(code));
// Skip for linked toolchains (e.g. custom-built rustc) where rustup component commands
// don't apply — the toolchain is expected to already include rust-src.
let toolchain_name = get_rustup_toolchain_name();
let is_linked_toolchain = !toolchain_name.contains("nightly") && !toolchain_name.contains("stable") && !toolchain_name.contains("beta");
if !is_linked_toolchain {
if let Err(code) = ensure_toolchain_installed(&toolchain_name, &["rust-src"]) {
eprintln!("rustup toolchain commands failed. Please ensure rustup is installed (https://www.rust-lang.org/tools/install)");
return Err(Some(code));
}
}

let target_dir = guest_opts.target_dir.as_ref().unwrap();
fs::create_dir_all(target_dir).unwrap();
let rust_flags: Vec<_> = guest_opts.rustc_flags.iter().map(|s| s.as_str()).collect();

let mut cmd = cargo_command("build", &rust_flags);
let with_std = guest_opts.features.iter().any(|f| f == "std");
let mut cmd = cargo_command("build", &rust_flags, with_std);

if !guest_opts.features.is_empty() {
cmd.args(["--features", guest_opts.features.join(",").as_str()]);
Expand Down
9 changes: 5 additions & 4 deletions crates/toolchain/openvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub use openvm_riscv_guest::*;

#[cfg(openvm_intrinsics)]
mod getrandom;
#[cfg(openvm_intrinsics)]
mod pal_abi;
pub mod io;
pub mod process;
pub mod serde;
Expand Down Expand Up @@ -71,7 +73,7 @@ fn _fault() -> ! {
///
/// fn main() { }
/// ```
#[cfg(all(not(feature = "std"), openvm_intrinsics))]
#[cfg(openvm_intrinsics)]
#[macro_export]
macro_rules! entry {
($path:path) => {
Expand All @@ -88,9 +90,8 @@ macro_rules! entry {
}
};
}
/// This macro does nothing. You should name the function `main` so that the normal rust main
/// function setup is used.
#[cfg(any(feature = "std", not(openvm_intrinsics)))]
/// This macro does nothing when not compiling for the guest target.
#[cfg(not(openvm_intrinsics))]
#[macro_export]
macro_rules! entry {
($path:path) => {};
Expand Down
Loading
Loading