Struct wasmer_wasix::WasiEnvBuilder

source ·
pub struct WasiEnvBuilder {
Show 22 fields pub(super) entry_function: Option<String>, pub(super) args: Vec<String>, pub(super) envs: Vec<(String, Vec<u8>)>, pub(super) preopens: Vec<PreopenedDir>, vfs_preopens: Vec<String>, pub(super) setup_fs_fn: Option<Box<dyn Fn(&WasiInodes, &mut WasiFs) -> Result<(), String> + Send>>, pub(super) stdout: Option<Box<dyn VirtualFile + Send + Sync + 'static>>, pub(super) stderr: Option<Box<dyn VirtualFile + Send + Sync + 'static>>, pub(super) stdin: Option<Box<dyn VirtualFile + Send + Sync + 'static>>, pub(super) fs: Option<WasiFsRoot>, pub(super) runtime: Option<Arc<dyn Runtime + Send + Sync + 'static>>, pub(super) current_dir: Option<PathBuf>, pub(super) uses: Vec<BinaryPackage>, pub(super) included_packages: HashSet<PackageId>, pub(super) module_hash: Option<ModuleHash>, pub(super) map_commands: HashMap<String, PathBuf>, pub(super) capabilites: Capabilities, pub(super) additional_imports: Imports, pub(super) snapshot_on: Vec<SnapshotTrigger>, pub(super) snapshot_interval: Option<Duration>, pub(super) journals: Vec<Arc<DynJournal>>, pub(super) attach_ctrl_c: bool,
}
Expand description

Builder API for configuring a WasiEnv environment needed to run WASI modules.

Usage:

let mut state_builder = WasiEnv::builder("wasi-prog-name");
state_builder
   .env("ENV_VAR", "ENV_VAL")
   .arg("--verbose")
   .preopen_dir("src")?
   .map_dir("name_wasi_sees", "path/on/host/fs")?
   .build_init()?;

Fields§

§entry_function: Option<String>

Name of entry function. Defaults to running _start if not specified.

§args: Vec<String>

Command line arguments.

§envs: Vec<(String, Vec<u8>)>

Environment variables.

§preopens: Vec<PreopenedDir>

Pre-opened directories that will be accessible from WASI.

§vfs_preopens: Vec<String>

Pre-opened virtual directories that will be accessible from WASI.

§setup_fs_fn: Option<Box<dyn Fn(&WasiInodes, &mut WasiFs) -> Result<(), String> + Send>>§stdout: Option<Box<dyn VirtualFile + Send + Sync + 'static>>§stderr: Option<Box<dyn VirtualFile + Send + Sync + 'static>>§stdin: Option<Box<dyn VirtualFile + Send + Sync + 'static>>§fs: Option<WasiFsRoot>§runtime: Option<Arc<dyn Runtime + Send + Sync + 'static>>§current_dir: Option<PathBuf>§uses: Vec<BinaryPackage>

List of webc dependencies to be injected.

§included_packages: HashSet<PackageId>§module_hash: Option<ModuleHash>§map_commands: HashMap<String, PathBuf>

List of host commands to map into the WASI instance.

§capabilites: Capabilities§additional_imports: Imports§snapshot_on: Vec<SnapshotTrigger>§snapshot_interval: Option<Duration>§journals: Vec<Arc<DynJournal>>§attach_ctrl_c: bool

Implementations§

source§

impl WasiEnvBuilder

source

pub fn new(program_name: impl Into<String>) -> Self

Creates an empty WasiEnvBuilder.

source

pub fn env<Key, Value>(self, key: Key, value: Value) -> Self
where Key: AsRef<[u8]>, Value: AsRef<[u8]>,

Add an environment variable pair.

Both the key and value of an environment variable must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

source

pub fn attach_ctrl_c(self) -> Self

Attaches a ctrl-c handler which will send signals to the process rather than immediately termiante it

source

pub fn add_env<Key, Value>(&mut self, key: Key, value: Value)
where Key: AsRef<[u8]>, Value: AsRef<[u8]>,

Add an environment variable pair.

Both the key and value of an environment variable must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

source

