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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
alexcrichton submitted PR Review.
alexcrichton submitted PR Review.
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?
alexcrichton created PR Review Comment:
Perhaps we could go ahead with the fully general
new_with_env
custom function for wasmtime itself?
peterhuene submitted PR Review.
peterhuene created PR Review Comment:
I'll change it to a function.
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.
peterhuene submitted PR Review.
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 theEngine
,Store
, andLinker
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
withwasi_snapshot_preview1
orwasi_unsable
.
alexcrichton submitted PR Review.
peterhuene merged PR #1411.
Last updated: Nov 22 2024 at 16:03 UTC