Skip to content

Commit 160de07

Browse files
Qumericjonathanpwang
authored andcommitted
feat: allow to override compiler's Rust toolchain (#1940)
Previously toolchain version was hardcoded to some version of rust 1.86 nightly. Sometimes users may want to use custom version, e.g. for some newest nightly Rust feature.
1 parent 20c494e commit 160de07

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

crates/cli/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ pub mod util;
66
use std::process::{Command, Stdio};
77

88
use eyre::{Context, Result};
9-
10-
pub const RUSTUP_TOOLCHAIN_NAME: &str = "nightly-2025-02-14";
9+
pub use openvm_build::{get_rustup_toolchain_name, DEFAULT_RUSTUP_TOOLCHAIN_NAME};
1110

1211
pub const OPENVM_VERSION_MESSAGE: &str = concat!(
1312
"v",

crates/toolchain/build/src/lib.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ mod config;
2121

2222
/// The rustc compiler [target](https://doc.rust-lang.org/rustc/targets/index.html).
2323
pub const RUSTC_TARGET: &str = "riscv32im-risc0-zkvm-elf";
24-
const RUSTUP_TOOLCHAIN_NAME: &str = "nightly-2025-02-14";
24+
/// The default Rust toolchain name to use if OPENVM_RUST_TOOLCHAIN is not set
25+
pub const DEFAULT_RUSTUP_TOOLCHAIN_NAME: &str = "nightly-2025-02-14";
26+
27+
/// Get the Rust toolchain name from environment variable or default
28+
pub fn get_rustup_toolchain_name() -> String {
29+
env::var("OPENVM_RUST_TOOLCHAIN").unwrap_or_else(|_| DEFAULT_RUSTUP_TOOLCHAIN_NAME.to_string())
30+
}
2531
const BUILD_LOCKED_ENV: &str = "OPENVM_BUILD_LOCKED";
2632
const SKIP_BUILD_ENV: &str = "OPENVM_SKIP_BUILD";
2733
const GUEST_LOGFILE_ENV: &str = "OPENVM_GUEST_LOGFILE";
@@ -240,7 +246,7 @@ fn sanitized_cmd(tool: &str) -> Command {
240246
/// Creates a std::process::Command to execute the given cargo
241247
/// command in an environment suitable for targeting the zkvm guest.
242248
pub fn cargo_command(subcmd: &str, rust_flags: &[&str]) -> Command {
243-
let toolchain = format!("+{RUSTUP_TOOLCHAIN_NAME}");
249+
let toolchain = format!("+{}", get_rustup_toolchain_name());
244250

245251
let rustc = sanitized_cmd("rustup")
246252
.args([&toolchain, "which", "rustc"])
@@ -382,7 +388,7 @@ pub fn build_generic(guest_opts: &GuestOptions) -> Result<PathBuf, Option<i32>>
382388

383389
// Check if the required toolchain and rust-src component are installed, and if not, install
384390
// them. This requires that `rustup` is installed.
385-
if let Err(code) = ensure_toolchain_installed(RUSTUP_TOOLCHAIN_NAME, &["rust-src"]) {
391+
if let Err(code) = ensure_toolchain_installed(&get_rustup_toolchain_name(), &["rust-src"]) {
386392
eprintln!("rustup toolchain commands failed. Please ensure rustup is installed (https://www.rust-lang.org/tools/install)");
387393
return Err(Some(code));
388394
}

0 commit comments

Comments
 (0)