Skip to content

Commit d40e0bc

Browse files
committed
Move sdk install to wit-bindgen
Anytime you use wit-bindgen you need the SDK's so we should install them on that package. Signed-off-by: James Sturtevant <[email protected]>
1 parent b27a5f3 commit d40e0bc

File tree

3 files changed

+83
-83
lines changed

3 files changed

+83
-83
lines changed
Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,4 @@
11
<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-
222
<Target Name="EmitWasmOnBuild" AfterTargets="CopyFilesToOutputDirectory" DependsOnTargets="LinkNativeLlvm; ConvertToWasmComponent"
233
Condition="'$(RuntimeIdentifier)' == 'wasi-wasm'">
244
<Message Importance="high" Text="$(ProjectName) -> $([System.IO.Path]::GetFullPath('$(NativeComponentBinary)'))" />
@@ -40,63 +20,4 @@
4020
<NativeComponentBinary>$(NativeOutputPath)$(TargetName.ToLower())-component.wasm</NativeComponentBinary>
4121
</PropertyGroup>
4222
</Target>
43-
44-
<Target Name="PrepareWasmSdks" BeforeTargets="CheckWasmSdks" DependsOnTargets="ObtainWasiSdk; ObtainEmscripten">
45-
<PropertyGroup>
46-
<EmSdk>$(EmscriptenRoot)</EmSdk>
47-
<WASI_SDK_PATH>$(WasiSdkRoot)</WASI_SDK_PATH>
48-
</PropertyGroup>
49-
</Target>
50-
51-
<Target Name="ObtainEmscripten" Condition="'$(EMSDK)' == '' AND !(Exists($(EmscriptenRoot)))">
52-
<!--
53-
This is not ideal because if your solution has multiple projects that use WasmComponent.Sdk, then if you
54-
build in parallel in CI where your machine doesn't already have wasi-sdk/emsdk, then it may try to download
55-
and extract the SDKs multiple times in parallel to the same disk location, which may cause it to fail.
56-
The only reason this doesn't happen in this repo is that it explicitly runs the PrepareWasmSdks task before
57-
building other projects.
58-
59-
For a proper fix, consider implementing an MSBuild task in C# that obtains wasi-sdk/emsdk, and uses a mutex
60-
so that only one flow executes at a time, with others blocking until it's done.
61-
-->
62-
63-
<PropertyGroup>
64-
<EmSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</EmSdkDownloadTempDir>
65-
</PropertyGroup>
66-
67-
<MakeDir Directories="$(EmSdkDownloadTempDir)" />
68-
<DownloadFile
69-
SourceUrl="$(EmSdkUrl)"
70-
DestinationFolder="$(EmSdkDownloadTempDir)">
71-
<Output TaskParameter="DownloadedFile" ItemName="EmSdkDownloadTempFile" />
72-
</DownloadFile>
73-
74-
<!-- Windows 10+ has tar built in, so this should work cross-platform -->
75-
<Message Importance="high" Text="Extracting @(EmSdkDownloadTempFile) to $(EmscriptenRoot)..." />
76-
<MakeDir Directories="$(EmscriptenRoot)" />
77-
<Exec Command="tar -xf &quot;@(EmSdkDownloadTempFile)&quot; -C . --strip-components=1" WorkingDirectory="$(EmscriptenRoot)" />
78-
<RemoveDir Directories="$(EmSdkDownloadTempDir)" />
79-
80-
<Exec Command="emsdk install $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" />
81-
<Exec Command="emsdk activate $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" />
82-
</Target>
83-
84-
<Target Name="ObtainWasiSdk" Condition="!(Exists($(WasiSdkRoot)))">
85-
<PropertyGroup>
86-
<WasiSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</WasiSdkDownloadTempDir>
87-
</PropertyGroup>
88-
89-
<MakeDir Directories="$(WasiSdkDownloadTempDir)" />
90-
<DownloadFile
91-
SourceUrl="$(WasiSdkUrl)"
92-
DestinationFolder="$(WasiSdkDownloadTempDir)">
93-
<Output TaskParameter="DownloadedFile" ItemName="WasiSdkDownloadTempFile" />
94-
</DownloadFile>
95-
96-
<!-- Windows 10+ has tar built in, so this should work cross-platform -->
97-
<Message Importance="high" Text="Extracting @(WasiSdkDownloadTempFile) to $(WasiSdkRoot)..." />
98-
<MakeDir Directories="$(WasiSdkRoot)" />
99-
<Exec Command="tar -xf &quot;@(WasiSdkDownloadTempFile)&quot; -C . --strip-components=1" WorkingDirectory="$(WasiSdkRoot)" />
100-
<RemoveDir Directories="$(WasiSdkDownloadTempDir)" />
101-
</Target>
10223
</Project>

