Implement WASI C API.

This commit implements an initial WASI C API that can be used to instantiate
and configure a WASI instance from C.

This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind
to Wasmtime's WASI implementation.
This commit is contained in:
Peter Huene
2020-02-07 11:24:26 -08:00
parent f8abe1169c
commit ae0b4090ce
28 changed files with 1303 additions and 268 deletions

View File

@@ -49,20 +49,33 @@ namespace Wasmtime
/// </summary>
/// <param name="host">The host to use for the WebAssembly module's instance.</param>
/// <returns>Returns a new <see cref="Instance" />.</returns>
public Instance Instantiate(IHost host)
public Instance Instantiate(IHost host = null)
{
if (host is null)
{
throw new ArgumentNullException(nameof(host));
}
return Instantiate(null, host);
}
if (host.Instance != null)
/// <summary>
/// Instantiates a WebAssembly module for the given host.
/// </summary>
/// <param name="wasi">The WASI instance to use for WASI imports.</param>
/// <param name="host">The host to use for the WebAssembly module's instance.</param>
/// <returns>Returns a new <see cref="Instance" />.</returns>
public Instance Instantiate(Wasi wasi, IHost host = null)
{
if (!(host?.Instance is null))
{
throw new InvalidOperationException("The host has already been associated with an instantiated module.");
}
host.Instance = new Instance(this, host);
return host.Instance;
var instance = new Instance(this, wasi, host);
if (!(host is null))
{
host.Instance = instance;
return instance;
}
return instance;
}
/// <summary>
@@ -94,6 +107,11 @@ namespace Wasmtime
Handle.Dispose();
Handle.SetHandleAsInvalid();
}
if (!(Imports is null))
{
Imports.Dispose();
Imports = null;
}
}
internal Interop.ModuleHandle Handle { get; private set; }