|
1 | 1 | <Project>
|
2 |
| - <!-- |
3 |
| - MSBuild stuff to acquire the necessary SDKs (WASI SDK and Emscripten) automatically. It will take a few mins on the |
4 |
| - first build on a given machine, but after that should no-op. |
5 |
| - --> |
6 |
| - |
7 |
| - <PropertyGroup> |
8 |
| - <!-- Keep this block all in sync manually, since URLs can be arbitrary --> |
9 |
| - <WasiSdkVersion>20.0</WasiSdkVersion> |
10 |
| - <WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Windows'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0.m-mingw.tar.gz</WasiSdkUrl> |
11 |
| - <WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Linux'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz</WasiSdkUrl> |
12 |
| - <WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('OSX'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz</WasiSdkUrl> |
13 |
| - <WasiSdkRoot>$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".wasi-sdk", "wasi-sdk-$(WasiSdkVersion)"))</WasiSdkRoot> |
14 |
| - |
15 |
| - <EmSdkVersion>3.1.23</EmSdkVersion> |
16 |
| - <EmSdkUrl>https://github.com/emscripten-core/emsdk/archive/refs/tags/$(EmSdkVersion).zip</EmSdkUrl> |
17 |
| - <!-- Support bring your own emscripten if $(EMSDK) is already set--> |
18 |
| - <EmscriptenRoot Condition="'$(EMSDK)' == ''">$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".emsdk", "emsdk-$(EmSdkVersion)"))</EmscriptenRoot> |
19 |
| - <EmscriptenRoot Condition="'$(EMSDK)' != ''">$(EMSDK)</EmscriptenRoot> |
20 |
| - </PropertyGroup> |
21 |
| - |
22 | 2 | <Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm; ConvertToWasmComponent"
|
23 | 3 | Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">
|
24 | 4 | <Message Importance="high" Text="$(ProjectName) -> $([System.IO.Path]::GetFullPath('$(NativeComponentBinary)'))" />
|
|
33 | 13 | <WasiPreview1AdapterType>reactor</WasiPreview1AdapterType>
|
34 | 14 | <WasiPreview1AdapterType Condition="'$(OutputType.ToLower())' == 'exe'">command</WasiPreview1AdapterType>
|
35 | 15 | <WasiPreview1AdapterPath>$(MSBuildThisFileDirectory)../tools/wasi-wasm/wasi_snapshot_preview1.$(WasiPreview1AdapterType).wasm</WasiPreview1AdapterPath>
|
36 |
| - <NativeComponentBinary>$(NativeOutputPath)$(TargetName).component.wasm</NativeComponentBinary> |
37 |
| - </PropertyGroup> |
38 |
| - </Target> |
39 |
| - |
40 |
| - <Target Name="PrepareWasmSdks" BeforeTargets="CheckWasmSdks" DependsOnTargets="ObtainWasiSdk; ObtainEmscripten"> |
41 |
| - <PropertyGroup> |
42 |
| - <EmSdk>$(EmscriptenRoot)</EmSdk> |
43 |
| - <WASI_SDK_PATH>$(WasiSdkRoot)</WASI_SDK_PATH> |
44 |
| - </PropertyGroup> |
45 |
| - </Target> |
46 |
| - |
47 |
| - <Target Name="ObtainEmscripten" Condition="'$(EMSDK)' == '' AND !(Exists($(EmscriptenRoot)))"> |
48 |
| - <!-- |
49 |
| - This is not ideal because if your solution has multiple projects that use WasmComponent.Sdk, then if you |
50 |
| - build in parallel in CI where your machine doesn't already have wasi-sdk/emsdk, then it may try to download |
51 |
| - and extract the SDKs multiple times in parallel to the same disk location, which may cause it to fail. |
52 |
| - The only reason this doesn't happen in this repo is that it explicitly runs the PrepareWasmSdks task before |
53 |
| - building other projects. |
54 |
| -
|
55 |
| - For a proper fix, consider implementing an MSBuild task in C# that obtains wasi-sdk/emsdk, and uses a mutex |
56 |
| - so that only one flow executes at a time, with others blocking until it's done. |
57 |
| - --> |
58 |
| - |
59 |
| - <PropertyGroup> |
60 |
| - <EmSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</EmSdkDownloadTempDir> |
| 16 | + <!-- |
| 17 | + wasm compose requires kabab case (todo: revisit when move to wac https://github.com/bytecodealliance/componentize-dotnet/issues/5) |
| 18 | + https://github.com/bytecodealliance/wasm-tools/issues/1440 |
| 19 | + --> |
| 20 | + <NativeComponentBinary>$(NativeOutputPath)$(TargetName.ToLower())-component.wasm</NativeComponentBinary> |
61 | 21 | </PropertyGroup>
|
62 |
| - |
63 |
| - <MakeDir Directories="$(EmSdkDownloadTempDir)" /> |
64 |
| - <DownloadFile |
65 |
| - SourceUrl="$(EmSdkUrl)" |
66 |
| - DestinationFolder="$(EmSdkDownloadTempDir)"> |
67 |
| - <Output TaskParameter="DownloadedFile" ItemName="EmSdkDownloadTempFile" /> |
68 |
| - </DownloadFile> |
69 |
| - |
70 |
| - <!-- Windows 10+ has tar built in, so this should work cross-platform --> |
71 |
| - <Message Importance="high" Text="Extracting @(EmSdkDownloadTempFile) to $(EmscriptenRoot)..." /> |
72 |
| - <MakeDir Directories="$(EmscriptenRoot)" /> |
73 |
| - <Exec Command="tar -xf "@(EmSdkDownloadTempFile)" -C . --strip-components=1" WorkingDirectory="$(EmscriptenRoot)" /> |
74 |
| - <RemoveDir Directories="$(EmSdkDownloadTempDir)" /> |
75 |
| - |
76 |
| - <Exec Command="emsdk install $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" /> |
77 |
| - <Exec Command="emsdk activate $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" /> |
78 |
| - </Target> |
79 |
| - |
80 |
| - <Target Name="ObtainWasiSdk" Condition="!(Exists($(WasiSdkRoot)))"> |
81 |
| - <PropertyGroup> |
82 |
| - <WasiSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</WasiSdkDownloadTempDir> |
83 |
| - </PropertyGroup> |
84 |
| - |
85 |
| - <MakeDir Directories="$(WasiSdkDownloadTempDir)" /> |
86 |
| - <DownloadFile |
87 |
| - SourceUrl="$(WasiSdkUrl)" |
88 |
| - DestinationFolder="$(WasiSdkDownloadTempDir)"> |
89 |
| - <Output TaskParameter="DownloadedFile" ItemName="WasiSdkDownloadTempFile" /> |
90 |
| - </DownloadFile> |
91 |
| - |
92 |
| - <!-- Windows 10+ has tar built in, so this should work cross-platform --> |
93 |
| - <Message Importance="high" Text="Extracting @(WasiSdkDownloadTempFile) to $(WasiSdkRoot)..." /> |
94 |
| - <MakeDir Directories="$(WasiSdkRoot)" /> |
95 |
| - <Exec Command="tar -xf "@(WasiSdkDownloadTempFile)" -C . --strip-components=1" WorkingDirectory="$(WasiSdkRoot)" /> |
96 |
| - <RemoveDir Directories="$(WasiSdkDownloadTempDir)" /> |
97 | 22 | </Target>
|
98 | 23 | </Project>
|
0 commit comments