Skip to content

Commit 4d8647f

Browse files
Acquire the WASI SDK for runtime build automatically and centrally
1 parent d23d6d3 commit 4d8647f

20 files changed

+142
-132
lines changed

eng/AcquireWasiSdk.targets

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!--
2+
Import these targets to acquire the WASI SDK.
3+
- Use DependsOnTargets="AcquireWasiSdk" on the target that depends on WASI SDK.
4+
- By default, this target is conditioned on $(TargetsWasi).
5+
- You can depend on "AcquireWasiSdkUnconditional" instead if this doesn't work for your project.
6+
- Use $(RuntimeBuildWasiSdkPath) (set by "AcquireWasiSdk") to refer to the SDK root in your target.
7+
-->
8+
<Project>
9+
<PropertyGroup>
10+
<_WasiSdkVersion>25.0</_WasiSdkVersion>
11+
<_RuntimeLocalWasiSdkPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'wasi-sdk'))</_RuntimeLocalWasiSdkPath>
12+
</PropertyGroup>
13+
14+
<!-- If the user wants us to use an explicit SDK, validate it matches our expectations. -->
15+
<Target Name="_ValidateWasiSdk">
16+
<PropertyGroup>
17+
<_ActualWasiSdkVersion Condition="'$(WASI_SDK_PATH)' != '' and Exists('$(WASI_SDK_PATH)/VERSION')">$([System.IO.File]::ReadAllText('$(WASI_SDK_PATH)/VERSION').Split()[0])</_ActualWasiSdkVersion>
18+
<_UseRuntimeLocalWasiSdk Condition="'$(_WasiSdkVersion)' != '$(_ActualWasiSdkVersion)'">true</_UseRuntimeLocalWasiSdk>
19+
</PropertyGroup>
20+
</Target>
21+
22+
<!-- Otherwise, download our own SDK. Use this file as the input since that's what defines the version. -->
23+
<Target Name="_AcquireLocalWasiSdk"
24+
Condition="'$(_UseRuntimeLocalWasiSdk)' == 'true'"
25+
Inputs="$(MSBuildThisFileFullPath)"
26+
Outputs="$(_RuntimeLocalWasiSdkPath)VERSION">
27+
28+
<Message Text="Downloading a runtime-local WASI SDK $(_WasiSdkVersion) to '$(_RuntimeLocalWasiSdkPath)'" Importance="High" />
29+
30+
<PropertyGroup>
31+
<_WasiSdkMajorVersion>$(_WasiSdkVersion.Split('.')[0])</_WasiSdkMajorVersion>
32+
<_WasiSdkUrl>https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(_WasiSdkMajorVersion)/wasi-sdk-$(_WasiSdkVersion)-x86_64-linux.tar.gz</_WasiSdkUrl>
33+
<_WasiSdkUrl Condition="'$(HostOS)' == 'osx'" >https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(_WasiSdkMajorVersion)/wasi-sdk-$(_WasiSdkVersion)-x86_64-macos.tar.gz</_WasiSdkUrl>
34+
<_WasiSdkUrl Condition="'$(HostOS)' == 'windows'" >https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(_WasiSdkMajorVersion)/wasi-sdk-$(_WasiSdkVersion)-x86_64-windows.tar.gz</_WasiSdkUrl>
35+
</PropertyGroup>
36+
37+
<RemoveDir Directories="$(_RuntimeLocalWasiSdkPath)" />
38+
<MakeDir Directories="$(_RuntimeLocalWasiSdkPath)" />
39+
40+
<Exec Command="curl -L -o wasi-sdk-$(_WasiSdkVersion).tar.gz $(_WasiSdkUrl) &amp;&amp; tar --strip-components=1 -xzmf wasi-sdk-$(_WasiSdkVersion).tar.gz -C $(_RuntimeLocalWasiSdkPath)"
41+
Condition="'$(HostOS)' != 'windows'"
42+
WorkingDirectory="$(ArtifactsObjDir)"
43+
IgnoreStandardErrorWarningFormat="true" />
44+
45+
<Exec Command="powershell -NonInteractive -command &quot;&amp; $(MSBuildThisFileDirectory)\download-wasi-sdk.ps1 -WasiSdkUrl $(_WasiSdkUrl) -WasiSdkVersion $(_WasiSdkVersion) -WasiSdkPath $(_RuntimeLocalWasiSdkPath); Exit $LastExitCode &quot;"
46+
Condition="'$(HostOS)' == 'windows'"
47+
WorkingDirectory="$(ArtifactsObjDir)"
48+
IgnoreStandardErrorWarningFormat="true" />
49+
</Target>
50+
51+
<Target Name="AcquireWasiSdkUnconditional"
52+
DependsOnTargets="_ValidateWasiSdk;_AcquireLocalWasiSdk">
53+
<PropertyGroup>
54+
<RuntimeBuildWasiSdkPath Condition="'$(_UseRuntimeLocalWasiSdk)' != 'true'">$([MSBuild]::NormalizeDirectory('$(WASI_SDK_PATH)'))</RuntimeBuildWasiSdkPath>
55+
<RuntimeBuildWasiSdkPath Condition="'$(_UseRuntimeLocalWasiSdk)' == 'true'">$(_RuntimeLocalWasiSdkPath)</RuntimeBuildWasiSdkPath>
56+
</PropertyGroup>
57+
</Target>
58+
59+
<Target Name="AcquireWasiSdk"
60+
Condition="'$(TargetsWasi)' == 'true'"
61+
DependsOnTargets="AcquireWasiSdkUnconditional" />
62+
</Project>

