MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / configure_wasip2

Method configure_wasip2

src/common.rs:314–382  ·  view source on GitHub ↗
(&self, builder: &mut WasiCtxBuilder)

Source from the content-addressed store, hash-verified

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 {

Callers 2

new_storeMethod · 0.80
set_wasi_ctxMethod · 0.80

Calls 14

OkFunction · 0.85
allow_tcpMethod · 0.80
allow_udpMethod · 0.80
max_random_sizeMethod · 0.80
is_noneMethod · 0.45
envMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
preopened_dirMethod · 0.45
initial_cwdMethod · 0.45

Tested by

no test coverage detected