Skip to content

Commit

Permalink
Merge pull request #61 from jsturtevant/use-wac
Browse files Browse the repository at this point in the history
Use Wac for composition
  • Loading branch information
jsturtevant authored Dec 2, 2024
2 parents 54c40c8 + 79b405c commit a70fddf
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 28 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ world root {

## Composing components

Once you have a components containing the Adder and Calculator host, you can use [wasm-tools](https://github.com/bytecodealliance/wasm-tools) to compose a runnable application:
Once you have a components containing the Adder and Calculator host, you can use [wac](https://github.com/bytecodealliance/wac) to compose a runnable application:

```bash
wasm-tools compose -o composed.wasm MyApp.wasm -d AddImplementation.wasm
wac plug MyApp.wasm --plug AddImplementation.wasm -o composed.wasm
```

then run it:
Expand All @@ -191,7 +191,7 @@ then run it:
wasmtime composed.wasm
```

While you can run wasm-tools manually, you can also generate this automatically. One way to do this is to [create a new project](./samples/calculator/CalculatorComposed/) and add the following:
While you can run wac manually, you can also generate this automatically. One way to do this is to [create a new project](./samples/calculator/CalculatorComposed/) and add the following:

```xml
<Target Name="ComposeWasmComponent" AfterTargets="Publish">
Expand All @@ -201,7 +201,7 @@ While you can run wasm-tools manually, you can also generate this automatically.
</PropertyGroup>

<MakeDir Directories="dist" />
<Exec Command="$(WasmToolsExe) compose -o dist/calculator.wasm $(EntrypointComponent) -d $(DependencyComponent)" />
<Exec Command="$(WacExe) plug $(EntrypointComponent) --plug $(DependencyComponent)" -o dist/calculator.wasm />
</Target>
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</PropertyGroup>

<MakeDir Directories="dist" />
<Exec Command="$(WasmToolsExe) compose -o dist/calculator.wasm $(EntrypointComponent) -d $(DependencyComponent)" />
<Exec Command="$(WacExe) plug $(EntrypointComponent) --plug $(DependencyComponent) -o dist/calculator.wasm" />
</Target>

</Project>
54 changes: 38 additions & 16 deletions src/WasmComponent.Sdk/WasmComponent.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
<!-- Things you might want to edit -->
<!-- Set BuildWasmToolsLocally to true if you want to build modules/wasm-tools locally and use its output -->
<BuildWasmToolsLocally>false</BuildWasmToolsLocally>
<PrebuiltWasmToolsVersion>1.219.1</PrebuiltWasmToolsVersion>
<PrebuiltWasmToolsBaseUrl>https://github.com/bytecodealliance/wasm-tools/releases/download/v$(PrebuiltWasmToolsVersion)/wasm-tools-$(PrebuiltWasmToolsVersion)</PrebuiltWasmToolsBaseUrl>
<WasmtimeVersionForWasiSnapshotPreview1Adapters>21.0.1</WasmtimeVersionForWasiSnapshotPreview1Adapters>

<WasmToolsModuleRoot>$(MSBuildThisFileDirectory)..\..\modules\wasm-tools\</WasmToolsModuleRoot>

<WasmToolsVersion>1.220.0</WasmToolsVersion>
<PrebuiltWasmToolsBaseUrl>https://github.com/bytecodealliance/wasm-tools/releases/download/v$(WasmToolsVersion)/wasm-tools-$(WasmToolsVersion)</PrebuiltWasmToolsBaseUrl>

<WacVersion>v0.6.1</WacVersion>
<WacBaseUrl>https://github.com/bytecodealliance/wac/releases/download/$(WacVersion)/wac-cli</WacBaseUrl>

<!-- Don't pack any assemblies in lib/*/.dll.-->
<NoPackageAnalysis>true</NoPackageAnalysis>
<IncludeBuildOutput>false</IncludeBuildOutput>
Expand Down Expand Up @@ -56,28 +58,48 @@
<Copy SourceFiles="$(WasmToolsModuleRoot)target\release\$(WasmToolsExeName)" DestinationFolder="tools\$(WasmToolsTarget)\" />
</Target>

<Target Name="DownloadNativeTooling" Condition="'$(BuildWasmToolsLocally)' != 'true'" DependsOnTargets="GetDownloadNativeToolingDependencies; DownloadNativeToolingCore">
<Target Name="DownloadNativeTooling" Condition="'$(BuildWasmToolsLocally)' != 'true'" DependsOnTargets="GetWasmToolsDependencies; DownloadWasmTools; GetWacDependencies; DownloadWac">
</Target>

<Target Name="GetDownloadNativeToolingDependencies">
<Target Name="GetWasmToolsDependencies">
<ItemGroup>
<PrebuiltWasmToolsTarget Include="aarch64-linux" Rid="linux-arm64" Ext=".tar.gz" />
<PrebuiltWasmToolsTarget Include="aarch64-macos" Rid="osx-arm64" Ext=".tar.gz" />
<PrebuiltWasmToolsTarget Include="x86_64-linux" Rid="linux-x64" Ext=".tar.gz" />
<PrebuiltWasmToolsTarget Include="x86_64-macos" Rid="osx-x64" Ext=".tar.gz" />
<WasmToolsTarget Include="aarch64-linux" Rid="linux-arm64" Ext=".tar.gz" />
<WasmToolsTarget Include="aarch64-macos" Rid="osx-arm64" Ext=".tar.gz" />
<WasmToolsTarget Include="x86_64-linux" Rid="linux-x64" Ext=".tar.gz" />
<WasmToolsTarget Include="x86_64-macos" Rid="osx-x64" Ext=".tar.gz" />
<!-- tar on non-Windows often cannot handle zip archives. Until we have a solution, we canonly publish the packages from the Windows build.
See https://github.com/bytecodealliance/componentize-dotnet/issues/41 -->
<PrebuiltWasmToolsTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
<WasmToolsTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>
<ItemGroup>
<PrebuiltWasmToolsOutputs Include="tools\%(PrebuiltWasmToolsTarget.Rid)\wasm-tools%(PrebuiltWasmToolsTarget.ExeExt)" />
<PrebuiltWasmToolsOutputs Include="tools\%(WasmToolsTarget.Rid)\wasm-tools%(WasmToolsTarget.ExeExt)" />
</ItemGroup>
</Target>

<Target Name="DownloadNativeToolingCore" Inputs="@(PrebuiltWasmToolsOutputs)" Outputs="@(PrebuiltWasmToolsOutputs)">
<DownloadFile SourceUrl="$(PrebuiltWasmToolsBaseUrl)-%(PrebuiltWasmToolsTarget.Identity)%(PrebuiltWasmToolsTarget.Ext)" DestinationFolder="tools\temp" DestinationFileName="%(PrebuiltWasmToolsTarget.Rid)%(PrebuiltWasmToolsTarget.Ext)" />
<MakeDir Directories="tools\%(PrebuiltWasmToolsTarget.Rid)" />
<Exec Command="tar -xf &quot;temp/%(PrebuiltWasmToolsTarget.Rid)%(PrebuiltWasmToolsTarget.Ext)&quot; -C %(PrebuiltWasmToolsTarget.Rid) --strip-components=1" WorkingDirectory="tools" />
<Target Name="GetWacDependencies">
<ItemGroup>
<WacTarget Include="aarch64-unknown-linux-musl" Rid="linux-arm64"/>
<WacTarget Include="aarch64-apple-darwin" Rid="osx-arm64"/>
<WacTarget Include="x86_64-unknown-linux-musl" Rid="linux-x64"/>
<WacTarget Include="x86_64-apple-darwin" Rid="osx-x64"/>
<WacTarget Include="x86_64-pc-windows-gnu" Rid="win-x64" ExeExt=".exe"/>
</ItemGroup>
<ItemGroup>
<WacOutputs Include="tools\%(WacTarget.Rid)\wac%(WacTarget.ExeExt)" />
</ItemGroup>
</Target>

<Target Name="DownloadWac" Inputs="@(WacOutputs)" Outputs="@(WacOutputs)">
<MakeDir Directories="tools\%(WacOutputs.Rid)" />
<DownloadFile SourceUrl="$(WacBaseUrl)-%(WacTarget.Identity)" DestinationFolder="tools\%(WacTarget.Rid)" DestinationFileName="wac%(WacTarget.ExeExt)" />
<!-- this makes CI pass but doesn't really make it work from Linux since package is build on Windows-->
<Exec Command="chmod +x tools/%(WacTarget.Rid)/wac" Condition="$([MSBuild]::IsOSPlatform('Linux')) And '%(WacTarget.ExeExt)' == ''"/>
</Target>

<Target Name="DownloadWasmTools" Inputs="@(PrebuiltWasmToolsOutputs)" Outputs="@(PrebuiltWasmToolsOutputs)">
<DownloadFile SourceUrl="$(PrebuiltWasmToolsBaseUrl)-%(WasmToolsTarget.Identity)%(WasmToolsTarget.Ext)" DestinationFolder="tools\temp" DestinationFileName="%(WasmToolsTarget.Rid)%(WasmToolsTarget.Ext)" />
<MakeDir Directories="tools\%(WasmToolsTarget.Rid)" />
<Exec Command="tar -xf &quot;temp/%(WasmToolsTarget.Rid)%(WasmToolsTarget.Ext)&quot; -C %(WasmToolsTarget.Rid) --strip-components=1" WorkingDirectory="tools" />
<RemoveDir Directories="tools\temp" />
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
<InvariantGlobalization>true</InvariantGlobalization>
<SelfContained>true</SelfContained>

<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</WasmToolsTarget>
<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</WasmToolsTarget>
<WasmToolsTarget Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</WasmToolsTarget>
<WasmToolsTarget>$(WasmToolsTarget)-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())</WasmToolsTarget>
<WasmToolsExe>$(MSBuildThisFileDirectory)..\tools\$(WasmToolsTarget)\wasm-tools</WasmToolsExe>
<ToolsTarget Condition="$([MSBuild]::IsOSPlatform('Windows'))">win</ToolsTarget>
<ToolsTarget Condition="$([MSBuild]::IsOSPlatform('Linux'))">linux</ToolsTarget>
<ToolsTarget Condition="$([MSBuild]::IsOSPlatform('OSX'))">osx</ToolsTarget>
<ToolsTarget>$(ToolsTarget)-$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLower())</ToolsTarget>

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

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

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/E2ETest/testapps/E2EConsumer/E2EConsumer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
</PropertyGroup>

<MakeDir Directories="dist" />
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm $(NativeOutputPath)$(TargetName.ToLower()).wasm -d $(DependencyComponent)" />
<Exec Command="$(WacExe) plug $(NativeOutputPath)$(TargetName.ToLower()).wasm --plug $(DependencyComponent) -o dist/composed.wasm" />
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</PropertyGroup>

<MakeDir Directories="dist" />
<Exec Command="$(WasmToolsExe) compose -o dist/composed.wasm $(NativeOutputPath)$(TargetName).wasm -d $(DependencyComponent)" />
<Exec Command="$(WacExe) plug $(NativeOutputPath)$(TargetName).wasm --plug $(DependencyComponent) -o dist/composed.wasm" />
</Target>

</Project>

0 comments on commit a70fddf

Please sign in to comment.