src/mono/wasi/provision.ps1 renamed to eng/download-wasi-sdk.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,13 @@ param(
44
[Parameter()]
55
[string]$WasiSdkVersion,
66
[Parameter()]
7-
[string]$WasiSdkPath,
8-
[Parameter()]
9-
[string]$WasiLocalPath
7+
[string]$WasiSdkPath
108
)
119

1210
Set-StrictMode -version 2.0
1311
$ErrorActionPreference='Stop'
1412
$ProgressPreference = 'SilentlyContinue'
1513

16-
New-Item -Path $WasiSdkPath -ItemType "directory"
1714
Invoke-WebRequest -Uri $WasiSdkUrl -OutFile ./wasi-sdk-$WasiSdkVersion-x86_64-windows.tar.gz
18-
tar --strip-components=1 -xzf ./wasi-sdk-$WasiSdkVersion-x86_64-windows.tar.gz -C $WasiSdkPath
19-
Copy-Item $WasiLocalPath/wasi-sdk-version.txt $WasiSdkPath/wasi-sdk-version.txt
15+
tar --strip-components=1 -xzmf ./wasi-sdk-$WasiSdkVersion-x86_64-windows.tar.gz -C $WasiSdkPath
2016
Remove-Item ./wasi-sdk-$WasiSdkVersion-x86_64-windows.tar.gz -fo