pub fn envs<I, Key, Value>(self, env_pairs: I) -> Self
where I: IntoIterator<Item = (Key, Value)>, Key: AsRef<[u8]>, Value: AsRef<[u8]>,

Add multiple environment variable pairs.

Both the key and value of the environment variables must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

source

pub fn add_envs<I, Key, Value>(&mut self, env_pairs: I)
where I: IntoIterator<Item = (Key, Value)>, Key: AsRef<[u8]>, Value: AsRef<[u8]>,

Add multiple environment variable pairs.

Both the key and value of the environment variables must not contain a nul byte (0x0), and the key must not contain the = byte (0x3d).

source

pub fn get_env(&self) -> &[(String, Vec<u8>)]

Get a reference to the configured environment variables.

source

pub fn get_env_mut(&mut self) -> &mut Vec<(String, Vec<u8>)>

Get a mutable reference to the configured environment variables.

source

pub fn entry_function<S>(self, entry_function: S) -> Self
where S: AsRef<str>,

source

pub fn set_entry_function<S>(&mut self, entry_function: S)
where S: AsRef<str>,

source

pub fn arg<V>(self, arg: V) -> Self
where V: AsRef<[u8]>,

Add an argument.

Arguments must not contain the nul (0x0) byte

source

pub fn add_arg<V>(&mut self, arg: V)
where V: AsRef<[u8]>,

Add an argument.

Arguments must not contain the nul (0x0) byte.

source

pub fn args<I, Arg>(self, args: I) -> Self
where I: IntoIterator<Item = Arg>, Arg: AsRef<[u8]>,

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

source

pub fn add_args<I, Arg>(&mut self, args: I)
where I: IntoIterator<Item = Arg>, Arg: AsRef<[u8]>,

Add multiple arguments.

Arguments must not contain the nul (0x0) byte

source

pub fn get_args(&self) -> &[String]

Get a reference to the configured arguments.

source

pub fn get_args_mut(&mut self) -> &mut Vec<String>

Get a mutable reference to the configured arguments.

source

pub fn use_webc(self, pkg: BinaryPackage) -> Self

Adds a container this module inherits from.

This will make all of the container’s files and commands available to the resulting WASI instance.

source

pub fn set_module_hash(&mut self, hash: ModuleHash) -> &mut Self

Sets the module hash for the running process. This ensures that the journal can restore the records for the right module. If no module hash is supplied then the process will start with a random module hash.

source

pub fn add_webc(&mut self, pkg: BinaryPackage) -> &mut Self

Adds a container this module inherits from.

This will make all of the container’s files and commands available to the resulting WASI instance.

source

pub fn include_package(&mut self, pkg_id: PackageId) -> &mut Self

Adds a package that is already included in the WasiEnvBuilder filesystem. These packages will not be merged to the final filesystem since they are already included.

source

pub fn include_packages( &mut self, pkg_ids: impl IntoIterator<Item = PackageId>, ) -> &mut Self

Adds packages that is already included in the WasiEnvBuilder filesystem. These packages will not be merged to the final filesystem since they are already included.

source

pub fn uses<I>(self, uses: I) -> Self
where I: IntoIterator<Item = BinaryPackage>,

Adds a list of other containers this module inherits from.

This will make all of the container’s files and commands available to the resulting WASI instance.

source

pub fn map_command<Name, Target>(self, name: Name, target: Target) -> Self
where Name: AsRef<str>, Target: AsRef<str>,

Map an atom to a local binary

source

pub fn add_mapped_command<Name, Target>(&mut self, name: Name, target: Target)
where Name: AsRef<str>, Target: AsRef<str>,

Map an atom to a local binary

source

pub fn map_commands<I, Name, Target>(self, map_commands: I) -> Self
where I: IntoIterator<Item = (Name, Target)>, Name: AsRef<str>, Target: AsRef<str>,

Maps a series of atoms to the local binaries

source

pub fn add_mapped_commands<I, Name, Target>(&mut self, map_commands: I)
where I: IntoIterator<Item = (Name, Target)>, Name: AsRef<str>, Target: AsRef<str>,

Maps a series of atoms to local binaries.

source

pub fn preopen_dir<P>(self, po_dir: P) -> Result<Self, WasiStateCreationError>
where P: AsRef<Path>,

