@@ -21,7 +21,13 @@ mod config;
21
21
22
22
/// The rustc compiler [target](https://doc.rust-lang.org/rustc/targets/index.html).
23
23
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
+ }
25
31
const BUILD_LOCKED_ENV : & str = "OPENVM_BUILD_LOCKED" ;
26
32
const SKIP_BUILD_ENV : & str = "OPENVM_SKIP_BUILD" ;
27
33
const GUEST_LOGFILE_ENV : & str = "OPENVM_GUEST_LOGFILE" ;
@@ -240,7 +246,7 @@ fn sanitized_cmd(tool: &str) -> Command {
240
246
/// Creates a std::process::Command to execute the given cargo
241
247
/// command in an environment suitable for targeting the zkvm guest.
242
248
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 ( ) ) ;
244
250
245
251
let rustc = sanitized_cmd ( "rustup" )
246
252
. args ( [ & toolchain, "which" , "rustc" ] )
@@ -382,7 +388,7 @@ pub fn build_generic(guest_opts: &GuestOptions) -> Result<PathBuf, Option<i32>>
382
388
383
389
// Check if the required toolchain and rust-src component are installed, and if not, install
384
390
// 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" ] ) {
386
392
eprintln ! ( "rustup toolchain commands failed. Please ensure rustup is installed (https://www.rust-lang.org/tools/install)" ) ;
387
393
return Err ( Some ( code) ) ;
388
394
}
0 commit comments