eng/native/gen-buildsys.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ if /i "%__Arch%" == "wasm" (
5959
)
6060
if /i "%__Os%" == "wasi" (
6161
if "%WASI_SDK_PATH%" == "" (
62-
if not exist "%__repoRoot%\src\mono\wasi\wasi-sdk" (
62+
if not exist "%__repoRoot%\artifacts\wasi-sdk" (
6363
echo Error: Should set WASI_SDK_PATH environment variable pointing to WASI SDK root.
6464
exit /B 1
6565
)
6666

67-
set "WASI_SDK_PATH=%__repoRoot%\src\mono\wasi\wasi-sdk"
67+
set "WASI_SDK_PATH=%__repoRoot%\artifacts\wasi-sdk"
6868
)
6969
set __CmakeGenerator=Ninja
7070
set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk-p2.cmake" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1"

eng/native/gen-buildsys.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ if [[ "$host_arch" == "wasm" ]]; then
109109
cmake_command="emcmake $cmake_command"
110110
elif [[ "$target_os" == "wasi" ]]; then
111111
if [[ -z "$WASI_SDK_PATH" ]]; then
112-
if [[ -d "$reporoot"/src/mono/wasi/wasi-sdk ]]; then
113-
export WASI_SDK_PATH="$reporoot"/src/mono/wasi/wasi-sdk
112+
if [[ -d "$reporoot"/artifacts/wasi-sdk ]]; then
113+
export WASI_SDK_PATH="$reporoot"/artifacts/wasi-sdk
114114
else
115115
echo "Error: You need to set the WASI_SDK_PATH environment variable pointing to the WASI SDK root."
116116
exit 1

eng/testing/tests.wasi.targets

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
>true</InstallWasmtimeForTests>
1414

1515
<!--<InstallWorkloadUsingArtifactsDependsOn>_GetWorkloadsToInstall;$(InstallWorkloadUsingArtifactsDependsOn)</InstallWorkloadUsingArtifactsDependsOn>-->
16-
<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/WASI-SDK-VERSION-25.0')">$([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
17-
<WASI_SDK_PATH>$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))</WASI_SDK_PATH>
1816

1917
<_BundleAOTTestWasmAppForHelixDependsOn>$(_BundleAOTTestWasmAppForHelixDependsOn);PrepareForWasiBuildApp;_PrepareForAOTOnHelix</_BundleAOTTestWasmAppForHelixDependsOn>
2018
</PropertyGroup>

src/libraries/sendtohelix-wasi.targets

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@
4646
<IncludeHelixCorrelationPayload>false</IncludeHelixCorrelationPayload>
4747
<EnableDefaultBuildHelixWorkItems>false</EnableDefaultBuildHelixWorkItems>
4848

49-
<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/WASI-SDK-VERSION-25.0')">$([MSBuild]::NormalizeDirectory($(RepoRoot), 'src', 'mono', 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
50-
<WASI_SDK_PATH>$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))</WASI_SDK_PATH>
5149
<WasiBuildTargetsDir>$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasi', 'build'))</WasiBuildTargetsDir>
5250
<WasiSdkDirForHelixPayload>$(HelixDependenciesStagingPath)$(WorkItemPrefix)wasi-sdk</WasiSdkDirForHelixPayload>
5351
<WasmtimeDirForHelixPayload>$(HelixDependenciesStagingPath)$(WorkItemPrefix)wasmtime</WasmtimeDirForHelixPayload>
@@ -63,11 +61,6 @@
6361
<SdkForWorkloadTestingDirName Condition="'$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' != 'true'">dotnet-none</SdkForWorkloadTestingDirName>
6462
</PropertyGroup>
6563

66-
<ItemGroup>
67-
<HelixDependenciesToStage Condition="'$(NeedsWasiSdk)' == 'true'" SourcePath="$(WASI_SDK_PATH)" Include="$(WasiSdkDirForHelixPayload)" />
68-
<HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)" Include="$(WasmtimeDirForHelixPayload)" />
69-
</ItemGroup>
70-
7164
<ItemGroup Condition="'$(WindowsShell)' != 'true'">
7265
<HelixPreCommand Condition="'$(Scenario)' != ''" Include="export SCENARIO=$(Scenario)" />
7366
<HelixPreCommand Include="export XHARNESS_DISABLE_COLORED_OUTPUT=true" />
@@ -104,7 +97,20 @@
10497
<EnableXHarnessTelemetry>false</EnableXHarnessTelemetry>
10598
</PropertyGroup>
10699

