Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 'Sdk="BytecodeAlliance.Componentize.DotNet.Wasm.SDK/[^"]+' ./templates/content/wasi-cli/wasi-cli.csproj | sed 's/Sdk="BytecodeAlliance.Componentize.DotNet.Wasm.SDK\///' | 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
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,22 @@ Create a `nuget.config` file and add the `dotnet-experimental` package source fo
<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

## 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>
```
Edit the `.csproj` file:

1. Change the SDK to `BytecodeAlliance.Componentize.DotNet.Wasm.SDK/[VERSION]`, for example:

```xml
<Project Sdk="BytecodeAlliance.Componentize.DotNet.WitBindgen.0.7.0-preview00014">
```
2. Add the following inside the `<PropertyGroup>`:

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

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

Expand Down
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>
7 changes: 7 additions & 0 deletions src/WasmComponent.Sdk/Version.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Project>

<PropertyGroup>
<WasmComponentSdkVersion>$version$</WasmComponentSdkVersion>
</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,13 @@

<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>
</PropertyGroup>

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

Choose a reason for hiding this comment

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

IsImplicitlyDefined is needed because of:

<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

Otherwise, it is complaining that the version is not managed by PackageVersion.

</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions src/WasmComponent.Sdk/sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="Version.props" />
<Import Project="BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" />

<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.WitBindgen" IsImplicitlyDefined="true" Version="$(WasmComponentSdkVersion)" />
</ItemGroup>
</Project>
4 changes: 4 additions & 0 deletions src/WasmComponent.Sdk/sdk/Sdk.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Project>
<Import Project="BytecodeAlliance.Componentize.DotNet.Wasm.SDK.targets" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
</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
21 changes: 0 additions & 21 deletions templates/content/wasi-cli/wasi-cli.csproj

This file was deleted.

12 changes: 12 additions & 0 deletions templates/wasi-cli.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="BytecodeAlliance.Componentize.DotNet.Wasm.SDK/$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>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

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

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion test/WasmComponentSdkTest/testapps/OciWit/OciWit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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 @@ -16,7 +16,6 @@

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

<!-- Just to ensure build order -->
<ProjectReference Include="..\SimpleProducer\SimpleProducer.csproj" ReferenceOutputAssembly="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 @@ -10,7 +10,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\WitBindgen\WitBindgen.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 @@ -11,7 +11,6 @@

<ItemGroup>
<ProjectReference Include="..\..\..\..\src\WitBindgen\WitBindgen.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 @@ -10,7 +10,6 @@

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

<ItemGroup>
Expand Down
Loading
Loading