Move Wasmtime for .NET to the Wasmtime repo.
This moves the Wasmtime for .NET implementation to the Wasmtime repo. Wasmtime for .NET is a binding of the Wasmtime API for use in .NET.
This commit is contained in:
33
crates/misc/dotnet/examples/global/Program.cs
Normal file
33
crates/misc/dotnet/examples/global/Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Wasmtime;
|
||||
|
||||
namespace HelloExample
|
||||
{
|
||||
class Host : IHost
|
||||
{
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
[Import("print_global")]
|
||||
public void PrintGlobal()
|
||||
{
|
||||
Console.WriteLine($"The value of the global is: {Global.Value}.");
|
||||
}
|
||||
|
||||
[Import("global")]
|
||||
public readonly MutableGlobal<int> Global = new MutableGlobal<int>(1);
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using (var engine = new Engine())
|
||||
using (var store = engine.CreateStore())
|
||||
using (var module = store.CreateModule("global.wasm"))
|
||||
using (dynamic instance = module.Instantiate(new Host()))
|
||||
{
|
||||
instance.run(20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
crates/misc/dotnet/examples/global/global.csproj
Normal file
21
crates/misc/dotnet/examples/global/global.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Wasmtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- This is needed as we're not referencing Wasmtime as a package. -->
|
||||
<Target Name="BuildWasmtime" BeforeTargets="AssignTargetPaths">
|
||||
<Message Text="Building Wasmtime from source." Importance="High" />
|
||||
<Exec Command="$(BuildWasmtimeCommand)" StandardOutputImportance="Low" StandardErrorImportance="Low" />
|
||||
<ItemGroup>
|
||||
<None Include="$(WasmtimeOutputPath)/$(WasmtimeLibraryFilename)" Link="$(WasmtimeLibraryFilename)" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
BIN
crates/misc/dotnet/examples/global/global.wasm
Normal file
BIN
crates/misc/dotnet/examples/global/global.wasm
Normal file
Binary file not shown.
22
crates/misc/dotnet/examples/global/global.wat
Normal file
22
crates/misc/dotnet/examples/global/global.wat
Normal file
@@ -0,0 +1,22 @@
|
||||
(module
|
||||
(import "" "print_global" (func $.print_global))
|
||||
(import "" "global" (global $.global (mut i32)))
|
||||
(func $run (param i32) (local $i i32)
|
||||
loop $l1
|
||||
call $.print_global
|
||||
global.get $.global
|
||||
i32.const 2
|
||||
i32.mul
|
||||
global.set $.global
|
||||
local.get $i
|
||||
i32.const 1
|
||||
i32.add
|
||||
local.set $i
|
||||
local.get $i
|
||||
local.get 0
|
||||
i32.le_u
|
||||
br_if $l1
|
||||
end
|
||||
)
|
||||
(export "run" (func $run))
|
||||
)
|
||||
30
crates/misc/dotnet/examples/hello/Program.cs
Normal file
30
crates/misc/dotnet/examples/hello/Program.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Wasmtime;
|
||||
|
||||
namespace HelloExample
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
crates/misc/dotnet/examples/hello/hello.csproj
Normal file
21
crates/misc/dotnet/examples/hello/hello.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Wasmtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- This is needed as we're not referencing Wasmtime as a package. -->
|
||||
<Target Name="BuildWasmtime" BeforeTargets="AssignTargetPaths">
|
||||
<Message Text="Building Wasmtime from source." Importance="High" />
|
||||
<Exec Command="$(BuildWasmtimeCommand)" StandardOutputImportance="Low" StandardErrorImportance="Low" />
|
||||
<ItemGroup>
|
||||
<None Include="$(WasmtimeOutputPath)/$(WasmtimeLibraryFilename)" Link="$(WasmtimeLibraryFilename)" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
BIN
crates/misc/dotnet/examples/hello/hello.wasm
Normal file
BIN
crates/misc/dotnet/examples/hello/hello.wasm
Normal file
Binary file not shown.
8
crates/misc/dotnet/examples/hello/hello.wat
Normal file
8
crates/misc/dotnet/examples/hello/hello.wat
Normal file
@@ -0,0 +1,8 @@
|
||||
(module
|
||||
(type $t0 (func))
|
||||
(import "" "hello" (func $.hello (type $t0)))
|
||||
(func $run
|
||||
call $.hello
|
||||
)
|
||||
(export "run" (func $run))
|
||||
)
|
||||
31
crates/misc/dotnet/examples/memory/Program.cs
Normal file
31
crates/misc/dotnet/examples/memory/Program.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using Wasmtime;
|
||||
|
||||
namespace HelloExample
|
||||
{
|
||||
class Host : IHost
|
||||
{
|
||||
public Instance Instance { get; set; }
|
||||
|
||||
[Import("log")]
|
||||
public void Log(int address, int length)
|
||||
{
|
||||
var message = Instance.Externs.Memories[0].ReadString(address, length);
|
||||
Console.WriteLine($"Message from WebAssembly: {message}");
|
||||
}
|
||||
}
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
using (var engine = new Engine())
|
||||
using (var store = engine.CreateStore())
|
||||
using (var module = store.CreateModule("memory.wasm"))
|
||||
using (dynamic instance = module.Instantiate(new Host()))
|
||||
{
|
||||
instance.run();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
crates/misc/dotnet/examples/memory/memory.csproj
Normal file
21
crates/misc/dotnet/examples/memory/memory.csproj
Normal file
@@ -0,0 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp3.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Wasmtime.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- This is needed as we're not referencing Wasmtime as a package. -->
|
||||
<Target Name="BuildWasmtime" BeforeTargets="AssignTargetPaths">
|
||||
<Message Text="Building Wasmtime from source." Importance="High" />
|
||||
<Exec Command="$(BuildWasmtimeCommand)" StandardOutputImportance="Low" StandardErrorImportance="Low" />
|
||||
<ItemGroup>
|
||||
<None Include="$(WasmtimeOutputPath)/$(WasmtimeLibraryFilename)" Link="$(WasmtimeLibraryFilename)" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
BIN
crates/misc/dotnet/examples/memory/memory.wasm
Normal file
BIN
crates/misc/dotnet/examples/memory/memory.wasm
Normal file
Binary file not shown.
12
crates/misc/dotnet/examples/memory/memory.wat
Normal file
12
crates/misc/dotnet/examples/memory/memory.wat
Normal file
@@ -0,0 +1,12 @@
|
||||
(module
|
||||
(type $t0 (func (param i32 i32)))
|
||||
(import "" "log" (func $.log (type $t0)))
|
||||
(memory (export "mem") 1 2)
|
||||
(data (i32.const 0) "Hello World")
|
||||
(func $run
|
||||
i32.const 0
|
||||
i32.const 11
|
||||
call $.log
|
||||
)
|
||||
(export "run" (func $run))
|
||||
)
|
||||
Reference in New Issue
Block a user