100+
<ItemGroup>
101+
<HelixDependenciesToStage Condition="'$(NeedsWasmtime)' == 'true'" SourcePath="$(WasmtimeDir)" Include="$(WasmtimeDirForHelixPayload)" />
102+
</ItemGroup>
103+
107104
<Import Project="$(RepositoryEngineeringDir)testing\wasi-provisioning.targets" />
105+
<Import Project="$(RepositoryEngineeringDir)AcquireWasiSdk.targets" />
106+
107+
<Target Name="IncludeWasiSdkForHelixStaging" Condition="'$(NeedsWasiSdk)' == 'true'"
108+
DependsOnTargets="AcquireWasiSdk"
109+
BeforeTargets="StageDependenciesForHelix">
110+
<ItemGroup>
111+
<HelixDependenciesToStage SourcePath="$(RuntimeBuildWasiSdkPath)" Include="$(WasiSdkDirForHelixPayload)" />
112+
</ItemGroup>
113+
</Target>
108114

109115
<Target Name="PrepareHelixCorrelationPayload_Wasi">
110116
<Error Condition="'$(Scenario)' != 'WasmTestOnWasmtime' and

src/libraries/sendtohelixhelp.proj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,6 @@
108108
<TestEnvFileName Condition=" '$(Scenario)' != '' and '$(TargetOS)' != 'windows' and '$(TargetOS)' != 'browser' and '$(TargetOS)' != 'wasi'">SetStressModes_$(Scenario).sh</TestEnvFileName>
109109
</PropertyGroup>
110110

111-
<ItemGroup>
112-
<__HelixDependenciesToStageThatDontExist Include="@(HelixDependenciesToStage)" />
113-
<__HelixDependenciesToStageThatDontExist Remove="@(HelixDependenciesToStage->Exists())" />
114-
</ItemGroup>
115-
116111
<!-- HelixPreCommands is a set of commands run before the work item command. We use it here to inject
117112
setting up the per-scenario environment.
118113
-->
@@ -362,7 +357,12 @@
362357
`WASI_SDK_PATH=/usr/local/wasi-sdk`
363358
.. then we need to stage that before passing the path to helix like under `artifacts/obj/helix-staging`
364359
-->
365-
<Target Name="StageDependenciesForHelix" Condition="@(__HelixDependenciesToStageThatDontExist->Count()) > 0">
360+
<Target Name="StageDependenciesForHelix"
361+
Condition="'@(HelixDependenciesToStage->Exists())' != '@(HelixDependenciesToStage)'">
362+
<ItemGroup>
363+
<__HelixDependenciesToStageThatDontExist Include="@(HelixDependenciesToStage)" Condition="!Exists('%(Identity)')" />
364+
</ItemGroup>
365+
366366
<Error Condition="'%(__HelixDependenciesToStageThatDontExist.SourcePath)' == '' or !Exists(%(__HelixDependenciesToStageThatDontExist.SourcePath))"
367367
Text="Could not find %(__HelixDependenciesToStageThatDontExist.Name) at %(__HelixDependenciesToStageThatDontExist.SourcePath), needed to provision for running tests on helix" />
368368

src/mono/Directory.Build.props

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@
3232
<EMSDK_PATH Condition="Exists('$(ProvisionEmscriptenDir)') and '$(EMSDK_PATH)' == ''">$(ProvisionEmscriptenDir.Replace('\', '/'))</EMSDK_PATH>
3333
</PropertyGroup>
3434

35-
<!-- Directory to provision and use WASI sdk if WASI_SDK_PATH env variable is not set -->
36-
<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
37-
<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/WASI-SDK-VERSION-25.0')">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
38-
<WASI_SDK_PATH>$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))</WASI_SDK_PATH>
39-
<ShouldProvisionWasiSdk Condition="!Exists('$(WASI_SDK_PATH)/WASI-SDK-VERSION-25.0')">true</ShouldProvisionWasiSdk>
40-
</PropertyGroup>
41-
4235
<PropertyGroup>
4336
<PlatformConfigPathPart>$(TargetOS).$(Platform).$(Configuration)</PlatformConfigPathPart>
4437
<RuntimeBinDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'mono', '$(TargetOS).$(Platform).$(Configuration)'))</RuntimeBinDir>

0 commit comments

Comments
 (0)