@@ -141,9 +141,10 @@ use clap::Parser;
141141use std:: os:: raw:: { c_int, c_void} ;
142142use std:: slice;
143143use std:: { env, path:: PathBuf } ;
144- use wasi_common:: { I32Exit , WasiCtx , sync:: WasiCtxBuilder } ;
145144use wasmtime:: { Engine , Instance , Linker , Module , Store } ;
146145use wasmtime_cli_flags:: CommonOptions ;
146+ use wasmtime_wasi:: cli:: { InputFile , OutputFile } ;
147+ use wasmtime_wasi:: { DirPerms , FilePerms , I32Exit , WasiCtx , preview1:: WasiP1Ctx } ;
147148
148149pub type ExitCode = c_int ;
149150pub const OK : ExitCode = 0 ;
@@ -272,15 +273,6 @@ pub extern "C" fn wasm_bench_create(
272273) -> ExitCode {
273274 let result = ( || -> Result < _ > {
274275 let working_dir = config. working_dir ( ) ?;
275- let working_dir =
276- cap_std:: fs:: Dir :: open_ambient_dir ( & working_dir, cap_std:: ambient_authority ( ) )
277- . with_context ( || {
278- format ! (
279- "failed to preopen the working directory: {}" ,
280- working_dir. display( ) ,
281- )
282- } ) ?;
283-
284276 let stdout_path = config. stdout_path ( ) ?;
285277 let stderr_path = config. stderr_path ( ) ?;
286278 let stdin_path = config. stdin_path ( ) ?;
@@ -298,39 +290,33 @@ pub extern "C" fn wasm_bench_create(
298290 config. execution_start ,
299291 config. execution_end ,
300292 move || {
301- let mut cx = WasiCtxBuilder :: new ( ) ;
293+ let mut cx = WasiCtx :: builder ( ) ;
302294
303295 let stdout = std:: fs:: File :: create ( & stdout_path)
304296 . with_context ( || format ! ( "failed to create {}" , stdout_path. display( ) ) ) ?;
305- let stdout = cap_std:: fs:: File :: from_std ( stdout) ;
306- let stdout = wasi_common:: sync:: file:: File :: from_cap_std ( stdout) ;
307- cx. stdout ( Box :: new ( stdout) ) ;
297+ cx. stdout ( OutputFile :: new ( stdout) ) ;
308298
309299 let stderr = std:: fs:: File :: create ( & stderr_path)
310300 . with_context ( || format ! ( "failed to create {}" , stderr_path. display( ) ) ) ?;
311- let stderr = cap_std:: fs:: File :: from_std ( stderr) ;
312- let stderr = wasi_common:: sync:: file:: File :: from_cap_std ( stderr) ;
313- cx. stderr ( Box :: new ( stderr) ) ;
301+ cx. stderr ( OutputFile :: new ( stderr) ) ;
314302
315303 if let Some ( stdin_path) = & stdin_path {
316304 let stdin = std:: fs:: File :: open ( stdin_path)
317305 . with_context ( || format ! ( "failed to open {}" , stdin_path. display( ) ) ) ?;
318- let stdin = cap_std:: fs:: File :: from_std ( stdin) ;
319- let stdin = wasi_common:: sync:: file:: File :: from_cap_std ( stdin) ;
320- cx. stdin ( Box :: new ( stdin) ) ;
306+ cx. stdin ( InputFile :: new ( stdin) ) ;
321307 }
322308
323309 // Allow access to the working directory so that the benchmark can read
324310 // its input workload(s).
325- cx. preopened_dir ( working_dir. try_clone ( ) ? , "." ) ?;
311+ cx. preopened_dir ( working_dir. clone ( ) , "." , DirPerms :: READ , FilePerms :: READ ) ?;
326312
327313 // Pass this env var along so that the benchmark program can use smaller
328314 // input workload(s) if it has them and that has been requested.
329315 if let Ok ( val) = env:: var ( "WASM_BENCH_USE_SMALL_WORKLOAD" ) {
330- cx. env ( "WASM_BENCH_USE_SMALL_WORKLOAD" , & val) ? ;
316+ cx. env ( "WASM_BENCH_USE_SMALL_WORKLOAD" , & val) ;
331317 }
332318
333- Ok ( cx. build ( ) )
319+ Ok ( cx. build_p1 ( ) )
334320 } ,
335321 ) ?) ;
336322 Ok ( Box :: into_raw ( state) as _ )
@@ -407,15 +393,15 @@ struct BenchState {
407393 instantiation_timer : * mut u8 ,
408394 instantiation_start : extern "C" fn ( * mut u8 ) ,
409395 instantiation_end : extern "C" fn ( * mut u8 ) ,
410- make_wasi_cx : Box < dyn FnMut ( ) -> Result < WasiCtx > > ,
396+ make_wasi_cx : Box < dyn FnMut ( ) -> Result < WasiP1Ctx > > ,
411397 module : Option < Module > ,
412398 store_and_instance : Option < ( Store < HostState > , Instance ) > ,
413399 epoch_interruption : bool ,
414400 fuel : Option < u64 > ,
415401}
416402
417403struct HostState {
418- wasi : WasiCtx ,
404+ wasi : WasiP1Ctx ,
419405 #[ cfg( feature = "wasi-nn" ) ]
420406 wasi_nn : wasmtime_wasi_nn:: witx:: WasiNnCtx ,
421407}
@@ -432,7 +418,7 @@ impl BenchState {
432418 execution_timer : * mut u8 ,
433419 execution_start : extern "C" fn ( * mut u8 ) ,
434420 execution_end : extern "C" fn ( * mut u8 ) ,
435- make_wasi_cx : impl FnMut ( ) -> Result < WasiCtx > + ' static ,
421+ make_wasi_cx : impl FnMut ( ) -> Result < WasiP1Ctx > + ' static ,
436422 ) -> Result < Self > {
437423 let mut config = options. config ( None ) ?;
438424 // NB: always disable the compilation cache.
@@ -459,7 +445,7 @@ impl BenchState {
459445 let fuel = options. wasm . fuel ;
460446
461447 if options. wasi . common != Some ( false ) {
462- wasi_common :: sync :: add_to_linker ( & mut linker, |cx| & mut cx. wasi ) ?;
448+ wasmtime_wasi :: preview1 :: add_to_linker_sync ( & mut linker, |cx| & mut cx. wasi ) ?;
463449 }
464450
465451 #[ cfg( feature = "wasi-nn" ) ]
0 commit comments