Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
run: |
ls ./artifacts/*.nupkg
version=$(unzip -p ./artifacts/*SDK*.nupkg '*.nuspec' | grep -oE "<version>[^<]+" | sed 's/<version>//' | 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")
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)";
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ artifacts/
test/WasmComponentSdkTest/testapps/OciWit/wit/*.wasm
*.binlog
.DS_Store
templates/content/wasi-cli/wasi-cli.csproj
src/WasmComponent.Sdk/sdk/Version.props
36 changes: 36 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,40 @@
<WasmtimeVersion>30.0.2</WasmtimeVersion>

</PropertyGroup>

<UsingTask TaskName="ReplaceFileText" TaskFactory="RoslynCodeTaskFactory" AssemblyFile="$(MSBuildBinPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<InputFilename ParameterType="System.String" Required="true" />
<OutputFilename ParameterType="System.String" Required="true" />
<MatchExpression ParameterType="System.String" Required="true" />
<ReplacementText ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.IO" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs">
<![CDATA[
if (File.Exists(InputFilename))
{
string result = File.ReadAllText(InputFilename);
var matches = MatchExpression.Split('|');
var replacements = ReplacementText.Split('|');

for (int i = 0; i < matches.Length; i++)
{
result = Regex.Replace(result, matches[i], replacements[i]);
}

File.WriteAllText(
OutputFilename,
"<!--\n This code was generated by a tool.\n\n Changes to this file may cause incorrect behavior and will be lost if\n the code is regenerated.\n-->\n\n" +
result
);
}
]]>
</Code>
</Task>
</UsingTask>

</Project>
4 changes: 0 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<!-- find latest versions at https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-experimental by name of package -->
<PackageVersion Include="Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-alpha.1.25162.1" />
<PackageVersion Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-alpha.1.25162.1" />

<!-- Tests -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.12.0,)" />
<PackageVersion Include="xunit" Version="[2.9.0,)" />
Expand Down
56 changes: 24 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,41 +256,21 @@ If you get a build error along the lines of _failed to encode a component from m
* `dotnet new console -o MyApp`
* `cd MyApp`

Create a `nuget.config` file and add the `dotnet-experimental` package source for the `NativeAOT-LLVM` dependency:
Edit the `.csproj` file:

* `dotnet new nugetconfig`
* Add these keys to `nuget.config` after `<clear />`:
1. Add the following line under `<Project>`:

```xml
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
```

Add the `componentize-dotnet` package:

`dotnet add package BytecodeAlliance.Componentize.DotNet.Wasm.SDK --prerelease`

Add the platform specific LLVM package:

```
## On Linux
dotnet add package runtime.linux-x64.microsoft.dotnet.ilcompiler.llvm --prerelease
```xml
<Project Sdk="BytecodeAlliance.Componentize.DotNet.WitBindgen" Version="[LatestVersion]" />
```
2. Add the following inside the `<PropertyGroup>`:

## or

## On Windows
dotnet add package runtime.win-x64.microsoft.dotnet.ilcompiler.llvm --prerelease
```

Edit the `.csproj` file, adding the following inside the `<PropertyGroup>`:

```
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<UseAppHost>false</UseAppHost>
<PublishTrimmed>true</PublishTrimmed>
<InvariantGlobalization>true</InvariantGlobalization>
<SelfContained>true</SelfContained>
```
```xml
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<InvariantGlobalization>true</InvariantGlobalization>
<SelfContained>true</SelfContained>
```

Now you can `dotnet build` to produce a `.wasm` file using NativeAOT compilation.

Expand All @@ -314,6 +294,18 @@ Caused by:

Some imports automatically imported since they are so common. In this case you should tell the runtime to implement those imports. For instance for the error above, in wasmtime you might add `-S cli` to the `wasmtime serve` command like `wasmtime serve -S cli` to include the `wasi:cli/environment@0.2.0` in wasmtime runtime host implementation.

## SDK configuration
You can configure the SDK by setting properties in your project file. The following are supported:

| Property Name | Description | Default |
|---------------|-------------|---------|
| `WasiSdkVersion` | Version of the WASI SDK to use.<br />Be aware that not all versions of the WASI SDK are compatible with NativeAOT-LLVM. A warning will appear if you select an incompatible version for NativeAOT-LLVM.<br /><br />⚠️ When changing this value, or the NativeAOT-LLVM version, check the build output for a warning! | `24.0` |
| `NativeAotLlvmVersion` | Version of the NativeAOT-LLVM package to use.<br />Find latest versions in the [dotnet-experimental feed](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-experimental/NuGet/Microsoft.DotNet.ILCompiler.LLVM/versions). | `10.0.0-alpha.1.25162.1` |
| `WitBindgenVersion` | Version of the `BytecodeAlliance.Componentize.DotNet.WitBindgen` package to use. | Current SDK version |
| `RegisterExperimentalNuGetSource` | Whether to register the [dotnet-experimental feed](https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-experimental/NuGet) to find the NativeAOT-LLVM package. Set this to `false` if you have a NuGet.config that already includes this feed. | `true` |
| `WitBindgenAddtionalArgs` | Additional arguments to pass to `wit-bindgen` when generating C# bindings. Separate multiple arguments with spaces. For example: `--with-wit-results --features tls`. | (empty) |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a typo in property item WitBindgenAddtionalArgs:

<Exec Command="$(WitBindgenExe) c-sharp %(Wit.Identity) %(Wit.WitWorldArg) --runtime $(WitBindgenRuntime) $(WitBindgenAddtionalArgs) --out-dir $(WitGeneratedFilesRoot)" />

Shouldn't this be WitBindgenAdditionalArgs?

| `WitGeneratedFilesRoot` | Folder (relative to the project root) where generated WIT files will be placed. | (empty) |

## Credits

This project was original developed and forked from https://github.com/SteveSandersonMS/wasm-component-sdk under the Apache 2.0 License with a LLVM exception.
Expand Down
10 changes: 0 additions & 10 deletions nuget.config

This file was deleted.

1 change: 0 additions & 1 deletion samples/calculator/Adder/Adder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\WasmComponent.Sdk\WasmComponent.Sdk.csproj" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<ItemGroup>
<ProjectReference Include="..\Adder\Adder.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\CalculatorHost\CalculatorHost.csproj" ReferenceOutputAssembly="false" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

<Target Name="ComposeWasmComponent" AfterTargets="Publish">
Expand Down
1 change: 0 additions & 1 deletion samples/calculator/CalculatorHost/CalculatorHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\WasmComponent.Sdk\WasmComponent.Sdk.csproj" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/WasmComponent.Sdk/ImportInDev.proj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@
<Import Project="build/*.targets" />

<Import Project="../WitBindgen/ImportInDev.proj" />

<ItemGroup>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/WasmComponent.Sdk/Version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project>
<PropertyGroup>
<WitBindgenVersion Condition="'$(WitBindgenVersion)' == ''">$version$</WitBindgenVersion>
</PropertyGroup>
</Project>
13 changes: 8 additions & 5 deletions src/WasmComponent.Sdk/WasmComponent.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
<TarPath Condition="'$(TarPath)' == ''">tar</TarPath>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\WitBindgen\WitBindgen.csproj" PrivateAssets="None" />
</ItemGroup>

<ItemGroup>
<None Include="../../Readme.md" Pack="true" PackagePath="\"/>
</ItemGroup>
Expand Down Expand Up @@ -106,8 +102,15 @@
</Target>

<Target Name="PackTaskDependencies" BeforeTargets="GenerateNuspec">
<!--
Copy Version.xml to sdk\Version.props and replace $version$ with the current NuGet version
We need this to reference the current 'BytecodeAlliance.Componentize.DotNet.WitBindgen' in the SDK project
-->
<ReplaceFileText InputFilename="Version.xml" OutputFilename="sdk\Version.props" MatchExpression="\$version\$" ReplacementText="$(PackageVersion)" />

<ItemGroup>
<_PackageFiles Include="build\**" BuildAction="Content" PackagePath="build" />
<_PackageFiles Include="sdk\**" BuildAction="Content" PackagePath="Sdk" />
<_PackageFiles Include="build\**" BuildAction="Content" PackagePath="Sdk" />
<_PackageFiles Include="tools\**" BuildAction="Content" PackagePath="tools" />
</ItemGroup>
</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

<WacExe>$(MSBuildThisFileDirectory)..\tools\$(ToolsTarget)\wac</WacExe>
<WacExe Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WacExe).exe</WacExe>

<!-- find latest versions at https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-experimental by name of package -->
<NativeAotLlvmVersion Condition="'$(NativeAotLlvmVersion)' == ''">10.0.0-alpha.1.25162.1</NativeAotLlvmVersion>
<RegisterExperimentalNuGetSource Condition="'$(RegisterExperimentalNuGetSource)' == ''">true</RegisterExperimentalNuGetSource>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" PrivateAssets="None" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
<Project>
<PropertyGroup Condition="'$(RegisterExperimentalNuGetSource)' == 'true'">
<RestoreAdditionalProjectSources>$(RestoreAdditionalProjectSources);https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json;</RestoreAdditionalProjectSources>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" IsImplicitlyDefined="true" Version="$(NativeAotLlvmVersion)" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).microsoft.dotnet.ilcompiler.llvm" IsImplicitlyDefined="true" Version="$(NativeAotLlvmVersion)" />
</ItemGroup>

<!--
This links the publish step with the build so that when a user runs `dotnet build` they get a wasm file.
-->
Expand Down
4 changes: 4 additions & 0 deletions src/WasmComponent.Sdk/sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project>
<Import Project="Version.props" />
<Import Project="BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" />
</Project>
7 changes: 7 additions & 0 deletions src/WasmComponent.Sdk/sdk/Sdk.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>
<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.WitBindgen" IsImplicitlyDefined="true" Version="$(WitBindgenVersion)" />
</ItemGroup>

<Import Project="BytecodeAlliance.Componentize.DotNet.Wasm.SDK.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<PropertyGroup>
<WitBindgenRuntime>native-aot</WitBindgenRuntime>

Expand All @@ -8,7 +9,6 @@
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Linux'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-linux.tar.gz</WasiSdkUrl>
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('OSX'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-macos.tar.gz</WasiSdkUrl>
<WasiSdkRoot>$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".wasi-sdk", "wasi-sdk-$(WasiSdkVersion)"))</WasiSdkRoot>

</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@
<None Include="../README.md" Pack="true" PackagePath="" />
</ItemGroup>

<Target Name="ReplaceVersion" BeforeTargets="BeforeBuild">
<!-- Copy wasi-cli.xml to content/wasi-cli/wasi-cli.csproj and replace $version$ with the current NuGet version -->
<ReplaceFileText InputFilename="wasi-cli.xml" OutputFilename="content\wasi-cli\wasi-cli.csproj" MatchExpression="\$version\$" ReplacementText="$(PackageVersion)" />
</Target>

</Project>
7 changes: 0 additions & 7 deletions templates/content/wasi-cli/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
"language": "C#",
"type": "project"
},
"symbols": {
"platform": {
"type": "bind",
"binding": "env:OS",
"defaultValue": "linux"
}
},
"postActions": [
{
"description": "Welcome to Componetize dotnet",
Expand Down
9 changes: 0 additions & 9 deletions templates/content/wasi-cli/nuget.config

This file was deleted.

21 changes: 0 additions & 21 deletions templates/content/wasi-cli/wasi-cli.csproj

This file was deleted.

14 changes: 14 additions & 0 deletions templates/wasi-cli.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$version$" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<RootNamespace>wasi_cli</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
</PropertyGroup>

</Project>
1 change: 0 additions & 1 deletion test/E2ETest/PackageTest/PackageTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

<!-- To ensure we don't build this until we've built the underlying packages -->
<ProjectReference Include="..\..\..\src\WasmComponent.Sdk\WasmComponent.Sdk.csproj" ReferenceOutputAssembly="false" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

<!-- The next targets (+ nuget.config in folder above) ensures we have the latest nuget packages for the e2e test since there is no great way to force a project to use a particular nuget pacakage -->
Expand Down
4 changes: 2 additions & 2 deletions test/E2ETest/testapps/E2EConsumer/E2EConsumer.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- This project can't be included in the solution because its package reference can't be satisfied except when running under test -->
<!-- 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>
Expand All @@ -19,7 +20,6 @@

<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-alpha.1.25118.1"/>

<!-- Just to ensure build order -->
<ProjectReference Include="..\E2EProducer\E2EProducer.csproj" ReferenceOutputAssembly="false" />
Expand Down
4 changes: 2 additions & 2 deletions test/E2ETest/testapps/E2EProducer/E2EProducer.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<!-- This project can't be included in the solution because its package reference can't be satisfied except when running under test -->
<!-- Only needed when referencing the dependencies as projects. For package references, these are imported automatically. -->
<Import Project="..\..\..\..\src\WasmComponent.Sdk\ImportInDev.proj" />

<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
Expand All @@ -17,7 +18,6 @@

<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="10.0.0-alpha.1.25118.1"/>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
<ProjectReference Include="..\testapps\SimpleConsumer\SimpleConsumer.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\testapps\AppWithWitFolder\AppWithWitFolder.csproj" ReferenceOutputAssembly="false"/>
<ProjectReference Include="..\testapps\OciWit\OciWit.csproj" ReferenceOutputAssembly="false"/>
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM"/>
</ItemGroup>

</Project>
Loading
Loading