Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to enable the build on Linux #40

Merged
merged 12 commits into from
Sep 6, 2024
Merged
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
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ on:

jobs:
build:
runs-on: windows-latest
name: Build with Dotnet ${{ matrix.dotnet }}
runs-on: ${{ matrix.os }}
name: Build on ${{ matrix.os }} with Dotnet ${{ matrix.dotnet }}
strategy:
matrix:
dotnet: [ '8.x', '9.0.100-preview.4.24267.66']
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
- name: Setup .NET
Expand All @@ -26,7 +27,7 @@ jobs:
- name: Restore dependencies
run: dotnet restore
- name: Prepare WASM SDKs
run: dotnet msbuild src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets /t:PrepareWasmSdks
run: dotnet msbuild src/WitBindgen/build/ByteCodeAlliance.Componentize.DotNet.WitBindgen.targets /t:PrepareWasmSdks
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
- name: Build
run: dotnet build --no-restore /p:BuildNumber=${{ github.run_number }}
- name: Test
Expand All @@ -36,7 +37,8 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: nuget-packages
name: nuget-packages-${{ matrix.os }}
path: artifacts/*.nupkg
if-no-files-found: error
if: ${{ matrix.dotnet == '8.x' }} # only need one package published https://github.com/actions/upload-artifact?tab=readme-ov-file#not-uploading-to-the-same-artifact

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ obj/
.vs/
artifacts/
test/WasmComponentSdkTest/testapps/OciWit/wit
*.binlog
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Requires [.NET 8+](https://dotnet.microsoft.com/en-us/download)

```
## needed to avoid errors with multiple projects calling and downloading the sdks at same time (https://github.com/bytecodealliance/componentize-dotnet/issues/8)
dotnet msbuild src/WitBindgen/build/BytecodeAlliance.Componentize.DotNet.WitBindgen.targets /t:PrepareWasmSdks
dotnet msbuild src/WitBindgen/build/ByteCodeAlliance.Componentize.DotNet.WitBindgen.targets /t:PrepareWasmSdks
dotnet build
```

Expand Down
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
</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="9.0.0-rc.1.24412.1" />
<PackageVersion Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24412.1" />
<PackageVersion Include="Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24429.1" />
<PackageVersion Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" Version="9.0.0-rc.1.24429.1" />

<!-- Tests -->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
Expand Down
3 changes: 3 additions & 0 deletions samples/calculator/Adder/Adder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>

<!-- Need kebab case -->
<TargetName>adder</TargetName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<Target Name="ComposeWasmComponent" AfterTargets="AfterBuild">
<PropertyGroup>
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/calculatorhost.wasm</EntrypointComponent>
<EntrypointComponent>../CalculatorHost/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/CalculatorHost.wasm</EntrypointComponent>
<DependencyComponent>../Adder/bin/$(Configuration)/$(TargetFramework)/wasi-wasm/native/adder.wasm</DependencyComponent>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/WasmComponent.Sdk/ImportInDev.proj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" />
</ItemGroup>
</Project>
7 changes: 4 additions & 3 deletions src/WasmComponent.Sdk/WasmComponent.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="build\BytecodeAlliance.Componentize.DotNet.Wasm.SDK.props" />
<Import Project="build\ByteCodeAlliance.Componentize.DotNet.Wasm.SDK.props" />

<PropertyGroup>
<PackageId>BytecodeAlliance.Componentize.DotNet.Wasm.SDK</PackageId>
Expand Down Expand Up @@ -32,7 +32,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.ILCompiler.LLVM" PrivateAssets="None" />
<PackageReference Include="runtime.win-x64.Microsoft.DotNet.ILCompiler.LLVM" PrivateAssets="None" />
<PackageReference Include="runtime.$(NETCoreSdkPortableRuntimeIdentifier).Microsoft.DotNet.ILCompiler.LLVM" PrivateAssets="None" />
<ProjectReference Include="..\WitBindgen\WitBindgen.csproj" PrivateAssets="None" />
</ItemGroup>

Expand Down Expand Up @@ -67,7 +67,8 @@
<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" />
<PrebuiltWasmToolsTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" />
<!-- tar on non-Windows often cannot handle zip archives -->
<PrebuiltWasmToolsTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" Condition="$([MSBuild]::IsOSPlatform('Windows'))" />
</ItemGroup>
Copy link
Contributor

Choose a reason for hiding this comment

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

This will have the result that, if built and published on Linux, there wouldn't be an .exe in the resulting nuget package.

Copy link
Contributor

Choose a reason for hiding this comment

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

we could either document that it must publish on Windows and/or open an issue to make it more robust?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, added #41 and referenced in the code.

<ItemGroup>
<PrebuiltWasmToolsOutputs Include="tools\%(PrebuiltWasmToolsTarget.Rid)\wasm-tools%(PrebuiltWasmToolsTarget.ExeExt)" />
Expand Down
6 changes: 4 additions & 2 deletions src/WitBindgen/WitBindgen.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="build\BytecodeAlliance.Componentize.DotNet.WitBindgen.props" />
<Import Project="build\ByteCodeAlliance.Componentize.DotNet.WitBindgen.props" />

<PropertyGroup>
<PackageId>BytecodeAlliance.Componentize.DotNet.WitBindgen</PackageId>
Expand Down Expand Up @@ -62,7 +62,8 @@
<PrebuiltToolTarget Include="aarch64-macos" Rid="osx-arm64" Ext=".tar.gz" wkg="aarch64-apple-darwin"/>
<PrebuiltToolTarget Include="x86_64-linux" Rid="linux-x64" Ext=".tar.gz" wkg="x86_64-unknown-linux-gnu"/>
<PrebuiltToolTarget Include="x86_64-macos" Rid="osx-x64" Ext=".tar.gz" wkg="x86_64-apple-darwin"/>
<PrebuiltToolTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" wkg="x86_64-pc-windows-gnu" />
<!-- tar on non-Windows often cannot handle zip archives -->
<PrebuiltToolTarget Include="x86_64-windows" Rid="win-x64" Ext=".zip" ExeExt=".exe" wkg="x86_64-pc-windows-gnu" Condition="$([MSBuild]::IsOSPlatform('Windows'))"/>
</ItemGroup>
<ItemGroup>
<PrebuiltWitBindgenOutputs Include="tools\%(PrebuiltToolTarget.Rid)\wit-bindgen%(PrebuiltToolTarget.ExeExt)" />
Expand All @@ -79,6 +80,7 @@
<RemoveDir Directories="tools\temp" />

<DownloadFile SourceUrl="$(PrebuildWkgBaseUrl)-%(PrebuiltToolTarget.wkg)" DestinationFolder="tools\%(PrebuiltToolTarget.Rid)" DestinationFileName="wkg%(PrebuiltToolTarget.ExeExt)" />
<Exec Command="chmod +x &quot;tools/%(PrebuiltToolTarget.Rid)/wkg%(PrebuiltToolTarget.ExeExt)&quot;" Condition="$([MSBuild]::IsOSPlatform('Linux'))" />
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
<WriteLinesToFile File="$(CurrentWkgVersion)" Lines="$(PrebuildWkgVersion)" Overwrite="true" WriteOnlyWhenDifferent="true" />
</Target>

Expand Down
2 changes: 1 addition & 1 deletion test/E2ETest/PackageTest/PackageTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<RemoveDir Directories="..\testapps\E2EProducer\obj" />
<RemoveDir Directories="..\testapps\E2EConsumer\obj" />
<Exec Command="dotnet restore --no-cache" WorkingDirectory="..\testapps\E2EConsumer" />
<Exec Command="dotnet build --no-restore" WorkingDirectory="..\testapps\E2EConsumer" />
<Exec Command="dotnet build --no-restore /bl" WorkingDirectory="..\testapps\E2EConsumer" />
</Target>

<Target Name="PackPackagesForE2ETest">
Expand Down
3 changes: 2 additions & 1 deletion test/E2ETest/testapps/E2EConsumer/E2EConsumer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<UseAppHost>false</UseAppHost>
<PublishTrimmed>true</PublishTrimmed>
<TargetName>e2econsumer</TargetName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />
<PackageReference Include="ByteCodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />

<!-- Just to ensure build order -->
<ProjectReference Include="..\E2EProducer\E2EProducer.csproj" ReferenceOutputAssembly="false" />
Expand Down
3 changes: 2 additions & 1 deletion test/E2ETest/testapps/E2EProducer/E2EProducer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<PublishTrimmed>true</PublishTrimmed>
<TargetName>e2eproducer</TargetName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />
<PackageReference Include="ByteCodeAlliance.Componentize.DotNet.Wasm.SDK" Version="$(PackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions test/E2ETest/testapps/nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,4 @@
<packageSources>
<add key="dev" value="..\PackageTest\packages" />
</packageSources>
<packageSourceMapping>
<packageSource key="dev">
<package pattern="BytecodeAlliance.Componentize.DotNet.WitBindgen" />
<package pattern="BytecodeAlliance.Componentize.DotNet.Wasm.SDK" />
</packageSource>
</packageSourceMapping>
jsturtevant marked this conversation as resolved.
Show resolved Hide resolved
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ private static string FindModulePath(string searchDir, string filename)
}

var matches = Directory.GetFiles(resolvedSearchDir, filename, SearchOption.AllDirectories);
if (matches.Count() != 1)
{
throw new Exception($"Failed to get modules path, matched {matches.Count()} entries for directory {resolvedSearchDir} and filename {filename}.");
}

return Path.GetFullPath(matches.Single());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<TargetName>appwithwitfolder</TargetName>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions test/WasmComponentSdkTest/testapps/OciWit/OciWit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<TargetName>ociwit</TargetName>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<TargetName>simpleconsumer</TargetName>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,7 +32,7 @@
</PropertyGroup>

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

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

<InvariantGlobalization>true</InvariantGlobalization>
<RuntimeIdentifier>wasi-wasm</RuntimeIdentifier>
<!-- Kebab case probably better -->
<TargetName>simpleproducer</TargetName>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion test/WasmtimeCliFetcher/FetchWasmtime.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- This is a marker file that lets the build scripts identity if the files need to be modified when updating versions -->
<CurrentWasmtimeVersion>$(MSBuildThisFileDirectory)tools\version-$(WasmtimeVersion)</CurrentWasmtimeVersion>

<WasmtimeUrlExtension>.tar.gz</WasmtimeUrlExtension>
<WasmtimeUrlExtension>.tar.xz</WasmtimeUrlExtension>
<WasmtimeUrlExtension Condition="$([MSBuild]::IsOSPlatform('Windows'))">.zip</WasmtimeUrlExtension>
<WasmtimeUrl>https://github.com/bytecodealliance/wasmtime/releases/download/v$(WasmtimeVersion)/wasmtime-v$(WasmtimeVersion)-$(WasmtimeTarget)$(WasmtimeUrlExtension)</WasmtimeUrl>
</PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion test/WitBindgenTest/WitBindgenTest/CodeGenerationTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using MyFuncsWorld;
using ProducerWorld;
using System;
using Xunit;

namespace WitBindgenTest;
Expand All @@ -14,7 +15,8 @@ public void GeneratesSimpleImport()
LibraryUsingWit.Code.CallSimpleDoSomething());

// Currently, it generates [DllImport("*", ...)] so validate that
Assert.StartsWith("Unable to load DLL", ex.Message);
var expectedErrorMessagePrefix = "Unable to load " + (OperatingSystem.IsWindows() ? "DLL" : "shared library");
Assert.StartsWith(expectedErrorMessagePrefix, ex.Message);
}

[Fact]
Expand Down