(&self, builder: &mut WasiCtxBuilder)
| 312 | } |
| 313 | |
| 314 | pub fn configure_wasip2(&self, builder: &mut WasiCtxBuilder) -> Result<()> { |
| 315 | // It's ok to block the current thread since we're the only thread in |
| 316 | // the program as the CLI. This helps improve the performance of some |
| 317 | // blocking operations in WASI, for example, by skipping the |
| 318 | // back-and-forth between sync and async. |
| 319 | // |
| 320 | // However, do not set this if a timeout is configured, as that would |
| 321 | // cause the timeout to be ignored if the guest does, for example, |
| 322 | // something like `sleep(FOREVER)`. |
| 323 | builder.allow_blocking_current_thread(self.common.wasm.timeout.is_none()); |
| 324 | |
| 325 | if self.common.wasi.inherit_env == Some(true) { |
| 326 | for (k, v) in std::env::vars() { |
| 327 | builder.env(&k, &v); |
| 328 | } |
| 329 | } |
| 330 | for (key, value) in self.vars.iter() { |
| 331 | let value = match value { |
| 332 | Some(value) => value.clone(), |
| 333 | None => match std::env::var_os(key) { |
| 334 | Some(val) => val |
| 335 | .into_string() |
| 336 | .map_err(|_| format_err!("environment variable `{key}` not valid utf-8"))?, |
| 337 | None => { |
| 338 | // leave the env var un-set in the guest |
| 339 | continue; |
| 340 | } |
| 341 | }, |
| 342 | }; |
| 343 | builder.env(key, &value); |
| 344 | } |
| 345 | |
| 346 | for (host, guest) in self.dirs.iter() { |
| 347 | builder.preopened_dir( |
| 348 | host, |
| 349 | guest, |
| 350 | wasmtime_wasi::DirPerms::all(), |
| 351 | wasmtime_wasi::FilePerms::all(), |
| 352 | )?; |
| 353 | } |
| 354 | if let Some(cwd) = &self.common.wasi.cwd { |
| 355 | builder.initial_cwd(cwd); |
| 356 | } |
| 357 | |
| 358 | if self.common.wasi.listenfd == Some(true) { |
| 359 | bail!("components do not support --listenfd"); |
| 360 | } |
| 361 | for _ in self.compute_preopen_sockets()? { |
| 362 | bail!("components do not support --tcplisten"); |
| 363 | } |
| 364 | |
| 365 | if self.common.wasi.inherit_network == Some(true) { |
| 366 | builder.inherit_network(); |
| 367 | } |
| 368 | if let Some(enable) = self.common.wasi.allow_ip_name_lookup { |
| 369 | builder.allow_ip_name_lookup(enable); |
| 370 | } |
| 371 | if let Some(enable) = self.common.wasi.tcp { |
no test coverage detected