@@ -60,7 +60,9 @@ struct libwasmtime_vm
6060 wasm_engine_t * engine ;
6161 wasmtime_store_t * store ;
6262 wasmtime_context_t * context ;
63+ # if WASMTIME_VERSION_MAJOR < 39
6364 wasi_config_t * config ;
65+ # endif
6466};
6567
6668static struct libwasmtime_vm *
@@ -119,36 +121,39 @@ libwasmtime_setup_vm (void *cookie, char *const argv[], struct libwasmtime_vm *v
119121 vm -> context = wasmtime_store_context (vm -> store );
120122
121123 // Init WASI program
122- vm -> config = wasi_config_new ("crun_wasi_program" );
123- if (vm -> config == NULL )
124+ wasi_config_t * config = wasi_config_new ("crun_wasi_program" );
125+ if (config == NULL )
124126 error (EXIT_FAILURE , 0 , "could not create WASI configuration" );
125127
126128 // Calculate argc for `wasi_config_set_argv`
127129 for (arg = argv ; * arg != NULL ; ++ arg )
128130 args_size ++ ;
129131
130- wasi_config_set_argv (vm -> config , args_size , (const char * * ) argv );
131- wasi_config_inherit_env (vm -> config );
132- wasi_config_inherit_stdin (vm -> config );
133- wasi_config_inherit_stdout (vm -> config );
134- wasi_config_inherit_stderr (vm -> config );
132+ wasi_config_set_argv (config , args_size , (const char * * ) argv );
133+ wasi_config_inherit_env (config );
134+ wasi_config_inherit_stdin (config );
135+ wasi_config_inherit_stdout (config );
136+ wasi_config_inherit_stderr (config );
135137 wasi_config_preopen_dir (
136- vm -> config ,
138+ config ,
137139 "." ,
138140 "." ,
139141 WASMTIME_WASI_DIR_PERMS_READ | WASMTIME_WASI_DIR_PERMS_WRITE ,
140142 WASMTIME_WASI_FILE_PERMS_READ | WASMTIME_WASI_FILE_PERMS_WRITE );
141143
144+ # if WASMTIME_VERSION_MAJOR >= 39
142145 // If we are compiling wasmtime against 39 or higher
143146 // we can make use of the unified wasi API.
144- # if WASMTIME_VERSION_MAJOR >= 39
145147 wasmtime_error_t * err = wasmtime_context_set_wasi (vm -> context , vm -> config );
146148 if (err != NULL )
147149 {
148150 wasmtime_error_message (err , & error_message );
149151 wasmtime_error_delete (err );
150152 error (EXIT_FAILURE , 0 , "failed to instantiate WASI: %.*s" , (int ) error_message .size , error_message .data );
151153 }
154+ # else
155+ // Otherwise let each branching path apply the config.
156+ vm -> config = config ;
152157# endif
153158
154159 return vm ;
0 commit comments