From 2561e795a3c09da66987ce8ab05c84fa5d626176 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Wed, 24 Mar 2021 17:15:34 -0400 Subject: [PATCH] [wasm] Add support for using emscripten from packages (#50077) * [wasm] Add support for using emscripten from packages When using a workload that has the emscripten packages, certain properties get set. If that isn't set then we fallback to using `$(EMSDK_PATH)`. This should allow being able to use emscripten from workloads, but for other cases where we depend on an installed emscripten, that should work too. * Fix setting PATH on windows * Using msbuild NormalizeDirectory to construct dir path * fix setting PATH on windows, when paths have trailing slash * [wasm] Improve checking emscripten from workload, and EMSDK_PATH - If a workload pack is being used, then ignore `EMSDK_PATH` - And error in that order too - Emit better error messages Example messages: - Missing python dir when relinking: `warning : Specified Emscripten sdk at $(EMSDK_PATH)=. is missing some paths: $(EmscriptenPythonToolsPath)=/Users/radical/dev/r3/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/e10djxv0.wdr/python/3.7.4-2_64bit/ . Emscripten SDK is required for building native files.` - Missing node directory, or the wrong version dir: `warning : Specified Emscripten sdk at $(EMSDK_PATH)=/Users/radical/dev/r3/src/mono/wasm/emsdk is missing some paths: $(EmscriptenNodeToolsPath)=/Users/radical/dev/r3/src/mono/wasm/emsdk/node/12.18.1_64bit/ . Emscripten SDK is required for building native files.` - Empty `EMSDK_PATH` `Error : Could not find Emscripten sdk at $(EMSDK_PATH)=/Users/radical/dev/r3/src/mono/wasm/emsdk/. Emscripten SDK is required for AOT'ing assemblies.` - Bad `EMSDK_PATH` `error : Specified Emscripten sdk at $(EMSDK_PATH)=. is missing some paths: $(EmscriptenPythonToolsPath)=/Users/radical/dev/r3/artifacts/bin/Wasm.Build.Tests/net6.0-Release/browser-wasm/l2mcsipf.isn/python/3.7.4-2_64bit/ . Emscripten SDK is required for AOT'ing assemblies.` * [wasm] Don't hardcode versions for python/node bundled in emsdk .. and listen to @lewing's suggestions! * [wasm] GetDirectories doesn't like non-existant paths * Fix the earlier fix * improve errors when some paths are missing * cleanup * debugging on ci * [wasm] emscripten uses system python on linux, so don't try to find it in emscripten sdk --- src/mono/wasm/build/WasmApp.targets | 133 ++++++++++++++++++++++++---- 1 file changed, 116 insertions(+), 17 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index c0d04fd798e4e9..44b256bf2f7261 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -3,7 +3,6 @@ - + + + + $([MSBuild]::EnsureTrailingSlash($(EMSDK_PATH))) + $([MSBuild]::NormalizeDirectory($(EmscriptenSdkToolsPath), 'upstream', 'bin')) + + <_NodeToolsBasePath>$(EmscriptenSdkToolsPath)node + + + <_NodeToolsVersionedPath Condition="Exists($(_NodeToolsBasePath))">$([System.IO.Directory]::GetDirectories($(_NodeToolsBasePath))) + $(_NodeToolsVersionedPath) + + <_UsingEMSDK_PATH>true + + + + <_EMSDKMissingPaths Condition="'$(_EMSDKMissingPaths)' == '' and ('$(EmscriptenSdkToolsPath)' == '' or !Exists('$(EmscriptenSdkToolsPath)'))">%24(EmscriptenSdkToolsPath)=$(EmscriptenSdkToolsPath) + <_EMSDKMissingPaths Condition="'$(_EMSDKMissingPaths)' == '' and ('$(EmscriptenNodeToolsPath)' == '' or !Exists('$(EmscriptenNodeToolsPath)'))">%24(EmscriptenNodeToolsPath)=$(EmscriptenNodeToolsPath) + <_EMSDKMissingPaths Condition="'$(_EMSDKMissingPaths)' == '' and ('$(EmSdkUpstreamBinPath)' == '' or !Exists('$(EmSdkUpstreamBinPath)'))">%24(EmSdkUpstreamBinPath)=$(EmSdkUpstreamBinPath) + + + + + <_PythonToolsBasePath>$(EmscriptenSdkToolsPath)python + <_PythonToolsVersionedPath Condition="Exists($(_PythonToolsBasePath))">$([System.IO.Directory]::GetDirectories($(_PythonToolsBasePath))) + $(_PythonToolsVersionedPath) + + <_EMSDKMissingPaths Condition="'$(_EMSDKMissingPaths)' == '' and ('$(EmscriptenPythonToolsPath)' == '' or !Exists('$(EmscriptenPythonToolsPath)'))">%24(EmscriptenPythonToolsPath)=$(EmscriptenPythonToolsPath) + + + + <_EMSDKMissingErrorMessage Condition="'$(EMSDK_PATH)' == '' and '$(EmscriptenSdkToolsPath)' == ''">Could not find emscripten sdk. Either set %24(EMSDK_PATH), or use workloads to get the sdk. + + <_EMSDKMissingErrorMessage Condition="'$(_EMSDKMissingErrorMessage)' == '' and '$(_UsingEMSDK_PATH)' != 'true' and '$(_EMSDKMissingPaths)' != ''">Emscripten from the workload is missing some paths: $(_EMSDKMissingPaths). + <_EMSDKMissingErrorMessage Condition="'$(_EMSDKMissingErrorMessage)' == '' and '$(_UsingEMSDK_PATH)' == 'true' and !Exists($(EMSDK_PATH))">Could not find Emscripten sdk at %24(EMSDK_PATH)=$(EMSDK_PATH) . + <_EMSDKMissingErrorMessage Condition="'$(_EMSDKMissingErrorMessage)' == '' and '$(_UsingEMSDK_PATH)' == 'true' and '$(_EMSDKMissingPaths)' != ''">Specified Emscripten sdk at %24(EMSDK_PATH)=$(EMSDK_PATH) is missing some paths: $(_EMSDKMissingPaths). + + <_IsEMSDKMissing Condition="'$(_EMSDKMissingErrorMessage)' != ''">true + + - <_IsEMSDKMissing Condition="'$(EMSDK_PATH)' == '' or !Exists('$(EMSDK_PATH)')">true + $([MSBuild]::NormalizeDirectory($(EmscriptenSdkToolsPath))) + $([MSBuild]::NormalizeDirectory($(EmscriptenNodeToolsPath))) + $([MSBuild]::NormalizeDirectory($(EmscriptenPythonToolsPath))) + $([MSBuild]::NormalizeDirectory($(EmSdkUpstreamBinPath))) + + + + + + + + + + <_EmscriptenAddPATH Condition="'$(EmscriptenPythonToolsPath)' != ''" Include="$(EmscriptenPythonToolsPath)bin" /> + <_EmscriptenAddPATH Include="$(EmscriptenSdkToolsPath)emscripten" /> + + + + <_EmscriptenAddPATH Include="$(EmscriptenSdkToolsPath)" /> + <_EmscriptenAddPATH Include="$(EmscriptenNodeToolsPath)bin" /> + <_EmscriptenAddPATH Include="$([MSBuild]::NormalizeDirectory($(EmscriptenSdkToolsPath), 'upstream', 'emscripten'))" /> + + + + + <_EmscriptenAddPATHFixed Include="%(_EmscriptenAddPATH.Identity)." + Condition="$([MSBuild]::ValueOrDefault('%(_EmscriptenAddPATH.Identity)', '').EndsWith('\'))" /> + <_EmscriptenAddPATHFixed Include="@(_EmscriptenAddPATH)" + Condition="!$([MSBuild]::ValueOrDefault('%(_EmscriptenAddPATH.Identity)', '').EndsWith('\'))" /> + <_EmscriptenAddPATH Remove="@(_EmscriptenAddPATH)" /> + <_EmscriptenAddPATH Include="@(_EmscriptenAddPATHFixed)" /> + + + + <_EmscriptenAddPATHProperty Condition="'$(OS)' == 'Windows_NT'">@(_EmscriptenAddPATH -> '%(Identity)', '%3B') + <_EmscriptenAddPATHProperty Condition="'$(OS)' != 'Windows_NT'">@(_EmscriptenAddPATH -> '%(Identity)', ':') + + + + + + + + + + + + Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for building native files." /> + Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for AOT'ing assemblies." /> true @@ -243,7 +342,7 @@ + Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for building native files." /> false @@ -291,7 +390,7 @@ - + $([MSBuild]::NormalizePath($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'src', 'emcc-flags.txt')) @@ -378,13 +477,13 @@ $(EmccCFlags) "-I$(_WasmIntermediateOutputPath)" $(EmccFlags) -s TOTAL_MEMORY=536870912 - <_WasmOptCommand>$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'upstream', 'bin', 'wasm-opt$(_ExeExt)')) + <_WasmOptCommand>$([MSBuild]::NormalizePath('$(EmSdkUpstreamBinPath)', 'wasm-opt$(_ExeExt)')) - - - + + + @@ -435,9 +534,9 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_ - + - +