Preopen a directory

This opens the given directory at the virtual root, /, and allows the WASI module to read and write to the given directory.

source

pub fn add_preopen_dir<P>( &mut self, po_dir: P, ) -> Result<(), WasiStateCreationError>
where P: AsRef<Path>,

Adds a preopen a directory

This opens the given directory at the virtual root, /, and allows the WASI module to read and write to the given directory.

source

pub fn preopen_dirs<I, P>(self, dirs: I) -> Result<Self, WasiStateCreationError>
where I: IntoIterator<Item = P>, P: AsRef<Path>,

Preopen multiple directories.

This opens the given directories at the virtual root, /, and allows the WASI module to read and write to the given directory.

source

pub fn preopen_build<F>(self, inner: F) -> Result<Self, WasiStateCreationError>
where F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,

Preopen a directory and configure it.

Usage:

WasiEnv::builder("program_name")
   .preopen_build(|p| p.directory("src").read(true).write(true).create(true))?
   .preopen_build(|p| p.directory(".").alias("dot").read(true))?
   .build_init()?;
source

pub fn add_preopen_build<F>( &mut self, inner: F, ) -> Result<(), WasiStateCreationError>
where F: Fn(&mut PreopenDirBuilder) -> &mut PreopenDirBuilder,

Preopen a directory and configure it.

Usage:

WasiEnv::builder("program_name")
   .preopen_build(|p| p.directory("src").read(true).write(true).create(true))?
   .preopen_build(|p| p.directory(".").alias("dot").read(true))?
   .build_init()?;
source

pub fn preopen_vfs_dirs<I>( &mut self, po_dirs: I, ) -> Result<&mut Self, WasiStateCreationError>
where I: IntoIterator<Item = String>,

Preopen the given directories from the Virtual FS.

source

pub fn map_dir<P>( self, alias: &str, po_dir: P, ) -> Result<Self, WasiStateCreationError>
where P: AsRef<Path>,

Preopen a directory with a different name exposed to the WASI.

source

pub fn add_map_dir<P>( &mut self, alias: &str, po_dir: P, ) -> Result<(), WasiStateCreationError>
where P: AsRef<Path>,

Preopen a directory with a different name exposed to the WASI.

source

pub fn map_dirs<I, P>( self, mapped_dirs: I, ) -> Result<Self, WasiStateCreationError>
where I: IntoIterator<Item = (String, P)>, P: AsRef<Path>,

Preopen directorys with a different names exposed to the WASI.

source

pub fn add_journal(&mut self, journal: Arc<DynJournal>)

Specifies one or more journal files that Wasmer will use to restore the state of the WASM process.

The state of the WASM process and its sandbox will be reapplied use the journals in the order that you specify here.

The last journal file specified will be created if it does not exist and opened for read and write. New journal events will be written to this file

source

pub fn get_current_dir(&mut self) -> Option<PathBuf>

source

pub fn set_current_dir(&mut self, dir: impl Into<PathBuf>)

source

pub fn current_dir(self, dir: impl Into<PathBuf>) -> Self

source