src/WitBindgen/build/WitBindgen.targets

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,91 @@
11
<Project>
22
<PropertyGroup>
33
<WitBindgenRuntime>native-aot</WitBindgenRuntime>
4+
5+
<!-- Keep this block all in sync manually, since URLs can be arbitrary -->
6+
<WasiSdkVersion>20.0</WasiSdkVersion>
7+
<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>
8+
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('Linux'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz</WasiSdkUrl>
9+
<WasiSdkUrl Condition="$([MSBuild]::IsOSPlatform('OSX'))">https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz</WasiSdkUrl>
10+
<WasiSdkRoot>$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".wasi-sdk", "wasi-sdk-$(WasiSdkVersion)"))</WasiSdkRoot>
11+
12+
<EmSdkVersion>3.1.61</EmSdkVersion>
13+
<EmSdkUrl>https://github.com/emscripten-core/emsdk/archive/refs/tags/$(EmSdkVersion).zip</EmSdkUrl>
14+
<!-- Support bring your own emscripten if $(EMSDK) is already set-->
15+
<EmscriptenRoot Condition="'$(EMSDK)' == ''">$([System.IO.Path]::Combine("$([System.Environment]::GetFolderPath(SpecialFolder.UserProfile))", ".emsdk", "emsdk-$(EmSdkVersion)"))</EmscriptenRoot>
16+
<EmscriptenRoot Condition="'$(EMSDK)' != ''">$(EMSDK)</EmscriptenRoot>
417
</PropertyGroup>
518

