Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,10 @@ jobs:
if: matrix.config == 'release'
run: dotnet run -c ${{ matrix.config }} --project benchmarks/simple/simple.csproj
- name: Run examples
env:
EXAMPLES: externref funcref global hello linking memory table
run: |
cd examples/hello
dotnet run
cd ../global
dotnet run
cd ../memory
dotnet run
cd ../table
dotnet run
cd ../externref
dotnet run
cd ../funcref
dotnet run
for e in $EXAMPLES; do cd examples/$e && dotnet run && cd ../..; done
- name: Create package
run: |
cd src
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<DevBuild Condition="'$(DevBuild)'==''">true</DevBuild>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">0.21.0</WasmtimeVersion>
<WasmtimeVersion Condition="'$(WasmtimeVersion)'==''">0.22.0</WasmtimeVersion>
<WasmtimePackageVersion Condition="'$(DevBuild)'=='true'">$(WasmtimeVersion)-preview1-dev</WasmtimePackageVersion>
<WasmtimePackageVersion Condition="'$(WasmtimePackageVersion)'==''">$(WasmtimeVersion)-preview1</WasmtimePackageVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@

## Installation

You can add a package reference with the [.NET Core SDK](https://dotnet.microsoft.com/):
You can add a package reference with the [.NET SDK](https://dotnet.microsoft.com/):

```text
$ dotnet add package --version 0.21.0-preview1 wasmtime
$ dotnet add package --version 0.22.0-preview1 wasmtime
```

_Note that the `--version` option is required because the package is currently prerelease._
Expand All @@ -54,7 +54,7 @@ $ dotnet new console
Next, add a reference to the [Wasmtime package](https://www.nuget.org/packages/Wasmtime):

```
$ dotnet add package --version 0.21.0-preview1 wasmtime
$ dotnet add package --version 0.22.0-preview1 wasmtime
```

Replace the contents of `Program.cs` with the following code:
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/simple/simple.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 6 additions & 6 deletions docs/articles/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The [.NET embedding of Wasmtime](https://github.com/bytecodealliance/wasmtime-dotnet) enables .NET developers to easily instantiate and execute WebAssembly modules using Wasmtime.

For this tutorial, we will create a WebAssembly module and use that WebAssembly module from a .NET Core 3.1 application.
For this tutorial, we will create a WebAssembly module and use that WebAssembly module from a .NET 5 application.

# A simple WebAssembly module

Expand All @@ -23,13 +23,13 @@ This module simply imports a `hello` function from the host and exports a `run`

# Using the WebAssembly module from .NET

## Installing a .NET Core 3.0 SDK
## Installing a .NET 5 SDK

Install a [.NET Core 3.1 SDK](https://dotnet.microsoft.com/download/dotnet-core/3.1) for your platform if you haven't already.
Install a [.NET 5 SDK](https://dotnet.microsoft.com/download/dotnet/5.0) for your platform if you haven't already.

This will add a `dotnet` command to your PATH.

## Creating the .NET Core project
## Creating the .NET project

The .NET program will be a simple console application, so create a new console project with `dotnet new`:

Expand All @@ -44,7 +44,7 @@ dotnet new console
To use the .NET embedding of Wasmtime from the project, we need to add a reference to the [Wasmtime NuGet package](https://www.nuget.org/packages/Wasmtime):

```text
dotnet add package --version 0.21.0-preview1 wasmtime
dotnet add package --version 0.22.0-preview1 wasmtime
```

_Note that the `--version` option is required because the package is currently prerelease._
Expand Down Expand Up @@ -100,7 +100,7 @@ Use `dotnet build` to build the .NET application:
dotnet build
```

This will create a `tutorial` (or `tutorial.exe` on Windows) executable in the `bin/Debug/netcoreapp3.1` directory that implements the .NET Core application.
This will create a `tutorial` (or `tutorial.exe` on Windows) executable in the `bin/Debug/net5.0` directory that implements the .NET application.

## Running the .NET application

Expand Down
2 changes: 1 addition & 1 deletion examples/externref/externref.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/funcref/funcref.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion examples/global/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ static void Main(string[] args)
using var function = host.DefineFunction(
"",
"print_global",
() => {
() =>
{
Console.WriteLine($"The value of the global is: {global.Value}.");
}
);
Expand Down
2 changes: 1 addition & 1 deletion examples/global/global.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/hello/hello.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
31 changes: 31 additions & 0 deletions examples/linking/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using Wasmtime;

namespace Example
{
class Program
{
static void Main(string[] args)
{
using var engine = new EngineBuilder().WithModuleLinking(true).Build();
using var module = Module.FromTextFile(engine, "name.wat");
using var program = Module.FromTextFile(engine, "program.wat");

using var store = new Store(engine);
using var host = new Host(store);

using var memory = host.DefineMemory("", "mem");

host.DefineInstance("", "inst", module.Instantiate(store, memory));

host.DefineFunction("", "print", (Caller caller, int addr, int len) =>
{
Console.WriteLine(caller.GetMemory("mem").ReadString(addr, len));
});

using dynamic instance = host.Instantiate(program);

instance.run();
}
}
}
12 changes: 12 additions & 0 deletions examples/linking/linking.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Wasmtime.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions examples/linking/name.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(module
(import "" "mem" (memory 1))
(func $name (export "write") (param i32) (result i32)
local.get 0
i32.const 119 ;;; w
i32.store offset=0 align=1
local.get 0
i32.const 111 ;;; o
i32.store offset=1 align=1
local.get 0
i32.const 114 ;;; r
i32.store offset=2 align=1
local.get 0
i32.const 108 ;;; l
i32.store offset=3 align=1
local.get 0
i32.const 100 ;;; d
i32.store offset=4 align=1
i32.const 5
)
)
21 changes: 21 additions & 0 deletions examples/linking/program.wat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
(module
(import "" "print" (func $print (param i32 i32)))
(import "" "inst" (instance $inst (export "write" (func $write (param i32) (result i32)))))
(import "" "mem" (memory 1))
(export "mem" (memory 0))
(func (export "run") (local i32)
i32.const 6
call $inst.$write
i32.const 6
i32.add
local.tee 0
i32.const 33 ;;; !
i32.store align=1
i32.const 0
local.get 0
i32.const 1
i32.add
call $print
)
(data (i32.const 0) "Hello ")
)
3 changes: 2 additions & 1 deletion examples/memory/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ static void Main(string[] args)
using var function = host.DefineFunction(
"",
"log",
(Caller caller, int address, int length) => {
(Caller caller, int address, int length) =>
{
var message = caller.GetMemory("mem").ReadString(address, length);
Console.WriteLine($"Message from WebAssembly: {message}");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/memory/memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion examples/table/table.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
12 changes: 12 additions & 0 deletions src/EngineBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ public EngineBuilder WithOptimizationLevel(OptimizationLevel level)
return this;
}

public EngineBuilder WithModuleLinking(bool enable)
{
_enableModuleLinking = enable;
return this;
}

/// <summary>
/// Builds the <see cref="Engine" /> instance.
/// </summary>
Expand Down Expand Up @@ -216,6 +222,11 @@ public Engine Build()
Interop.wasmtime_config_wasm_multi_value_set(config, _enableMultiValue.Value);
}

if (_enableModuleLinking.HasValue)
{
Interop.wasmtime_config_wasm_module_linking_set(config, _enableModuleLinking.Value);
}

if (_strategy.HasValue)
{
Interop.wasmtime_config_strategy_set(config, _strategy.Value);
Expand All @@ -240,6 +251,7 @@ public Engine Build()
private bool? _enableSIMD;
private bool? _enableBulkMemory;
private bool? _enableMultiValue;
private bool? _enableModuleLinking;
private Interop.wasmtime_strategy_t? _strategy;
private bool? _enableCraneliftDebugVerifier;
private Interop.wasmtime_opt_level_t? _optLevel;
Expand Down
11 changes: 9 additions & 2 deletions src/Exports/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Wasmtime.Exports
{
/// <summary>
/// Represents an export of a WebAssembly module.
/// Represents an export of a WebAssembly module or instance.
/// </summary>
public abstract class Export
{
Expand All @@ -13,7 +13,14 @@ internal Export(IntPtr exportType)
unsafe
{
var name = Interop.wasm_exporttype_name(exportType);
Name = Marshal.PtrToStringUTF8((IntPtr)name->data, (int)name->size);
if (name->size == UIntPtr.Zero)
{
Name = String.Empty;
}
else
{
Name = Marshal.PtrToStringUTF8((IntPtr)name->data, (int)name->size);
}
}
}

Expand Down
Loading