33use pico_sdk:: client:: DefaultProverClient ;
44use pico_vm:: emulator:: stdin:: EmulatorStdinBuilder ;
55use serde:: de:: DeserializeOwned ;
6- use std:: { io:: Read , path:: Path , process:: Command , time:: Instant } ;
6+ use std:: { env , io:: Read , path:: Path , process:: Command , time:: Instant } ;
77use zkvm_interface:: {
88 Compiler , Input , InputItem , ProgramExecutionReport , ProgramProvingReport , Proof ,
99 ProverResourceType , PublicValues , zkVM, zkVMError,
1010} ;
11+ use compile_stock_rust:: compile_pico_program_stock_rust;
12+
13+ mod compile_stock_rust;
1114
1215include ! ( concat!( env!( "OUT_DIR" ) , "/name_and_sdk_version.rs" ) ) ;
1316mod error;
@@ -21,38 +24,48 @@ impl Compiler for PICO_TARGET {
2124
2225 type Program = Vec < u8 > ;
2326
24- fn compile ( & self , guest_path : & Path ) -> Result < Self :: Program , Self :: Error > {
25- // 1. Check guest path
26- if !guest_path. exists ( ) {
27- return Err ( PicoError :: PathNotFound ( guest_path. to_path_buf ( ) ) ) ;
27+ fn compile ( & self , guest_directory : & Path ) -> Result < Self :: Program , Self :: Error > {
28+ let toolchain =
29+ env:: var ( "ERE_GUEST_TOOLCHAIN" ) . unwrap_or_else ( |_error| "risc0" . into ( ) ) ;
30+ match toolchain. as_str ( ) {
31+ "risc0" => Ok ( compile_pico_program ( guest_directory) ?) ,
32+ _ => Ok ( compile_pico_program_stock_rust ( guest_directory, & toolchain) ?) ,
2833 }
34+ }
35+ }
2936
30- // 2. Run `cargo pico build`
31- let status = Command :: new ( "cargo" )
32- . current_dir ( guest_path)
33- . env ( "RUST_LOG" , "info" )
34- . args ( [ "pico" , "build" ] )
35- . status ( ) ?; // From<io::Error> → Spawn
36-
37- if !status. success ( ) {
38- return Err ( PicoError :: CargoFailed { status } ) ;
39- }
37+ fn compile_pico_program ( guest_directory : & Path ) -> Result < Vec < u8 > , PicoError >
38+ {
39+ // 1. Check guest path
40+ if !guest_directory. exists ( ) {
41+ return Err ( PicoError :: PathNotFound ( guest_directory. to_path_buf ( ) ) ) ;
42+ }
4043
41- // 3. Locate the ELF file
42- let elf_path = guest_path. join ( "elf/riscv32im-pico-zkvm-elf" ) ;
44+ // 2. Run `cargo pico build`
45+ let status = Command :: new ( "cargo" )
46+ . current_dir ( guest_directory)
47+ . env ( "RUST_LOG" , "info" )
48+ . args ( [ "pico" , "build" ] )
49+ . status ( ) ?; // From<io::Error> → Spawn
4350
44- if !elf_path . exists ( ) {
45- return Err ( PicoError :: ElfNotFound ( elf_path ) ) ;
46- }
51+ if !status . success ( ) {
52+ return Err ( PicoError :: CargoFailed { status } ) ;
53+ }
4754
48- // 4. Read the ELF file
49- let elf_bytes = std:: fs:: read ( & elf_path) . map_err ( |e| PicoError :: ReadElf {
50- path : elf_path,
51- source : e,
52- } ) ?;
55+ // 3. Locate the ELF file
56+ let elf_path = guest_directory. join ( "elf/riscv32im-pico-zkvm-elf" ) ;
5357
54- Ok ( elf_bytes)
58+ if !elf_path. exists ( ) {
59+ return Err ( PicoError :: ElfNotFound ( elf_path) ) ;
5560 }
61+
62+ // 4. Read the ELF file
63+ let elf_bytes = std:: fs:: read ( & elf_path) . map_err ( |e| PicoError :: ReadElf {
64+ path : elf_path,
65+ source : e,
66+ } ) ?;
67+
68+ Ok ( elf_bytes)
5669}
5770
5871pub struct ErePico {
@@ -194,6 +207,14 @@ mod tests {
194207 assert_eq ! ( io. deserialize_outputs( & zkvm, & public_values) , io. outputs( ) ) ;
195208 }
196209
210+ #[ test]
211+ fn test_execute_nightly ( ) {
212+ let guest_directory = testing_guest_directory ( "pico" , "stock_nightly_no_std" ) ;
213+ let program = compile_pico_program_stock_rust ( & guest_directory, & "nightly" . to_string ( ) ) . unwrap ( ) ;
214+ let zkvm = ErePico :: new ( program, ProverResourceType :: Cpu ) ;
215+ run_zkvm_execute ( & zkvm, & Input :: new ( ) ) ;
216+ }
217+
197218 #[ test]
198219 fn test_execute_invalid_inputs ( ) {
199220 let program = basic_program ( ) ;
0 commit comments