|
| 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) && 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 "& $(MSBuildThisFileDirectory)\download-wasi-sdk.ps1 -WasiSdkUrl $(_WasiSdkUrl) -WasiSdkVersion $(_WasiSdkVersion) -WasiSdkPath $(_RuntimeLocalWasiSdkPath); Exit $LastExitCode "" |
| 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> |
0 commit comments