@@ -359,25 +359,30 @@ where
359359 Ok ( ( pre, engine, guest_resources, host_resources) )
360360}
361361
362- fn new_store < C : Invoke > (
362+ fn new_store < ' a , C : Invoke > (
363363 engine : & Engine ,
364364 wrpc : C ,
365365 cx : C :: Context ,
366366 arg0 : & str ,
367367 timeout : Duration ,
368+ vars : impl IntoIterator < Item = ( & ' a str , & ' a str ) > ,
368369) -> wasmtime:: Store < Ctx < C > > {
370+ let mut builder = WasiCtxBuilder :: new ( ) ;
371+ builder
372+ . inherit_env ( )
373+ . inherit_stdio ( )
374+ . inherit_network ( )
375+ . allow_ip_name_lookup ( true )
376+ . allow_tcp ( true )
377+ . allow_udp ( true )
378+ . args ( & [ arg0] ) ;
379+ for ( k, v) in vars {
380+ builder. env ( k, v) ;
381+ }
369382 Store :: new (
370383 engine,
371384 Ctx {
372- wasi : WasiCtxBuilder :: new ( )
373- . inherit_env ( )
374- . inherit_stdio ( )
375- . inherit_network ( )
376- . allow_ip_name_lookup ( true )
377- . allow_tcp ( true )
378- . allow_udp ( true )
379- . args ( & [ arg0] )
380- . build ( ) ,
385+ wasi : builder. build ( ) ,
381386 http : WasiHttpCtx :: new ( ) ,
382387 table : ResourceTable :: new ( ) ,
383388 wrpc : WrpcCtx {
@@ -395,6 +400,7 @@ pub async fn handle_run<C>(
395400 clt : C ,
396401 cx : C :: Context ,
397402 timeout : Duration ,
403+ vars : Vec < ( String , String ) > ,
398404 workload : & str ,
399405) -> anyhow:: Result < ( ) >
400406where
@@ -403,7 +409,14 @@ where
403409{
404410 let ( pre, engine, _, _) =
405411 instantiate_pre ( WASI_SNAPSHOT_PREVIEW1_COMMAND_ADAPTER , workload) . await ?;
406- let mut store = new_store ( & engine, clt, cx, "command.wasm" , timeout) ;
412+ let mut store = new_store (
413+ & engine,
414+ clt,
415+ cx,
416+ "command.wasm" ,
417+ timeout,
418+ vars. iter ( ) . map ( |( k, v) | ( k. as_str ( ) , v. as_str ( ) ) ) ,
419+ ) ;
407420 let cmd = wasmtime_wasi:: p2:: bindings:: CommandPre :: new ( pre)
408421 . map_err ( anyhow:: Error :: from)
409422 . context ( "failed to construct `command` instance" ) ?
@@ -605,7 +618,14 @@ where
605618 let invocations = srv
606619 . serve_function (
607620 move || {
608- new_store ( & engine, clt. clone ( ) , cx. clone ( ) , "reactor.wasm" , timeout)
621+ new_store (
622+ & engine,
623+ clt. clone ( ) ,
624+ cx. clone ( ) ,
625+ "reactor.wasm" ,
626+ timeout,
627+ std:: iter:: empty ( ) ,
628+ )
609629 } ,
610630 pre. clone ( ) ,
611631 Arc :: clone ( & host_resources) ,
@@ -665,6 +685,7 @@ where
665685 cx. clone ( ) ,
666686 "reactor.wasm" ,
667687 timeout,
688+ std:: iter:: empty ( ) ,
668689 )
669690 } ,
670691 pre. clone ( ) ,
@@ -768,7 +789,14 @@ where
768789 serve_shared (
769790 & mut handlers,
770791 srv,
771- new_store ( & engine, clt, cx, "reactor.wasm" , timeout) ,
792+ new_store (
793+ & engine,
794+ clt,
795+ cx,
796+ "reactor.wasm" ,
797+ timeout,
798+ std:: iter:: empty ( ) ,
799+ ) ,
772800 pre,
773801 guest_resources,
774802 host_resources,
0 commit comments