Stream: git-wasmtime

Topic: wasmtime / PR #1411 Reimplement the .NET API in terms of ...


view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 01:49):

peterhuene opened PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 01:56):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 02:05):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 03:21):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 05:50):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 08:12):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 08:15):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 15:49):

alexcrichton submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 15:49):

alexcrichton submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 15:49):

alexcrichton created PR Review Comment:

We might end up having a number of configuration options, so could this become a configuration method rather than a constructor parameter?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 15:49):

alexcrichton created PR Review Comment:

Perhaps we could go ahead with the fully general new_with_env custom function for wasmtime itself?

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 18:06):

peterhuene submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 18:06):

peterhuene created PR Review Comment:

I'll change it to a function.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 18:07):

peterhuene created PR Review Comment:

Can do. I'll see about sharing the impls between these and the wasm_ counterparts the best we can, too.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 18:07):

peterhuene submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 18:48):

peterhuene updated PR #1411 from reimplement-dotnet-api to master:

This PR takes a new approach to the .NET API.

Instead of using reflection to bind .NET code to host imports, we now internally use a Linker from Wasmtime to preform the binding.

This allows a much closer abstraction to what the Rust API has. In the new API, users interact with the Host type that represents a hosting environment for WebAssembly modules. It internally hides the Engine, Store, and Linker types.

So this:

class Host : IHost
{
    public Instance Instance { get; set; }

    [Import("hello")]
    public void SayHello()
    {
        Console.WriteLine("Hello from C#, WebAssembly!");
    }
}

class Program
{
    static void Main(string[] args)
    {
        using var engine = new Engine();
        using var store = engine.CreateStore();
        using var module = store.CreateModule("hello.wasm");
        using dynamic instance = module.Instantiate(new Host());

        instance.run();
    }
}

becomes this:

using var host = new Host();

host.DefineFunction(
    "",
    "hello",
    () => Console.WriteLine("Hello from C#, WebAssembly!")
);

using var module = host.LoadModule("hello.wasm");

using dynamic instance = host.Instantiate(module);
instance.run();

Where DefineFunction accepts lambdas up to 16 parameters (of acceptable Wasm types). The lambdas can also return tuples to represent multiple return values (of acceptable Wasm types).

Along with this PR are changes that make the WASI C API configurable on the module name, allowing users to call Host.DefineWasi with wasi_snapshot_preview1 or wasi_unsable.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 19:20):

alexcrichton submitted PR Review.

view this post on Zulip Wasmtime GitHub notifications bot (Mar 26 2020 at 19:35):

peterhuene merged PR #1411.


Last updated: Dec 23 2024 at 12:05 UTC