From fac28db475da2341336af2485e3079ef8adedd5c Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Wed, 19 Jun 2024 21:28:18 -0700 Subject: [PATCH] Add docs on how to reference package Signed-off-by: James Sturtevant --- README.md | 11 +++++++++ .../SimpleProducerConsumerTest.cs | 7 ++++++ .../WasmComponentSdkTest.csproj | 1 + .../AppWithWitFolder/AppWithWitFolder.csproj | 24 +++++++++++++++++++ .../testapps/AppWithWitFolder/program.cs | 1 + .../testapps/AppWithWitFolder/wit/imports.wit | 5 ++++ .../testapps/AppWithWitFolder/wit/world.wit | 5 ++++ 7 files changed, 54 insertions(+) create mode 100644 test/WasmComponentSdkTest/testapps/AppWithWitFolder/AppWithWitFolder.csproj create mode 100644 test/WasmComponentSdkTest/testapps/AppWithWitFolder/program.cs create mode 100644 test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/imports.wit create mode 100644 test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/world.wit diff --git a/README.md b/README.md index 990d042..ff7fb58 100644 --- a/README.md +++ b/README.md @@ -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 + + + + +``` + ### 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 `` in your _host_ `.csproj` file (that is, the application that's _importing_ the interface): diff --git a/test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs b/test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs index fecdd40..e52c153 100644 --- a/test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs +++ b/test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs @@ -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() { diff --git a/test/WasmComponentSdkTest/WasmComponentSdkTest/WasmComponentSdkTest.csproj b/test/WasmComponentSdkTest/WasmComponentSdkTest/WasmComponentSdkTest.csproj index 9f7bff0..bf6eba0 100644 --- a/test/WasmComponentSdkTest/WasmComponentSdkTest/WasmComponentSdkTest.csproj +++ b/test/WasmComponentSdkTest/WasmComponentSdkTest/WasmComponentSdkTest.csproj @@ -28,6 +28,7 @@ + diff --git a/test/WasmComponentSdkTest/testapps/AppWithWitFolder/AppWithWitFolder.csproj b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/AppWithWitFolder.csproj new file mode 100644 index 0000000..7962b9c --- /dev/null +++ b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/AppWithWitFolder.csproj @@ -0,0 +1,24 @@ + + + + + + + Exe + net8.0 + enable + enable + + true + wasi-wasm + + + + + + + + + + + diff --git a/test/WasmComponentSdkTest/testapps/AppWithWitFolder/program.cs b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/program.cs new file mode 100644 index 0000000..d0b58d6 --- /dev/null +++ b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/program.cs @@ -0,0 +1 @@ +ImportstestWorld.wit.imports.test.pkg.v0_2_0.FolderInterop.Folder(); diff --git a/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/imports.wit b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/imports.wit new file mode 100644 index 0000000..9f2e0ff --- /dev/null +++ b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/imports.wit @@ -0,0 +1,5 @@ +interface folder { folder: func();} + +world imports { + import folder; +} diff --git a/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/world.wit b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/world.wit new file mode 100644 index 0000000..1a89340 --- /dev/null +++ b/test/WasmComponentSdkTest/testapps/AppWithWitFolder/wit/world.wit @@ -0,0 +1,5 @@ +package test:pkg@0.2.0; + +world importstest { + include imports; +}