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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ world root {

This component can be used anywhere that WASI 0.2 components can be used. For example, use `wasm-tools compose` as illustrated above.

### Referencing Wit Packages

By default the project will find all wit files and execute wit-bindgen against each one. This is makes it easy to get started with a single wit file. If you have more complicated wit files, then you can create wit packages. To use folder with all the wit in it you can add the following to your `.csproj`.

```xml
<ItemGroup>
<Wit Remove="**\*.wit" />
<Wit Include="wit-folder" World="wit-world" />
</ItemGroup>
```

### WIT strings and memory

The calculator example above works easily because it doesn't need to allocate memory dynamically. Once you start working with strings, you must add an extra line to the `<PropertyGroup>` in your _host_ `.csproj` file (that is, the application that's _importing_ the interface):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ public void CanBuildComponentWithExport()
Assert.Contains("export test:producer-consumer/operations", witInfo);
}

[Fact]
public void CanBuildComponentWithWitPackage()
{
var witInfo = GetWitInfo(FindModulePath($"../testapps/AppWithWitFolder/bin/{Config}", "appwithwitfolder-component.wasm"));
Assert.Contains("import test:pkg/folder", witInfo);
}

[Fact]
public void CanComposeImportWithExport()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\testapps\SimpleConsumer\SimpleConsumer.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\testapps\AppWithWitFolder\AppWithWitFolder.csproj" ReferenceOutputAssembly="false"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- Only needed when referencing the dependencies as projects. For package references, these are imported automatically. -->
<Import Project="..\..\..\..\src\WasmComponent.Sdk\ImportInDev.proj" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
</PropertyGroup>

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

<ItemGroup>
<Wit Remove="**\*.wit" />
<Wit Include="wit" World="importstest" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ImportstestWorld.wit.imports.test.pkg.v0_2_0.FolderInterop.Folder();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
interface folder { folder: func();}

world imports {
import folder;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package test:pkg@0.2.0;

world importstest {
include imports;
}