19+
<!--
20+
MSBuild stuff to acquire the necessary SDKs (WASI SDK and Emscripten) automatically. It will take a few mins on the
21+
first build on a given machine, but after that should no-op.
22+
-->
23+
<Target Name="PrepareWasmSdks" BeforeTargets="CheckWasmSdks" DependsOnTargets="ObtainWasiSdk; ObtainEmscripten">
24+
<PropertyGroup>
25+
<EmSdk>$(EmscriptenRoot)</EmSdk>
26+
<Wasicompiler>$(EmscriptenRoot)\upstream\emscripten\emcc.bat</Wasicompiler>
27+
<WASI_SDK_PATH>$(WasiSdkRoot)</WASI_SDK_PATH>
28+
</PropertyGroup>
29+
</Target>
30+
31+
<Target Name="ObtainEmscripten" Condition="'$(EMSDK)' == '' AND !(Exists($(EmscriptenRoot)))">
32+
<!--
33+
This is not ideal because if your solution has multiple projects that use WasmComponent.Sdk, then if you
34+
build in parallel in CI where your machine doesn't already have wasi-sdk/emsdk, then it may try to download
35+
and extract the SDKs multiple times in parallel to the same disk location, which may cause it to fail.
36+
The only reason this doesn't happen in this repo is that it explicitly runs the PrepareWasmSdks task before
37+
building other projects.
38+
39+
For a proper fix, consider implementing an MSBuild task in C# that obtains wasi-sdk/emsdk, and uses a mutex
40+
so that only one flow executes at a time, with others blocking until it's done.
41+
-->
42+
43+
<PropertyGroup>
44+
<EmSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</EmSdkDownloadTempDir>
45+
</PropertyGroup>
46+
47+
<MakeDir Directories="$(EmSdkDownloadTempDir)" />
48+
<DownloadFile
49+
SourceUrl="$(EmSdkUrl)"
50+
DestinationFolder="$(EmSdkDownloadTempDir)">
51+
<Output TaskParameter="DownloadedFile" ItemName="EmSdkDownloadTempFile" />
52+
</DownloadFile>
53+
54+
<!-- Windows 10+ has tar built in, so this should work cross-platform -->
55+
<Message Importance="high" Text="Extracting @(EmSdkDownloadTempFile) to $(EmscriptenRoot)..." />
56+
<MakeDir Directories="$(EmscriptenRoot)" />
57+
<Exec Command="tar -xf &quot;@(EmSdkDownloadTempFile)&quot; -C . --strip-components=1" WorkingDirectory="$(EmscriptenRoot)" />
58+
<RemoveDir Directories="$(EmSdkDownloadTempDir)" />
59+
60+
<Exec Command="emsdk install $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" />
61+
<Exec Command="emsdk activate $(EmSdkVersion)" WorkingDirectory="$(EmscriptenRoot)" />
62+
</Target>
63+
64+
<Target Name="ObtainWasiSdk" Condition="!(Exists($(WasiSdkRoot)))">
65+
<PropertyGroup>
66+
<WasiSdkDownloadTempDir>$([System.IO.Path]::Combine($([System.IO.Path]::GetTempPath()), $([System.IO.Path]::GetRandomFileName())))</WasiSdkDownloadTempDir>
67+
</PropertyGroup>
68+
69+
<MakeDir Directories="$(WasiSdkDownloadTempDir)" />
70+
<DownloadFile
71+
SourceUrl="$(WasiSdkUrl)"
72+
DestinationFolder="$(WasiSdkDownloadTempDir)">
73+
<Output TaskParameter="DownloadedFile" ItemName="WasiSdkDownloadTempFile" />
74+
</DownloadFile>
75+
76+
<!-- Windows 10+ has tar built in, so this should work cross-platform -->
77+
<Message Importance="high" Text="Extracting @(WasiSdkDownloadTempFile) to $(WasiSdkRoot)..." />
78+
<MakeDir Directories="$(WasiSdkRoot)" />
79+
<Exec Command="tar -xf &quot;@(WasiSdkDownloadTempFile)&quot; -C . --strip-components=1" WorkingDirectory="$(WasiSdkRoot)" />
80+
<RemoveDir Directories="$(WasiSdkDownloadTempDir)" />
81+
</Target>
82+
83+
<!--
84+
Following generats and compiles the wit code for the c# project
85+
-->
686
<Target Name="WitCompile_BeforeCsCompile" BeforeTargets="BeforeCompile"
787
Condition="'$(Language)' == 'C#' AND '@(Wit)' != ''"
8-
DependsOnTargets="WitCompile_GetDependencies; WitCompile_InvokeTool">
88+
DependsOnTargets="PrepareWasmSdks; WitCompile_GetDependencies; WitCompile_InvokeTool">
989
<ItemGroup>
1090
<Compile Include="$(WitGeneratedFilesRoot)**\*.cs" />
1191
<NativeObjects Include="$(WitGeneratedFilesRoot)**\*.o" />
@@ -40,8 +120,8 @@
40120
<ItemGroup>
41121
<CabiReAllocFiles Include="$(WitGeneratedFilesRoot)**\*World_cabi_realloc.c" />
42122
</ItemGroup>
43-
<Message Importance="high" Text="building cabi... @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ')" />
44-
<Exec WorkingDirectory="$(WitGeneratedFilesRoot)" Command="emcc.bat @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ') -c"/>
123+
<Message Importance="high" Text="building cabi_realloc files... @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ') with $(Wasicompiler)" />
124+
<Exec WorkingDirectory="$(WitGeneratedFilesRoot)" Command="&quot;$(Wasicompiler)&quot; @(CabiReAllocFiles->'&quot;%(FullPath)&quot;', ' ') -c"/>
45125

46126
<ItemGroup>
47127
<WitGeneratedCsFiles Include="$(WitGeneratedFilesRoot)**\*.cs" />

test/E2ETest/PackageTest/PackageTest.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
</PackageReference>
2828

2929
<!-- To ensure we don't build this until we've built the underlying packages -->
30-
<ProjectReference Include="..\testapps\E2EConsumer\E2EConsumer.csproj" ReferenceOutputAssembly="false" />
3130
<ProjectReference Include="..\..\..\src\WasmComponent.Sdk\WasmComponent.Sdk.csproj" ReferenceOutputAssembly="false" />
3231
</ItemGroup>
3332

0 commit comments

Comments
 (0)