WACS.HostBindings.SourceGen
0.1.1
dotnet add package WACS.HostBindings.SourceGen --version 0.1.1
NuGet\Install-Package WACS.HostBindings.SourceGen -Version 0.1.1
<PackageReference Include="WACS.HostBindings.SourceGen" Version="0.1.1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="WACS.HostBindings.SourceGen" Version="0.1.1" />
<PackageReference Include="WACS.HostBindings.SourceGen"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add WACS.HostBindings.SourceGen --version 0.1.1
#r "nuget: WACS.HostBindings.SourceGen, 0.1.1"
#:package WACS.HostBindings.SourceGen@0.1.1
#addin nuget:?package=WACS.HostBindings.SourceGen&version=0.1.1
#tool nuget:?package=WACS.HostBindings.SourceGen&version=0.1.1
WACS.HostBindings.SourceGen
Roslyn source generator that auto-generates the IImports adapter for a
transpiled wasm module's host functions, using [WacsImport]-annotated
static methods discovered in the consumer's compilation references.
What it does
For every [assembly: WacsTranspiledImports(typeof(T))] attribute the
generator finds across the compilation:
- Scans referenced assemblies for
[WacsImport(module, name)]static methods. - Pairs each method on the
IImportsinterface with its matching binding (by wasm import name). - Emits a
GeneratedHostImports : IImportspartial class whose method bodies forward to the matched bindings. - Threads any binding-required shared-state parameters
(e.g.
Wacs.WASI.Preview1.State) through a constructor.
If no binding is found for an import, the generator emits a WACS001 error
diagnostic so the compile fails with a clear message rather than at runtime.
Diagnostics
WACS001(error): no binding found for<module>.<name>WACS002(error): binding signature mismatchWACS003(error): multiple bindings registered (ambiguous)WACS004(info): matched binding (verbose; off by default)
Consumer usage
Add the generator alongside your binding package(s):
<ItemGroup>
<Reference Include="MyTranspiledApp" HintPath="MyTranspiledApp.dll" />
<PackageReference Include="WACS.WASI.Preview1" />
<PackageReference Include="WACS.HostBindings.SourceGen" />
</ItemGroup>
Then in your code:
var state = new Wacs.WASI.Preview1.State { /* ... */ };
var imports = new MyTranspiledApp.WacsGenerated.GeneratedHostImports(state)
{
MemoryProvider = () => GetWasmMemoryView(), // wire to your runtime
};
var module = new MyTranspiledApp.Module(imports);
module._start();
wacs aot wires the package reference + memory provider for you; the
manual setup above is for embedders who construct the host process by hand.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.