Skip to content
Open
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
5 changes: 4 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<WasmtimePackageVersion Condition="'$(DevBuild)'=='true'">$(WasmtimeVersion)$(WasmtimeDotnetVersion)-dev</WasmtimePackageVersion>
<WasmtimePackageVersion Condition="'$(WasmtimePackageVersion)'==''">$(WasmtimeVersion)$(WasmtimeDotnetVersion)</WasmtimePackageVersion>
</PropertyGroup>
</Project>
<PropertyGroup Condition="'$(DevBuild)'=='true'">
<DefineConstants>$(DefineConstants);WASMTIME_DEV</DefineConstants>
</PropertyGroup>
</Project>
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ $ dotnet build Wasmtime.sln
This will download the latest development snapshot of Wasmtime for your
platform.

By default, local builds set `DevBuild=true`, which uses the dev C API artifacts
(`wasmtime-dev-*`) and enables a `WASMTIME_DEV` build define to match the dev
ABI (value/trap layouts). To build against the stable Wasmtime release instead,
override the flag:

```
$ dotnet build Wasmtime.sln -p:DevBuild=false
```

If you switch between `DevBuild=true` and `DevBuild=false`, you may need to
delete `src/obj` to force the correct C API download.

### Testing

Use `dotnet` to run the unit tests:
Expand Down
4 changes: 2 additions & 2 deletions src/Caller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,11 @@ public ulong Fuel

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern unsafe bool wasmtime_caller_export_get(IntPtr caller, byte* name, UIntPtr len, out Extern item);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasmtime_caller_context(IntPtr caller);
}

Expand Down
48 changes: 24 additions & 24 deletions src/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,76 +382,76 @@ protected override bool ReleaseHandle()

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_config_new();

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_config_delete(IntPtr config);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_debug_info_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_epoch_interruption_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_consume_fuel_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_max_wasm_stack_set(Handle config, nuint size);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_threads_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_reference_types_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_relaxed_simd_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_relaxed_simd_deterministic_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_bulk_memory_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_multi_value_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_multi_memory_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_wasm_memory64_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_strategy_set(Handle config, byte strategy);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_cranelift_debug_verifier_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_cranelift_nan_canonicalization_set(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_cranelift_opt_level_set(Handle config, byte level);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_profiler_set(Handle config, byte strategy);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_memory_reservation_set(Handle config, ulong size);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_memory_guard_size_set(Handle config, ulong size);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasmtime_config_cache_config_load(Handle config, [MarshalAs(Extensions.LPUTF8Str)] string? path);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_config_macos_use_mach_ports(Handle config, [MarshalAs(UnmanagedType.I1)] bool enable);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ protected override bool ReleaseHandle()

private static class Native
{
[DllImport(LibraryName)]
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_engine_new();

[DllImport(LibraryName)]
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_engine_new_with_config(Config.Handle config);

[DllImport(LibraryName)]
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_engine_delete(IntPtr engine);

[DllImport(LibraryName)]
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_engine_increment_epoch(Handle engine);

[DllImport(LibraryName)]
[DllImport(LibraryName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern bool wasmtime_engine_is_pulley(Handle engine);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Export.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public Export[] ToExportArray()

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_exporttype_vec_delete(in ExportTypeArray vec);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)]
public static extern byte wasm_externtype_kind(IntPtr valueType);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_exporttype_type(IntPtr exportType);
}
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public override string ToString()

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern ByteArray* wasm_exporttype_name(IntPtr type);
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ internal FunctionExport(IntPtr exportType, IntPtr externType) : base(exportType)

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_externtype_as_functype_const(IntPtr type);
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ internal GlobalExport(IntPtr exportType, IntPtr externType) : base(exportType)

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_externtype_as_globaltype_const(IntPtr type);
}
}
Expand Down Expand Up @@ -222,7 +222,7 @@ internal MemoryExport(IntPtr exportType, IntPtr externType) : base(exportType)

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_externtype_as_memorytype_const(IntPtr type);
}
}
Expand Down Expand Up @@ -267,7 +267,7 @@ internal TableExport(IntPtr exportType, IntPtr externType) : base(exportType)

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_externtype_as_tabletype_const(IntPtr type);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Externs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void Dispose()

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_extern_delete(in Extern self);
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/Function.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,47 +730,50 @@ internal static unsafe IntPtr HandleCallbackException(Exception ex)

internal static class Native
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void Finalizer(IntPtr data);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate IntPtr WasmtimeFuncCallback(IntPtr env, IntPtr caller, Value* args, nuint nargs, Value* results, nuint nresults);

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate IntPtr WasmtimeFuncUncheckedCallback(IntPtr env, IntPtr caller, ValueRaw* args_and_results, nuint num_args_and_results);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_func_new(IntPtr context, IntPtr type, WasmtimeFuncCallback callback, IntPtr env, Finalizer? finalizer, out ExternFunc func);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_func_new_unchecked(IntPtr context, IntPtr type, WasmtimeFuncUncheckedCallback callback, IntPtr env, Finalizer? finalizer, out ExternFunc func);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern IntPtr wasmtime_func_call(IntPtr context, in ExternFunc func, Value* args, nuint nargs, Value* results, nuint nresults, out IntPtr trap);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern IntPtr wasmtime_func_call_unchecked(IntPtr context, in ExternFunc func, ValueRaw* args_and_results, nuint args_and_results_len, out IntPtr trap);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasmtime_func_type(IntPtr context, in ExternFunc func);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern void wasmtime_func_from_raw(IntPtr context, IntPtr raw, out ExternFunc func);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern IntPtr wasmtime_func_to_raw(IntPtr context, in ExternFunc func);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_functype_new(in ValueTypeArray parameters, in ValueTypeArray results);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe ValueTypeArray* wasm_functype_params(IntPtr type);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe ValueTypeArray* wasm_functype_results(IntPtr type);


[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_functype_delete(IntPtr functype);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern IntPtr wasmtime_trap_new(byte* bytes, nuint len);
}

Expand Down
16 changes: 8 additions & 8 deletions src/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,28 +251,28 @@ protected override bool ReleaseHandle()

internal static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasmtime_global_new(IntPtr context, TypeHandle type, in Value val, out ExternGlobal global);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_global_get(IntPtr context, in ExternGlobal global, out Value val);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasmtime_global_set(IntPtr context, in ExternGlobal global, in Value val);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasmtime_global_type(IntPtr context, in ExternGlobal global);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_globaltype_new(IntPtr valueType, Mutability mutability);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_globaltype_content(IntPtr type);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern byte wasm_globaltype_mutability(IntPtr type);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_globaltype_delete(IntPtr type);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Import.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public Import[] ToImportArray()

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern void wasm_importtype_vec_delete(in ImportTypeArray vec);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_importtype_type(IntPtr importType);
}
}
Expand Down Expand Up @@ -124,10 +124,10 @@ public override string ToString()

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern ByteArray* wasm_importtype_module(IntPtr type);

[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static unsafe extern ByteArray* wasm_importtype_name(IntPtr type);
}
}
Expand Down Expand Up @@ -235,7 +235,7 @@ internal MemoryImport(IntPtr importType, IntPtr externType) : base(importType)

private static class Native
{
[DllImport(Engine.LibraryName)]
[DllImport(Engine.LibraryName, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr wasm_externtype_as_memorytype_const(IntPtr type);
}
}
Expand Down
Loading