pub fn stdout( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> Self

Overwrite the default WASI stdout, if you want to hold on to the original stdout use WasiFs::swap_file after building.

source

pub fn set_stdout( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, )

Overwrite the default WASI stdout, if you want to hold on to the original stdout use WasiFs::swap_file after building.

source

pub fn stderr( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> Self

Overwrite the default WASI stderr, if you want to hold on to the original stderr use WasiFs::swap_file after building.

source

pub fn set_stderr( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, )

Overwrite the default WASI stderr, if you want to hold on to the original stderr use WasiFs::swap_file after building.

source

pub fn stdin( self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, ) -> Self

Overwrite the default WASI stdin, if you want to hold on to the original stdin use WasiFs::swap_file after building.

source

pub fn set_stdin( &mut self, new_file: Box<dyn VirtualFile + Send + Sync + 'static>, )

Overwrite the default WASI stdin, if you want to hold on to the original stdin use WasiFs::swap_file after building.

source

pub fn fs(self, fs: Box<dyn FileSystem + Send + Sync>) -> Self

Sets the FileSystem to be used with this WASI instance.

This is usually used in case a custom virtual_fs::FileSystem is needed.

source

pub fn set_fs(&mut self, fs: Box<dyn FileSystem + Send + Sync>)

source

pub fn sandbox_fs(self, fs: TmpFileSystem) -> Self

Sets a new sandbox FileSystem to be used with this WASI instance.

This is usually used in case a custom virtual_fs::FileSystem is needed.

source

pub fn setup_fs( self, setup_fs_fn: Box<dyn Fn(&WasiInodes, &mut WasiFs) -> Result<(), String> + Send>, ) -> Self

Configure the WASI filesystem before running.

source

pub fn runtime(self, runtime: Arc<dyn Runtime + Send + Sync>) -> Self

Sets the WASI runtime implementation and overrides the default implementation

source

pub fn set_runtime(&mut self, runtime: Arc<dyn Runtime + Send + Sync>)

source

pub fn capabilities(self, capabilities: Capabilities) -> Self

source

pub fn capabilities_mut(&mut self) -> &mut Capabilities

source

pub fn set_capabilities(&mut self, capabilities: Capabilities)

source

pub fn add_snapshot_trigger(&mut self, on: SnapshotTrigger)

source

pub fn with_snapshot_interval(&mut self, interval: Duration)

source

pub fn import( self, namespace: impl Into<String>, name: impl Into<String>, value: impl Into<Extern>, ) -> Self

Add an item to the list of importable items provided to the instance.

source

pub fn add_import( &mut self, namespace: impl Into<String>, name: impl Into<String>, value: impl Into<Extern>, )

Add an item to the list of importable items provided to the instance.

source

pub fn add_imports<I, S1, S2, E>(&mut self, imports: I)
where I: IntoIterator<Item = ((S1, S2), E)>, S1: Into<String>, S2: Into<String>, E: Into<Extern>,

source

pub fn imports<I, S1, S2, E>(self, imports: I) -> Self
where I: IntoIterator<Item = ((S1, S2), E)>, S1: Into<String>, S2: Into<String>, E: Into<Extern>,

source

pub fn build_init(self) -> Result<WasiEnvInit, WasiStateCreationError>

Consumes the WasiEnvBuilder and produces a WasiEnvInit, which can be used to construct a new WasiEnv.

Returns the error from WasiFs::new if there’s an error

NOTE: You should prefer to not work directly with WasiEnvInit. Use WasiEnvBuilder::run or WasiEnvBuilder::run_with_store instead to ensure proper invokation of WASI modules.

source

pub fn build(self) -> Result<WasiEnv, WasiRuntimeError>

source

pub fn instantiate( self, module: Module, store: &mut impl AsStoreMut, ) -> Result<(Instance, WasiFunctionEnv), WasiRuntimeError>

Consumes the WasiEnvBuilder and produces a WasiEnvInit, which can be used to construct a new WasiEnv.

Returns the error from WasiFs::new if there’s an error

source

pub fn instantiate_ext( self, module: Module, module_hash: ModuleHash, store: &mut impl AsStoreMut, ) -> Result<(Instance, WasiFunctionEnv), WasiRuntimeError>

source

pub fn run(self, module: Module) -> Result<(), WasiRuntimeError>

source

pub fn run_ext( self, module: Module, module_hash: ModuleHash, ) -> Result<(), WasiRuntimeError>

source

pub fn run_with_store( self, module: Module, store: &mut Store, ) -> Result<(), WasiRuntimeError>

source

pub fn run_with_store_ext( self, module: Module, module_hash: ModuleHash, store: &mut Store, ) -> Result<(), WasiRuntimeError>

source

pub fn run_with_store_async( self, module: Module, module_hash: ModuleHash, store: Store, ) -> Result<(), WasiRuntimeError>

Start the WASI executable with async threads enabled.

Trait Implementations§

source§

impl Debug for WasiEnvBuilder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for WasiEnvBuilder

source§

fn default() -> WasiEnvBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcastable for T
where T: Any + Debug + 'static,

§

fn upcast_any_ref(&self) -> &(dyn Any + 'static)

§

fn upcast_any_mut(&mut self) -> &mut (dyn Any + 'static)

§

fn upcast_any_box(self: Box<T>) -> Box<dyn Any>

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,