Module wasmer_ruby::Wasmer::Wasi

source ·
Expand description

Wasmer’s WASI implementation.

From the user perspective, WASI is a bunch of imports. To generate the appropriated imports, you can use StateBuilder to build an Environment. This environment holds the WASI memory, and can be used to generate a valid ImportObject. This last one can be passed to Instance to instantiate a Module that needs WASI support.

Example

store = Wasmer::Store.new
module_ = Wasmer::Module.new store, bytes

# Get the WASI version.
wasi_version = Wasmer::Wasi::get_version module_, true

# Build a WASI environment for the imports.
wasi_env = Wasmer::Wasi::StateBuilder.new("test-program")
             .argument("--foo")
             .environments({"ABC" => "DEF", "X" => "YZ"})
             .map_directory("the_host_directory", ".")
             .finalize

# Generate an `ImportObject` for the WASI environment.
import_object = wasi_env.generate_import_object store, wasi_version

# Now we are ready to instantiate the module.
instance = Wasmer::Instance.new module_, import_object

instance.exports._start.()

Structs

Enums

Functions

  • Detect the version of WASI being used based on the import namespaces.