Skip to content

Commit

Permalink
Add generic support for staging helix payloads
Browse files Browse the repository at this point in the history
For a directory specified as a helix correlation payload, the helix
tasks will attempt to write a `.payload` file to the directory. But if the
directory is not writable then we need to stage the payload in a
writable location, before passing the path to helix.

For example, if we have `wasi-sdk` installed on the system as:
    `WASI_SDK_PATH=/usr/local/wasi-sdk`

.. then we can stage it by copying to
`artifacts/obj/helix-staging/wasi-sdk`, and then using that staging path
for the helix correlation payload.

This was already being done for `EMSDK`, and `WasiSdk` in two separate
targets. And now needs to be done for `wasmtime` also. Instead of having
completely separate targets for all this, add a new mechanism to specify
helix dependencies to stage.

For example:
```xml
  <ItemGroup>
    <HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)"   Include="$(WasmtimeDirForHelixPayload)" />
  </ItemGroup>
```

.. and the payload can use specified as
```xml
<HelixCorrelationPayload Include="$(WasmtimeDirForHelixPayload)" Destination="wasmtime" Condition="'$(NeedsWasmtime)' == 'true'" />
```
  • Loading branch information
radical committed Mar 2, 2023
1 parent d11aaed commit 2deb22a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 45 deletions.
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
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>

0 comments on commit 2deb22a

Please sign in to comment.