Skip to content

Commit 6b7be43

Browse files
authored
Merge pull request #35 from jsturtevant/support-wasi-0.2
Support wasi 0.2.0 directly
2 parents cf48a96 + 2e93952 commit 6b7be43

File tree

12 files changed

+36
-84
lines changed

12 files changed

+36
-84
lines changed

Directory.Packages.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
</PropertyGroup>
55
<ItemGroup>
66
<!-- find latest versions at https://dev.azure.com/dnceng/public/_artifacts/feed/dotnet-experimental by name of package -->
7-
<PackageVersion Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-preview.5.24304.1" />
8-
<PackageVersion Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-preview.5.24304.1" />
7+
<PackageVersion Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24412.1" />
8+
<PackageVersion Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24412.1" />
99

1010
<!-- Tests -->
1111
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,6 @@ Another option, if you use Visual Studio, is to select the WIT file in *Solution
101101

102102
You can simply type the world name `hostapp` into the properties pane.
103103

104-
For now, you must also specify the functions you want to import in the `.csproj` file. Add this to the `ItemGroup`:
105-
106-
```xml
107-
<WasmImport Include="example:calculator/operations!add" />
108-
```
109-
110104
Now you can call the imported `Add` function by putting the following in `Program.cs`:
111105

112106
```cs

samples/calculator/CalculatorComposed/CalculatorComposed.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<ProjectReference Include="..\CalculatorHost\CalculatorHost.csproj" ReferenceOutputAssembly="false" />
1616
</ItemGroup>
1717

18-
<Target Name="ComposeWasmComponent" AfterTargets="Build">
18+
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
1919
<PropertyGroup>
20-
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/calculatorhost-component.wasm</EntrypointComponent>
21-
<DependencyComponent>../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder-component.wasm</DependencyComponent>
20+
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/calculatorhost.wasm</EntrypointComponent>
21+
<DependencyComponent>../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder.wasm</DependencyComponent>
2222
</PropertyGroup>
2323

2424
<MakeDir Directories="dist" />

samples/calculator/CalculatorHost/CalculatorHost.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
<ItemGroup>
2222
<Wit Include="..\Adder\calculator.wit" World="hostapp" />
23-
24-
<!-- Ideally this would be unnecessary, either because the MSBuild tooling adds it automatically, -->
25-
<!-- or better still, the generated .cs code should include the full required annotations -->
26-
<WasmImport Include="example:calculator/operations!add" />
27-
<WasmImport Include="example:calculator/operations!to-upper" />
2823
</ItemGroup>
2924

3025
</Project>

src/WasmComponent.Sdk/WasmComponent.Sdk.csproj

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
<None Include="ImportInDev.proj" />
4545
</ItemGroup>
4646

47-
<Target Name="BuildOrDownloadNativeTooling" BeforeTargets="Build" DependsOnTargets="BuildNativeTooling; DownloadNativeTooling; DownloadWasiPreview1Adapters">
47+
<Target Name="BuildOrDownloadNativeTooling" BeforeTargets="Build" DependsOnTargets="BuildNativeTooling; DownloadNativeTooling;">
4848
</Target>
4949

5050
<Target Name="BuildNativeTooling" Condition="'$(BuildWasmToolsLocally)' == 'true'">
@@ -81,12 +81,6 @@
8181
<RemoveDir Directories="tools\temp" />
8282
</Target>
8383

84-
<Target Name="DownloadWasiPreview1Adapters" Inputs="$(MSBuildThisFileDirectory)tools\wasi-wasm\version" Outputs="$(MSBuildThisFileDirectory)tools\wasi-wasm\version" >
85-
<DownloadFile SourceUrl="https://github.com/bytecodealliance/wasmtime/releases/download/v$(WasmtimeVersionForWasiSnapshotPreview1Adapters)/wasi_snapshot_preview1.command.wasm" DestinationFolder="tools\wasi-wasm" />
86-
<DownloadFile SourceUrl="https://github.com/bytecodealliance/wasmtime/releases/download/v$(WasmtimeVersionForWasiSnapshotPreview1Adapters)/wasi_snapshot_preview1.reactor.wasm" DestinationFolder="tools\wasi-wasm" />
87-
<WriteLinesToFile File="$(MSBuildThisFileDirectory)tools\wasi-wasm\version" Lines="$(WasmtimeVersionForWasiSnapshotPreview1Adapters)" Overwrite="true" WriteOnlyWhenDifferent="true" />
88-
</Target>
89-
9084
<Target Name="PackTaskDependencies" BeforeTargets="GenerateNuspec">
9185
<ItemGroup>
9286
<_PackageFiles Include="build\**" BuildAction="Content" PackagePath="build" />
Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
<Project>
2-
<Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm; ConvertToWasmComponent"
2+
<Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm;"
33
Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">
4-
<Message Importance="high" Text="$(ProjectName) -> $([System.IO.Path]::GetFullPath('$(NativeComponentBinary)'))" />
5-
</Target>
6-
7-
<Target Name="ConvertToWasmComponent" DependsOnTargets="GetConvertToWasmComponentDependencies" Inputs="$(WasiPreview1AdapterPath);$(NativeBinary)" Outputs="$(NativeComponentBinary)" >
8-
<Exec Command="$(WasmToolsExe) component new $(NativeBinary) -o $(NativeComponentBinary) --adapt $(WasiPreview1AdapterPath)" />
9-
</Target>
10-
11-
<Target Name="GetConvertToWasmComponentDependencies">
12-
<PropertyGroup>
13-
<WasiPreview1AdapterType>reactor</WasiPreview1AdapterType>
14-
<WasiPreview1AdapterType Condition="'$(OutputType.ToLower())' == 'exe'">command</WasiPreview1AdapterType>
15-
<WasiPreview1AdapterPath>$(MSBuildThisFileDirectory)../tools/wasi-wasm/wasi_snapshot_preview1.$(WasiPreview1AdapterType).wasm</WasiPreview1AdapterPath>
16-
<!--
17-
wasm compose requires kabab case (todo: revisit when move to wac https://github.com/bytecodealliance/componentize-dotnet/issues/5)
18-
https://github.com/bytecodealliance/wasm-tools/issues/1440
19-
-->
20-
<NativeComponentBinary>$(NativeOutputPath)$(TargetName.ToLower())-component.wasm</NativeComponentBinary>
21-
</PropertyGroup>
4+
<Message Importance="high" Text="Emit on build $(ProjectName) " />
225
</Target>
236
</Project>

src/WitBindgen/WitBindgen.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<!-- Things you might want to edit -->
2020
<!-- Set BuildWitBindgenLocally to true if you want to build modules/wit-bindgen locally and use its output -->
2121
<BuildWitBindgenLocally>false</BuildWitBindgenLocally>
22-
<PrebuiltWitBindgenVersion>0.29.0</PrebuiltWitBindgenVersion>
22+
<PrebuiltWitBindgenVersion>0.30.0</PrebuiltWitBindgenVersion>
2323
<PrebuiltWitBindgenBaseUrl>https://github.com/bytecodealliance/wit-bindgen/releases/download/v$(PrebuiltWitBindgenVersion)/wit-bindgen-$(PrebuiltWitBindgenVersion)</PrebuiltWitBindgenBaseUrl>
2424
<WitBindgenModuleRoot>$(MSBuildThisFileDirectory)..\..\modules\wit-bindgen\</WitBindgenModuleRoot>
2525

src/WitBindgen/build/ByteCodeAlliance.Componentize.DotNet.WitBindgen.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<Context>File;BrowseObject</Context>
2727
</PropertyPageSchema>
2828

29-
<Wit Include="**\*.wit" />
29+
<Wit Include="*.wit;wit/*.wit" />
3030

3131
<!-- Treats this itemgroup as a compilation input (e.g., changes affect VS fast up-to-date check, and generator is shown in properties pane) -->
3232
<AvailableItemName Include="Wit" />

src/WitBindgen/build/ByteCodeAlliance.Componentize.DotNet.WitBindgen.targets

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<WitBindgenRuntime>native-aot</WitBindgenRuntime>
44

55
<!-- Keep this block all in sync manually, since URLs can be arbitrary -->
6-
<WasiSdkVersion>22.0</WasiSdkVersion>
7-
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Windows'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion).m-mingw64.tar.gz</WasiSdkUrl>
8-
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Linux'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-linux.tar.gz</WasiSdkUrl>
9-
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('OSX'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-macos.tar.gz</WasiSdkUrl>
6+
<WasiSdkVersion>24.0</WasiSdkVersion>
7+
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Windows'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion.Split(".")[0])/wasi-sdk-$(WasiSdkVersion)-x86_64-windows.tar.gz</WasiSdkUrl>
8+
<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>
9+
<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>
1010
<WasiSdkRoot>$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".wasi-sdk", "wasi-sdk-$(WasiSdkVersion)"))</WasiSdkRoot>
1111

1212
</PropertyGroup>
@@ -17,9 +17,6 @@
1717
-->
1818
<Target Name="PrepareWasmSdks" BeforeTargets="CheckWasmSdks" DependsOnTargets="ObtainWasiSdk">
1919
<PropertyGroup>
20-
<ClangExeName>clang</ClangExeName>
21-
<ClangExeName Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(ClangExeName).exe</ClangExeName>
22-
<Wasicompiler>$(WasiSdkRoot)\bin\$(ClangExeName)</Wasicompiler>
2320
<WASI_SDK_PATH>$(WasiSdkRoot)</WASI_SDK_PATH>
2421
</PropertyGroup>
2522
</Target>
@@ -46,16 +43,15 @@
4643
<!--
4744
Following generats and compiles the wit code for the c# project
4845
-->
49-
<Target Name="WitCompile_BeforeCsCompile" BeforeTargets="BeforeCompile"
46+
<Target Name="WitCompile_BeforeCsCompile" BeforeTargets="LinkNativeLlvm; BeforeCompile; "
5047
Condition="'$(Language)' == 'C#' AND '@(Wit)' != ''"
5148
DependsOnTargets="PrepareWasmSdks; WitCompile_GetDependencies; WitCompile_InvokeTool">
5249
<ItemGroup>
5350
<Compile Include="$(WitGeneratedFilesRoot)**\*.cs" />
54-
<NativeObjects Include="$(WitGeneratedFilesRoot)**\*.o" />
5551
</ItemGroup>
5652
</Target>
5753

58-
<Target Name="PullWitOciFiles" Inputs="@(Wit)" Outputs="@(Wit)" BeforeTargets="WitCompile_GetDependencies">
54+
<Target Name="PullWitOciFiles" Inputs="@(Wit)" Outputs="@(Wit)" BeforeTargets="WitCompile_InvokeTool">
5955
<PropertyGroup>
6056
<WitOciFile>@(Wit)</WitOciFile>
6157
</PropertyGroup>
@@ -64,16 +60,21 @@
6460
<Exec Condition="'%(Wit.Registry)' != ''" Command="$(WkgExe) oci pull %(Wit.Registry) --output $(WitOciFile)" />
6561
</Target>
6662

67-
<Target Name="WitCompile_GetDependencies">
68-
<PropertyGroup>
69-
<WitGeneratedFilesRoot Condition="'$(WitGeneratedFilesRoot)' == ''">$(IntermediateOutputPath)wit_bindgen\</WitGeneratedFilesRoot>
70-
</PropertyGroup>
63+
<Target Name="WitCompile_GetDependencies" DependsOnTargets="WitCompile_InvokeTool">
64+
7165
<ItemGroup>
7266
<WitGeneratedCsFiles Include="$(WitGeneratedFilesRoot)**\*.cs" />
67+
<WitComponentImports Include="$(WitGeneratedFilesRoot)**\*.wit"/>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<CustomLinkerArg Include="@(WitComponentImports->Replace('\', '/')->'-Wl,--component-type,&quot;%(Identity)&quot;')" />
7371
</ItemGroup>
7472
</Target>
7573

7674
<Target Name="WitCompile_InvokeTool" Inputs="@(Wit);$(MSBuildProjectFile)" Outputs="@(WitGeneratedCsFiles);$(WitGeneratedFilesRoot)lastbuild.txt">
75+
<PropertyGroup>
76+
<WitGeneratedFilesRoot Condition="'$(WitGeneratedFilesRoot)' == ''">$(IntermediateOutputPath)wit_bindgen\</WitGeneratedFilesRoot>
77+
</PropertyGroup>
7778
<ItemGroup>
7879
<WitGeneratedCsFiles Remove="@(WitGeneratedCsFiles)" />
7980
<Wit Update="@(Wit)">
@@ -87,13 +88,6 @@
8788
<MakeDir Directories="$(WitGeneratedFilesRoot)" />
8889
<Exec Command="$(WitBindgenExe) c-sharp %(Wit.Identity) %(Wit.WitWorldArg) --runtime $(WitBindgenRuntime) --out-dir $(WitGeneratedFilesRoot)" />
8990
<WriteLinesToFile File="$(WitGeneratedFilesRoot)lastbuild.txt" Lines="" Overwrite="true" />
90-
91-
<!-- Need to compile cabi from c https://github.com/bytecodealliance/wit-bindgen/pull/791-->
92-
<ItemGroup>
93-
<CabiReAllocFiles Include="$(WitGeneratedFilesRoot)**\*World_cabi_realloc.c" />
94-
</ItemGroup>
95-
<Message Importance="high" Text="building cabi_realloc files... @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ') with $(Wasicompiler)" />
96-
<Exec WorkingDirectory="$(WitGeneratedFilesRoot)" Command="&quot;$(Wasicompiler)&quot; @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ') -c"/>
9791

9892
<ItemGroup>
9993
<WitGeneratedCsFiles Include="$(WitGeneratedFilesRoot)**\*.cs" />

test/E2ETest/testapps/E2EConsumer/E2EConsumer.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,16 @@
2424

2525
<ItemGroup>
2626
<Wit Include="..\E2EProducer\producer-consumer.wit" World="consumer" />
27-
28-
<!-- Ideally this would be unnecessary, either because the MSBuild tooling adds it automatically, -->
29-
<!-- or better still, the generated .cs code should include the full required annotations -->
30-
<WasmImport Include="test:producer-consumer/operations!add" />
3127
</ItemGroup>
3228

3329
<!-- After build, create the composed component so it can be executed in the test -->
34-
<Target Name="ComposeWasmComponent" AfterTargets="ConvertToWasmComponent">
30+
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
3531
<PropertyGroup>
36-
<DependencyComponent>../E2EProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/e2eproducer-component.wasm</DependencyComponent>
32+
<DependencyComponent>../E2EProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/e2eproducer.wasm</DependencyComponent>
3733
</PropertyGroup>
3834

3935
<MakeDir Directories="dist" />
40-
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/e2econsumer-component.wasm -d $(DependencyComponent)" />
36+
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm $(NativeOutputPath)$(TargetName.ToLower()).wasm -d $(DependencyComponent)" />
4137
</Target>
4238

4339
</Project>

test/WasmComponentSdkTest/WasmComponentSdkTest/SimpleProducerConsumerTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ public class SimpleProducerConsumerTest
1919
[Fact]
2020
public void CanBuildComponentWithImport()
2121
{
22-
var witInfo = GetWitInfo(FindModulePath($"../testapps/SimpleConsumer/bin/{Config}", "simpleconsumer-component.wasm"));
22+
var witInfo = GetWitInfo(FindModulePath($"../testapps/SimpleConsumer/bin/{Config}", "simpleconsumer.wasm"));
2323
Assert.Contains("import test:producer-consumer/operations", witInfo);
2424
}
2525

2626
[Fact]
2727
public void CanBuildComponentWithExport()
2828
{
29-
var witInfo = GetWitInfo(FindModulePath($"../testapps/SimpleProducer/bin/{Config}", "simpleproducer-component.wasm"));
29+
var witInfo = GetWitInfo(FindModulePath($"../testapps/SimpleProducer/bin/{Config}", "simpleproducer.wasm"));
3030
Assert.Contains("export test:producer-consumer/operations", witInfo);
3131
}
3232

3333
[Fact]
3434
public void CanBuildComponentWithWitPackage()
3535
{
36-
var witInfo = GetWitInfo(FindModulePath($"../testapps/AppWithWitFolder/bin/{Config}", "appwithwitfolder-component.wasm"));
36+
var witInfo = GetWitInfo(FindModulePath($"../testapps/AppWithWitFolder/bin/{Config}", "appwithwitfolder.wasm"));
3737
Assert.Contains("import test:pkg/folder", witInfo);
3838
}
3939

@@ -49,7 +49,7 @@ public void CanComposeImportWithExport()
4949
[Fact]
5050
public void CanBuildAppFromOci()
5151
{
52-
var composed = FindModulePath("../testapps/OciWit", "ociwit-component.wasm");
52+
var composed = FindModulePath("../testapps/OciWit", "ociwit.wasm");
5353
var stdout = ExecuteCommandComponent(composed);
5454
Assert.StartsWith("Oci is awesome!", stdout);
5555
}

test/WasmComponentSdkTest/testapps/SimpleConsumer/SimpleConsumer.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,16 @@
2222

2323
<ItemGroup>
2424
<Wit Include="..\SimpleProducer\producer-consumer.wit" World="consumer" />
25-
26-
<!-- Ideally this would be unnecessary, either because the MSBuild tooling adds it automatically, -->
27-
<!-- or better still, the generated .cs code should include the full required annotations -->
28-
<WasmImport Include="test:producer-consumer/operations!add" />
2925
</ItemGroup>
3026

3127
<!-- After build, create the composed component so it can be executed in the test -->
32-
<Target Name="ComposeWasmComponent" AfterTargets="ConvertToWasmComponent">
28+
<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
3329
<PropertyGroup>
34-
<DependencyComponent>../SimpleProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/simpleproducer-component.wasm</DependencyComponent>
30+
<DependencyComponent>../SimpleProducer/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/simpleproducer.wasm</DependencyComponent>
3531
</PropertyGroup>
3632

3733
<MakeDir Directories="dist" />
38-
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm $(NativeComponentBinary) -d $(DependencyComponent)" />
34+
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm $(NativeOutputPath)$(TargetName.ToLower()).wasm -d $(DependencyComponent)" />
3935
</Target>
4036

4137
</Project>

0 commit comments

Comments
 (0)