Skip to content

A Plugin Development Kit (PDK) for building Extism plugins in C# using .NET NativeAOT, compiled to WebAssembly.

Notifications You must be signed in to change notification settings

andreakarasho/Extism.Pdk.NativeAot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extism PDK for .NET NativeAOT

A Plugin Development Kit (PDK) for building Extism plugins in C# using .NET NativeAOT, compiled to WebAssembly.

Write your plugin exports as regular C# methods, annotate them with [ExtismExport], and the included source generator + MSBuild targets handle the rest — WIT generation, WASM compilation, component-model unbundling, and optional WASI stubbing.

How It Works

The project has three main components:

  • Extism.Pdk.NativeAot — The PDK library. Provides the Pdk API (input/output, memory, config, variables, logging, HTTP) and MSBuild integration that automatically configures NativeAOT-to-WASM compilation.
  • Extism.Pdk.SourceGenerator — A Roslyn source generator that finds [ExtismExport("name")] attributes and generates the UnmanagedCallersOnly wrapper functions, handling serialization/deserialization of strings, byte arrays, primitives, multi-parameter packing, and FlatBuffers types.
  • clip.py — A post-publish tool that strips the WASM Component Model wrapper, optionally stubs WASI imports, and converts namespaces so the resulting .wasm file is a bare module compatible with the Extism runtime.

Prerequisites

Building the Sample Plugin

dotnet publish samples/extism-plugin-dotnet/ExtismPluginExample.csproj -c Release

This compiles the plugin to WASM via NativeAOT, then automatically runs clip.py to produce the final ExtismPluginExample_clipped.wasm.

To keep wasi:* imports in the clipped output, set this in your plugin .csproj:

<PropertyGroup>
  <ExtismClipKeepWasiImports>true</ExtismClipKeepWasiImports>
</PropertyGroup>

To keep stubbing enabled but bridge key WASI P2 calls through wasi_snapshot_preview1 imports (including random/clock/exit, basic stdio handles, and preopen directory enumeration), set:

<PropertyGroup>
  <ExtismClipWasiP1Bridge>true</ExtismClipWasiP1Bridge>
</PropertyGroup>

Running the Sample Host

dotnet run --project samples/extism-host-dotnet/ExtismHostExample.csproj

The host loads the clipped WASM plugin and calls every exported function, demonstrating string, numeric, binary, and FlatBuffers round-trips.

Writing a Plugin

  1. Reference Extism.Pdk.NativeAot and import its .props / .targets in your .csproj.
  2. Write static methods and annotate them with [ExtismExport("name")]:
using Extism.Pdk;

public static class Plugin
{
    [ExtismExport("greet")]
    public static string Greet(string name) => $"Hello, {name}!";

    [ExtismExport("add")]
    public static int Add(int a, int b) => a + b;
}

Supported Types

Category Parameter Return
string yes yes
byte[] yes yes
Primitives (bool, byte, sbyte, short, ushort, int, uint, long, ulong, float, double) yes yes
void yes
FlatBuffers (IFlatbufferObject) yes yes

Multi-parameter exports are supported when all parameters are primitives (packed as little-endian bytes).

Acknowledgements

About

A Plugin Development Kit (PDK) for building Extism plugins in C# using .NET NativeAOT, compiled to WebAssembly.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •