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

[wasi] CI: Provision wasi-sdk, and wasmtime only when needed #82454

Merged
merged 4 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@
<CoreCLRToolPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'coreclr', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfiguration)'))</CoreCLRToolPath>
<ILAsmToolPath Condition="'$(DotNetBuildFromSource)' == 'true' or '$(BuildArchitecture)' == 's390x' or '$(BuildArchitecture)' == 'ppc64le'">$(CoreCLRToolPath)</ILAsmToolPath>

<WasmtimeDir>$([MSBuild]::NormalizeDirectory($(ArtifactsObjDir), 'wasmtime'))</WasmtimeDir>
<WasmtimeDir Condition="'$(WasmtimeDir)' == '' and '$(WASMTIME_PATH)' != '' and Exists($(WASMTIME_PATH))">$(WASMTIME_PATH)</WasmtimeDir>
<WasmtimeDir Condition="'$(WasmtimeDir)' == ''">$([MSBuild]::NormalizeDirectory($(ArtifactsObjDir), 'wasmtime'))</WasmtimeDir>
<InstallWasmtimeForTests Condition="'$(InstallWasmtimeForTests)' == '' and !Exists($(WasmtimeDir))">true</InstallWasmtimeForTests>
</PropertyGroup>

<PropertyGroup Label="CalculateOS">
Expand Down
6 changes: 3 additions & 3 deletions eng/pipelines/common/global-build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ jobs:
inputs:
PathtoPublish: '$(Build.SourcesDirectory)/artifacts/log/'
PublishLocation: Container
${{ if ne(parameters.osGroup, 'browser') }}:
${{ if notin(parameters.osGroup, 'browser', 'wasi') }}:
ArtifactName: Logs_Build_${{ parameters.osGroup }}_${{ parameters.osSubGroup }}_${{ parameters.archType }}_${{ parameters.buildConfig }}_${{ parameters.nameSuffix }}
${{ if eq(parameters.osGroup, 'browser') }}:
ArtifactName: Logs_Build_browser_wasm_${{ parameters.hostedOs }}_${{ parameters.buildConfig }}_${{ parameters.nameSuffix }}
${{ if in(parameters.osGroup, 'browser', 'wasi') }}:
ArtifactName: Logs_Build_${{ parameters.osGroup }}_${{ parameters.archType }}_${{ parameters.hostedOs }}_${{ parameters.buildConfig }}_${{ parameters.nameSuffix }}
continueOnError: true
condition: always()
12 changes: 9 additions & 3 deletions eng/testing/wasi-provisioning.targets
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<Project>
<PropertyGroup>
<_WasmtimeVersionFile>$(MonoProjectRoot)wasi/wasmtime-version.txt</_WasmtimeVersionFile>
<InstallWasmtimeForTests Condition="'$(InstallWasmtimeForTests)' == '' and '$(TargetOS)' == 'wasi'">true</InstallWasmtimeForTests>
<_WasmtimeStampPath>$(WasmtimeDir)\.stamp-wasmtime-version.txt</_WasmtimeStampPath>
<InstallWasmtimeForTests Condition="'$(InstallWasmtimeForTests)' == '' and !Exists($(WasmtimeDir))">true</InstallWasmtimeForTests>
</PropertyGroup>

<!-- FIXMEWASI: prevent multiple downloads -->
<Target Name="ProvisionWasmtime" AfterTargets="Build" Condition="'$(InstallWasmtimeForTests)' == 'true'" Inputs="$(_WasmtimeVersionFile)" Outputs="$(WasmtimeDir).stamp-wasmtime-version.txt">
<Target Name="ProvisionWasmtime"
AfterTargets="Build"
Condition="'$(InstallWasmtimeForTests)' == 'true' and !Exists($(WasmtimeDir))"
Inputs="$(_WasmtimeVersionFile)"
Outputs="$(_WasmtimeStampPath)">

<ReadLinesFromFile File="$(_WasmtimeVersionFile)">
<Output TaskParameter="Lines" ItemName="_VersionLines" />
</ReadLinesFromFile>
Expand All @@ -24,6 +30,6 @@
<MakeDir Directories="$(WasmtimeDir)" />
<Exec Command="powershell -command &quot;Expand-Archive $(_DownloadedFile) . ; Move-Item wasmtime-v$(WasmtimeVersion)-x86_64-windows/*.* . &quot;" WorkingDirectory="$(WasmtimeDir)" Condition="'$(HostOS)' == 'windows'"/>
<Exec Command="tar -Jx --strip-components=1 -f $(_DownloadedFile)" WorkingDirectory="$(WasmtimeDir)" Condition="'$(HostOS)' != 'windows'"/>
<Copy SourceFiles="$(MonoProjectRoot)wasi/wasmtime-version.txt" DestinationFiles="$(WasmtimeDir).stamp-wasmtime-version.txt" SkipUnchangedFiles="true" />
<Copy SourceFiles="$(MonoProjectRoot)wasi/wasmtime-version.txt" DestinationFiles="$(_WasmtimeStampPath)" SkipUnchangedFiles="true" />
</Target>
</Project>
46 changes: 22 additions & 24 deletions src/libraries/sendtohelix-wasi.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

- Useful properties to condition on: $(Scenario), $(IsRunningLibraryTests)
- And add to, change, or remove from @(HelixWorkItem)

** Staging system directories before use as helix payloads **

Helix tries to write a `.payload` file to the payload directory, but if that is
not writable then it needs to be staged first. For example:

<HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)" Include="$(WasmtimeDirForHelixPayload)" />

Then the payload can use specified as:

<HelixCorrelationPayload Include="$(WasmtimeDirForHelixPayload)" Destination="wasmtime" Condition="'$(NeedsWasmtime)' == 'true'" />
-->

<PropertyGroup>
Expand All @@ -29,11 +40,13 @@
_AddWorkItemsForBuildWasmApps
</PrepareForBuildHelixWorkItems_WasiDependsOn>

<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);StageWasiSdkForHelix;PrepareForBuildHelixWorkItems_Wasi</BuildHelixWorkItemsDependsOn>
<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);PrepareForBuildHelixWorkItems_Wasi</BuildHelixWorkItemsDependsOn>
<IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload>
<EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems>

<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == ''">$(RepoRoot)src\mono\wasi\wasi-sdk\</WASI_SDK_PATH>
<WasiSdkForHelixPayload>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasi', 'wasi-sdk'))</WasiSdkForHelixPayload>
<WasiSdkDirForHelixPayload>$(HelixDependenciesStagingPath)\wasi-sdk</WasiSdkDirForHelixPayload>
<WasmtimeDirForHelixPayload>$(HelixDependenciesStagingPath)\wasmtime</WasmtimeDirForHelixPayload>

<NeedsWorkload Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsWorkload>
<NeedsWasiSdk Condition="'$(NeedsToBuildWasmAppsOnHelix)' == 'true' or '$(Scenario)' == 'BuildWasmApps'">true</NeedsWasiSdk>
Expand All @@ -46,6 +59,11 @@
<SdkForWorkloadTestingDirName Condition="'$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' != 'true'">dotnet-none</SdkForWorkloadTestingDirName>
</PropertyGroup>

<ItemGroup>
<HelixDependenciesToStage Condition="'$(NeedsWasiSdk)' == 'true'" SourcePath="$(WASI_SDK_PATH)" Include="$(WasiSdkDirForHelixPayload)" />
<HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)" Include="$(WasmtimeDirForHelixPayload)" />
</ItemGroup>

<ItemGroup Condition="'$(WindowsShell)' != 'true'">
<HelixPreCommand Condition="'$(Scenario)' != ''" Include="export SCENARIO=$(Scenario)" />
<HelixPreCommand Include="export XHARNESS_DISABLE_COLORED_OUTPUT=true" />
Expand Down Expand Up @@ -95,13 +113,11 @@

<Target Name="PrepareHelixCorrelationPayload_Wasi">
<Error Text="Cannot find %24(WasmtimeDir)=$(WasmtimeDir)" Condition="'$(WasmtimeDir)' == '' or !Exists($(WasmtimeDir))" />
<Message Condition="'$(NeedsWasiSdk)' == 'true'" Importance="High" Text="Using wasi-sdk: $(WasiSdkForHelixPayload)" />

<ItemGroup>
<HelixCorrelationPayload Include="$(WasmtimeDir)" Destination="wasmtime" Condition="'$(NeedsWasmtime)' == 'true'" />
<HelixCorrelationPayload Include="$(WasmtimeDirForHelixPayload)" Destination="wasmtime" Condition="'$(NeedsWasmtime)' == 'true'" />

<HelixCorrelationPayload Include="$(_ShippingPackagesPath)" Destination="built-nugets" Condition="'$(NeedsBuiltNugets)' == 'true'" />
<HelixCorrelationPayload Include="$(WasiSdkForHelixPayload)" Destination="build/wasi-sdk" Condition="'$(NeedsWasiSdk)' == 'true'" />
<HelixCorrelationPayload Include="$(WasiSdkDirForHelixPayload)" Destination="build/wasi-sdk" Condition="'$(NeedsWasiSdk)' == 'true'" />
</ItemGroup>
</Target>

Expand Down Expand Up @@ -167,22 +183,4 @@
</HelixWorkItem>
</ItemGroup>
</Target>

<!-- CI has wasi-sdk provisioned in $(WASK_SDK_PATH) as `/usr/local/wasi-sdk`. Because helix tasks will
attempt to write a .payload file, we cannot use $(WASI_SDK_PATH) to package wasi-sdk as a helix correlation
payload. Instead, we copy over the files to a new directory `src/mono/wasi/wasi-sdk` and use that. -->
<Target Name="StageWasiSdkForHelix" Condition="'$(NeedsWasiSdk)' == 'true' and !Exists($(WasiSdkForHelixPayload))">
<Error Condition="'$(WASI_SDK_PATH)' == '' or !Exists($(WASI_SDK_PATH))"
Text="Could not find wasi sdk in WASI_SDK_PATH=$(WASI_SDK_PATH), needed to provision for running tests on helix" />

<MakeDir Directories="$(WasiSdkForHelixPayload)" />

<ItemGroup>
<_WasiSdkFiles Include="$(WASI_SDK_PATH)\**\*" Exclude="$(WASI_SDK_PATH)\.git\**\*" />
</ItemGroup>

<Copy SourceFiles="@(_WasiSdkFiles)"
DestinationFiles="@(_WasiSdkFiles -> '$(WasiSdkForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>
</Project>
42 changes: 22 additions & 20 deletions src/libraries/sendtohelix-wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

- Useful properties to condition on: $(Scenario), $(IsRunningLibraryTests)
- And add to, change, or remove from @(HelixWorkItem)

** Staging system directories before use as helix payloads **

Helix tries to write a `.payload` file to the payload directory, but if that is
not writable then it needs to be staged first. For example:

<HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)" Include="$(WasmtimeDirForHelixPayload)" />

Then the payload can use specified as:

<HelixCorrelationPayload Include="$(WasmtimeDirForHelixPayload)" Destination="wasmtime" Condition="'$(NeedsWasmtime)' == 'true'" />
-->

<PropertyGroup>
Expand All @@ -35,13 +46,13 @@
_AddWorkItemsForBuildWasmApps
</PrepareForBuildHelixWorkItems_WasmDependsOn>

<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);StageEmSdkForHelix;PrepareForBuildHelixWorkItems_Wasm</BuildHelixWorkItemsDependsOn>
<BuildHelixWorkItemsDependsOn>$(BuildHelixWorkItemsDependsOn);PrepareForBuildHelixWorkItems_Wasm</BuildHelixWorkItemsDependsOn>
<IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload>
<EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems>

<!-- on unix CI has emscripten provisioned in $(EMSDK_PATH) as `/usr/local/emscripten`. -->
<EMSDK_PATH Condition="$([MSBuild]::IsOSPlatform('WINDOWS')) and '$(EMSDK_PATH)' == ''">$(RepoRoot)src\mono\wasm\emsdk\</EMSDK_PATH>
<EmSdkDirForHelixPayload>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasm', 'emsdk'))</EmSdkDirForHelixPayload>
<EmSdkDirForHelixPayload>$(HelixDependenciesStagingPath)\emsdk</EmSdkDirForHelixPayload>
<DebuggerHost Condition="'$(DebuggerHost)' == ''">chrome</DebuggerHost>

<NeedsWorkload Condition="'$(Scenario)' == 'BuildWasmApps'">true</NeedsWorkload>
Expand Down Expand Up @@ -70,6 +81,15 @@
<_HelixLocalNodePath Condition="'$(NeedsEMSDK)' == 'true' and '$(WindowsShell)' == 'true'">%HELIX_CORRELATION_PAYLOAD%\build\emsdk\node</_HelixLocalNodePath>
</PropertyGroup>

<ItemGroup>
<HelixDependenciesToStage
pavelsavara marked this conversation as resolved.
Show resolved Hide resolved
Name="emsdk"
Include="$(EmSdkDirForHelixPayload)"
Condition="'$(NeedsEMSDK)' == 'true' or '$(IncludeNodePayload)' == 'true'"
SourcePath="$(EMSDK_PATH)"
/>
</ItemGroup>

<ItemGroup Condition="'$(WindowsShell)' != 'true'">
<HelixPreCommand Condition="'$(Scenario)' != ''" Include="export SCENARIO=$(Scenario)" />
<HelixPreCommand Condition="'$(Scenario)' != 'WasmTestOnBrowser'" Include="export XHARNESS_COMMAND=test" />
Expand Down Expand Up @@ -274,22 +294,4 @@
</HelixWorkItem>
</ItemGroup>
</Target>

<!-- CI has emscripten provisioned in $(EMSDK_PATH) as `/usr/local/emscripten`. Because helix tasks will
attempt to write a .payload file, we cannot use $(EMSDK_PATH) to package emsdk as a helix correlation
payload. Instead, we copy over the files to a new directory `src/mono/wasm/emsdk` and use that. -->
<Target Name="StageEmSdkForHelix" Condition="('$(NeedsEMSDK)' == 'true' or '$(IncludeNodePayload)' == 'true') and !Exists($(EmSdkDirForHelixPayload))">
<Error Condition="'$(EMSDK_PATH)' == '' or !Exists($(EMSDK_PATH))"
Text="Could not find emscripten sdk in EMSDK_PATH=$(EMSDK_PATH), needed to provision for running tests on helix" />

<MakeDir Directories="$(EmSdkDirForHelixPayload)" />

<ItemGroup>
<_EmSdkFiles Include="$(EMSDK_PATH)\**\*" Exclude="$(EMSDK_PATH)\.git\**\*" />
</ItemGroup>

<Copy SourceFiles="@(_EmSdkFiles)"
DestinationFiles="@(_EmSdkFiles -> '$(EmSdkDirForHelixPayload)\%(RecursiveDir)%(FileName)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>
</Project>
37 changes: 36 additions & 1 deletion src/libraries/sendtohelixhelp.proj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@

<HelixConfiguration>$(Configuration)</HelixConfiguration>
<HelixArchitecture>$(TargetArchitecture)</HelixArchitecture>
<BuildHelixWorkItemsDependsOn>BuildHelixCommand</BuildHelixWorkItemsDependsOn>
<BuildHelixWorkItemsDependsOn>BuildHelixCommand;StageDependenciesForHelix</BuildHelixWorkItemsDependsOn>
<EnableDefaultBuildHelixWorkItems>true</EnableDefaultBuildHelixWorkItems>
<HelixDependenciesStagingPath>$([MSBuild]::NormalizeDirectory($(ArtifactsObjDir), 'helix-staging'))</HelixDependenciesStagingPath>
</PropertyGroup>

