Skip to content

Commit 4b44f68

Browse files
authored
Merge pull request #24 from jsturtevant/folder-support
Add docs on how to reference package
2 parents f33ea43 + fac28db commit 4b44f68

7 files changed

Lines changed: 54 additions & 0 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,17 @@ world root {
175175

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

178+
### Referencing Wit Packages
179+
180+
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`.
181+
182+
```xml
183+
<ItemGroup>
184+
<Wit Remove="**\*.wit" />
185+
<Wit Include="wit-folder" World="wit-world" />
186+
</ItemGroup>
187+
```
188+
178189
### WIT strings and memory
179190

180191
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):

test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public void CanBuildComponentWithExport()
3030
Assert.Contains("export test:producer-consumer/operations", witInfo);
3131
}
3232

33+
[Fact]
34+
public void CanBuildComponentWithWitPackage()
35+
{
36+
var witInfo = GetWitInfo(FindModulePath($"../testapps/AppWithWitFolder/bin/{Config}", "appwithwitfolder-component.wasm"));
37+
Assert.Contains("import test:pkg/folder", witInfo);
38+
}
39+
3340
[Fact]
3441
public void CanComposeImportWithExport()
3542
{

test/WasmComponentSdkTest/WasmComponentSdkTest/WasmComponentSdkTest.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
<ItemGroup>
3030
<ProjectReference Include="..\testapps\SimpleConsumer\SimpleConsumer.csproj" ReferenceOutputAssembly="false" />
31+
<ProjectReference Include="..\testapps\AppWithWitFolder\AppWithWitFolder.csproj" ReferenceOutputAssembly="false"/>
3132
</ItemGroup>
3233

3334
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<!-- Only needed when referencing the dependencies as projects. For package references, these are imported automatically. -->
4+
<Import Project="..\..\..\..\src\WasmComponent.Sdk\ImportInDev.proj" />
5+
6+
<PropertyGroup>
7+
<OutputType>Exe</OutputType>
8+
<TargetFramework>net8.0</TargetFramework>
9+
<ImplicitUsings>enable</ImplicitUsings>
10+
<Nullable>enable</Nullable>
11+
12+
<InvariantGlobalization>true</InvariantGlobalization>
13+
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<ProjectReference Include="..\..\..\..\src\WasmComponent.Sdk\WasmComponent.Sdk.csproj" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<Wit Remove="**\*.wit" />
22+
<Wit Include="wit" World="importstest" />
23+
</ItemGroup>
24+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ImportstestWorld.wit.imports.test.pkg.v0_2_0.FolderInterop.Folder();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
interface folder { folder: func();}
2+
3+
world imports {
4+
import folder;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package test:pkg@0.2.0;
2+
3+
world importstest {
4+
include imports;
5+
}

0 commit comments

Comments
 (0)