diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6e235f6..97ddf3a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -39,12 +39,15 @@ jobs: run: | ls ./artifacts/*.nupkg version=$(unzip -p ./artifacts/*SDK*.nupkg '*.nuspec' | grep -oE "[^<]+" | sed 's///' | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+-preview") - template_version=$(grep -oE "Version=\"[^\"]+" ./templates/content/wasi-cli/wasi-cli.csproj | sed 's/Version="//' | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+-preview") - echo "Package Version: $version | Template version: $template_version" - if [ "$version" != "$template_version" ]; then - echo "Version mismatch: Package version ($version) does not match template version ($template_version)"; - exit 1; - fi + for dir in ./templates/content/*/; do + template=$(basename $dir) + template_version=$(grep -oE "Version=\"[^\"]+" $dir$template.csproj | sed 's/Version="//' | grep -oE "^[0-9]+\.[0-9]+\.[0-9]+-preview") + echo "Package Version: $version | Template $template version: $template_version" + if [ "$version" != "$template_version" ]; then + echo "Version mismatch: Package version ($version) does not match template $template version ($template_version)"; + exit 1; + fi + done - name: Test Template shell: bash run: | @@ -57,6 +60,12 @@ jobs: dotnet nuget add source $artifact_dir dotnet build dotnet list package + cd .. + dotnet new componentize.wasi.lib -o TestLib + cd TestLib + dotnet nuget add source $artifact_dir + dotnet build + dotnet list package popd # must use windows to generate package https://github.com/bytecodealliance/componentize-dotnet/issues/41 # only need one package published https://github.com/actions/upload-artifact?tab=readme-ov-file#not-uploading-to-the-same-artifact diff --git a/README.md b/README.md index 41b543c..a9ba725 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,17 @@ Hello world from compontize-dotnet! (if needed, replace `MyApp` with the actual name of your project) +### Library components + +If you want to build a library component that exports functionality via WIT instead of a command line application, use the library template: + +```bash +dotnet new componentize.wasi.lib -o MyLib +dotnet build MyLib +``` + +The generated project contains a `component.wit` file with an exported interface and a corresponding implementation class. See [Creating a WASI 0.2 component, including WIT support](#creating-a-wasi-02-component-including-wit-support) below for how to customize it. + ## Creating a WASI 0.2 component, including WIT support Lastest version of NativeAOT compiler package and the mono support in dotnet 9-preview 7 build native wasi 0.2 components with no additional tools. diff --git a/RELEASE.md b/RELEASE.md index 7f3250e..4f503ec 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -3,7 +3,7 @@ 1. Update all the tool versions in [Directory.Build.Props](./Directory.Build.props) 1. Open a PR to update: - the `` tag in [Directory.Build.Props](./Directory.Build.props) - - the `BytecodeAlliance.Componentize.DotNet.Wasm.SDK` package `version` to match the `` in the [template](./templates/content/wasi-cli/wasi-cli.csproj). For example the template version might look like `Version="0.6.0-preview*"`. This ensures the templates use the latest package. + - the `BytecodeAlliance.Componentize.DotNet.Wasm.SDK` package `version` to match the `` in each template under [templates/content](./templates/content/) ([wasi-cli](./templates/content/wasi-cli/wasi-cli.csproj) and [wasi-lib](./templates/content/wasi-lib/wasi-lib.csproj)). For example the template version might look like `Version="0.6.0-preview*"`. This ensures the templates use the latest package. 1. Maintainers approve and merge PR 1. After the PR merges a maintainer triggers the Release workflow on the main branch via the github Actions UI or runs: diff --git a/templates/content/wasi-cli/.template.config/template.json b/templates/content/wasi-cli/.template.config/template.json index 18386a5..9599cba 100644 --- a/templates/content/wasi-cli/.template.config/template.json +++ b/templates/content/wasi-cli/.template.config/template.json @@ -23,7 +23,7 @@ }, "postActions": [ { - "description": "Welcome to Componetize dotnet", + "description": "Welcome to Componentize dotnet", "manualInstructions": [ { "text": "To get started run `dotnet build` inside your new project. Learn more at https://github.com/bytecodealliance/componentize-dotnet." diff --git a/templates/content/wasi-lib/.template.config/template.json b/templates/content/wasi-lib/.template.config/template.json new file mode 100644 index 0000000..5dbaf14 --- /dev/null +++ b/templates/content/wasi-lib/.template.config/template.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "Bytecode Alliance Developers", + "classifications": [ + "wasi", + "wasm", + "Library" + ], + "identity": "BytecodeAlliance.Componentize.DotNet.Templates.Library", + "name": "Componentize-dotnet wasi library template", + "shortName": "componentize.wasi.lib", + "sourceName": "wasi-lib", + "tags": { + "language": "C#", + "type": "project" + }, + "symbols": { + "platform": { + "type": "bind", + "binding": "env:OS", + "defaultValue": "linux" + } + }, + "postActions": [ + { + "description": "Welcome to Componentize dotnet", + "manualInstructions": [ + { + "text": "To get started run `dotnet build` inside your new project. Learn more at https://github.com/bytecodealliance/componentize-dotnet." + } + ], + "actionId": "AC1156F7-BB77-4DB8-B28F-24EEBCCA1E5C", + "continueOnError": true + } + ] +} diff --git a/templates/content/wasi-lib/OperationsImpl.cs b/templates/content/wasi-lib/OperationsImpl.cs new file mode 100644 index 0000000..52e91d6 --- /dev/null +++ b/templates/content/wasi-lib/OperationsImpl.cs @@ -0,0 +1,9 @@ +namespace LibraryWorld.wit.exports.example.component; + +public class OperationsImpl : IOperations +{ + public static int Add(int left, int right) + { + return left + right; + } +} diff --git a/templates/content/wasi-lib/component.wit b/templates/content/wasi-lib/component.wit new file mode 100644 index 0000000..ff75a6b --- /dev/null +++ b/templates/content/wasi-lib/component.wit @@ -0,0 +1,9 @@ +package example:component; + +interface operations { + add: func(left: s32, right: s32) -> s32; +} + +world library { + export operations; +} diff --git a/templates/content/wasi-lib/nuget.config b/templates/content/wasi-lib/nuget.config new file mode 100644 index 0000000..caa4ee8 --- /dev/null +++ b/templates/content/wasi-lib/nuget.config @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/templates/content/wasi-lib/wasi-lib.csproj b/templates/content/wasi-lib/wasi-lib.csproj new file mode 100644 index 0000000..6dfb8cd --- /dev/null +++ b/templates/content/wasi-lib/wasi-lib.csproj @@ -0,0 +1,26 @@ + + + + Library + net10.0 + wasi_lib + enable + enable + wasi-wasm + false + true + true + true + + + + + + + + + + + + +