<Import Project="$(MSBuildThisFileDirectory)sendtohelix-wasi.targets" Condition="'$(TargetOS)' == 'wasi'" />
Expand Down Expand Up @@ -104,6 +105,11 @@
<TestEnvFileName Condition=" '$(Scenario)' != '' and '$(TargetOS)' != 'windows' and '$(TargetOS)' != 'browser' and '$(TargetOS)' != 'wasi'">SetStressModes_$(Scenario).sh</TestEnvFileName>
</PropertyGroup>

<ItemGroup>
<__HelixDependenciesToStageThatDontExist Include="@(HelixDependenciesToStage)" />
<__HelixDependenciesToStageThatDontExist Remove="@(HelixDependenciesToStage->Exists())" />
</ItemGroup>

<!-- HelixPreCommands is a set of commands run before the work item command. We use it here to inject
setting up the per-scenario environment.
-->
Expand Down Expand Up @@ -298,4 +304,33 @@
<Target Name="PrintBuildTargetFramework">
<Message Importance="High" Text="Build TargetFramework: $(BuildTargetFramework)" />
</Target>

<!--
Helix tasks will attempt to write a .payload file to the payload directory. But if the
directory is not writable, for example when it is a system installed dependency like
`WASI_SDK_PATH=/usr/local/wasi-sdk`
.. then we need to stage that before passing the path to helix like under `artifacts/obj/helix-staging`
-->
<Target Name="StageDependenciesForHelix" Condition="@(__HelixDependenciesToStageThatDontExist->Count()) > 0">
<Error Condition="'%(__HelixDependenciesToStageThatDontExist.SourcePath)' == '' or !Exists(%(__HelixDependenciesToStageThatDontExist.SourcePath))"
Text="Could not find %(__HelixDependenciesToStageThatDontExist.Name) at %(__HelixDependenciesToStageThatDontExist.SourcePath), needed to provision for running tests on helix" />

<ItemGroup>
<__HelixDependenciesToStageThatDontExist Name="%(FileName)" />
</ItemGroup>

<Message Importance="High" Text="Using %(__HelixDependenciesToStageThatDontExist.Name): %(__HelixDependenciesToStageThatDontExist.SourcePath)" />
<MakeDir Directories="%(__HelixDependenciesToStageThatDontExist.Identity)" />

<ItemGroup>
<_FilesToStage Remove="@(_FilesToStage)" />
<_FilesToStage Include="%(__HelixDependenciesToStageThatDontExist.SourcePath)\**\*"
Exclude="%(__HelixDependenciesToStageThatDontExist.SourcePath)\.git\**\*"
DirName="@(__HelixDependenciesToStageThatDontExist->'%(Name)')" />
</ItemGroup>

<Copy SourceFiles="@(_FilesToStage)"
DestinationFiles="@(_FilesToStage -> '$(HelixDependenciesStagingPath)\%(DirName)\%(RecursiveDir)%(FileName)%(Extension)')"
SkipUnchangedFiles="true" />
</Target>
</Project>
1 change: 0 additions & 1 deletion src/mono/sample/wasi/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<Import Project="$(MonoProjectRoot)\wasi\build\WasiApp.InTree.targets" />

<PropertyGroup>
<InstallWasmtimeForTests>true</InstallWasmtimeForTests>
<_SampleProject Condition="'$(_SampleProject)' == ''">$(MSBuildProjectFile)</_SampleProject>
<_SampleAssembly Condition="'$(_SampleAssembly)' == ''">$(TargetFileName)</_SampleAssembly>
<_ExeExt Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">.exe</_ExeExt>
Expand Down
1 change: 0 additions & 1 deletion src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<!-- these are imported in this project instead -->
<SkipWorkloadsTestingTargetsImport>false</SkipWorkloadsTestingTargetsImport>
<InstallWorkloadForTesting>true</InstallWorkloadForTesting>
<InstallWasmtimeForTests>true</InstallWasmtimeForTests>

<!-- don't run any wasm build steps -->
<IsBrowserWasmProject>false</IsBrowserWasmProject>
Expand Down