From 812cb93edb6d5bcce76ac8a0a6aa2176b826b18d Mon Sep 17 00:00:00 2001 From: Pavel Savara Date: Wed, 10 Jul 2024 12:44:45 +0200 Subject: [PATCH] [WASI] use WASI_SDK22_PATH variable (#104379) --- eng/native/gen-buildsys.cmd | 13 ++++--- eng/native/gen-buildsys.sh | 3 +- eng/testing/tests.wasi.targets | 3 +- src/libraries/sendtohelix-wasi.targets | 13 ++++--- src/libraries/sendtohelixhelp.proj | 2 +- src/mono/Directory.Build.props | 11 ++---- src/mono/mono.proj | 37 ++++++++++++++----- src/mono/wasi/Makefile | 8 ++-- src/mono/wasi/README.md | 4 +- .../wasi/Wasi.Build.Tests/BuildTestBase.cs | 4 +- .../wasi/Wasi.Build.Tests/SdkMissingTests.cs | 2 +- src/mono/wasi/build/WasiApp.InTree.props | 1 - src/mono/wasi/build/WasiApp.targets | 6 +-- src/mono/wasi/build/WasiSdk.Defaults.props | 9 +++-- src/mono/wasi/provision.ps1 | 8 ++++ src/mono/wasi/wasi.proj | 19 +++++----- .../Common/EnvironmentVariables.cs | 2 +- src/mono/wasm/build/WasmApp.LocalBuild.props | 3 +- .../wasm/data/aot-tests/Directory.Build.props | 2 +- src/native/libs/build-native.sh | 12 +++--- 20 files changed, 94 insertions(+), 68 deletions(-) diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd index b81ef55cbe49b..2f1ef10a51e40 100644 --- a/eng/native/gen-buildsys.cmd +++ b/eng/native/gen-buildsys.cmd @@ -60,19 +60,20 @@ if /i "%__Arch%" == "wasm" ( set __UseEmcmake=1 ) if /i "%__Os%" == "wasi" ( - if "%WASI_SDK_PATH%" == "" ( + set "__repoRoot=!__repoRoot:\=/!" + if "%WASI_SDK22_PATH%" == "" ( if not exist "%__repoRoot%\src\mono\wasi\wasi-sdk" ( - echo Error: Should set WASI_SDK_PATH environment variable pointing to WASI SDK root. + echo Error: Should set WASI_SDK22_PATH environment variable pointing to WASI SDK root. exit /B 1 ) - set "WASI_SDK_PATH=%__repoRoot%\src\mono\wasi\wasi-sdk" + set "WASI_SDK22_PATH=%__repoRoot%\src\mono\wasi\wasi-sdk" ) :: replace backslash with forward slash and append last slash - set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!" - if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_PATH!/" + set "WASI_SDK22_PATH=!WASI_SDK22_PATH:\=/!" + if not "!WASI_SDK22_PATH:~-1!" == "/" set "WASI_SDK22_PATH=!WASI_SDK22_PATH!/" set __CmakeGenerator=Ninja - set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm "-DWASI_SDK_PREFIX=!WASI_SDK_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK_PATH!/share/cmake/wasi-sdk.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!/share/wasi-sysroot" + set __ExtraCmakeParams=%__ExtraCmakeParams% -DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm "-DWASI_SDK_PREFIX=!WASI_SDK22_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!WASI_SDK22_PATH!share/cmake/wasi-sdk.cmake" "-DCMAKE_SYSROOT=!WASI_SDK22_PATH!share/wasi-sysroot" ) ) else ( set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0" diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh index 4c1ed0943c45a..c4d79110b8c82 100755 --- a/eng/native/gen-buildsys.sh +++ b/eng/native/gen-buildsys.sh @@ -4,6 +4,7 @@ # scriptroot="$( cd -P "$( dirname "$0" )" && pwd )" +reporoot="$(cd "$scriptroot"/../..; pwd -P)" if [[ "$#" -lt 4 ]]; then echo "Usage..." @@ -97,7 +98,7 @@ if [[ "$host_arch" == "wasm" ]]; then if [[ "$target_os" == "browser" ]]; then cmake_command="emcmake $cmake_command" elif [[ "$target_os" == "wasi" ]]; then - true + cmake_extra_defines="$cmake_extra_defines -DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm -DWASI_SDK_PREFIX=$WASI_SDK22_PATH -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK22_PATH}share/cmake/wasi-sdk.cmake" "-DCMAKE_SYSROOT=${WASI_SDK22_PATH}share/wasi-sysroot" else echo "target_os was not specified" exit 1 diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets index d7183c26cb597..4aa0b76692dee 100644 --- a/eng/testing/tests.wasi.targets +++ b/eng/testing/tests.wasi.targets @@ -13,7 +13,8 @@ >true - $([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk')) + $([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) <_BundleAOTTestWasmAppForHelixDependsOn>$(_BundleAOTTestWasmAppForHelixDependsOn);PrepareForWasiBuildApp;_PrepareForAOTOnHelix diff --git a/src/libraries/sendtohelix-wasi.targets b/src/libraries/sendtohelix-wasi.targets index ff1b8f17b277f..dff72dccfe949 100644 --- a/src/libraries/sendtohelix-wasi.targets +++ b/src/libraries/sendtohelix-wasi.targets @@ -46,7 +46,8 @@ false false - $(RepoRoot)src\mono\wasi\wasi-sdk\ + $([MSBuild]::NormalizeDirectory($(RepoRoot), 'src', 'mono', 'wasi', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) $([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasi', 'build')) $(HelixDependenciesStagingPath)$(WorkItemPrefix)wasi-sdk $(HelixDependenciesStagingPath)$(WorkItemPrefix)wasmtime @@ -63,7 +64,7 @@ - + @@ -73,7 +74,7 @@ - + @@ -82,7 +83,7 @@ - + @@ -92,8 +93,8 @@ - - + + diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 3608f1cae63d0..4d44b54312bcb 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -355,7 +355,7 @@ diff --git a/src/mono/Directory.Build.props b/src/mono/Directory.Build.props index d97bf84a1da66..5181dd77d674e 100644 --- a/src/mono/Directory.Build.props +++ b/src/mono/Directory.Build.props @@ -32,14 +32,11 @@ $(ProvisionEmscriptenDir.Replace('\', '/')) - + - - $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk')) - $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/')) - true + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) + true diff --git a/src/mono/mono.proj b/src/mono/mono.proj index ceb783599086e..6166d92f8f487 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -125,7 +125,7 @@ - + @@ -302,7 +302,7 @@ JS_ENGINES = [NODE_JS] - + @@ -317,20 +317,36 @@ JS_ENGINES = [NODE_JS] https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-$(WasiSdkVersion)/wasi-sdk-$(WasiSdkVersion).0.m-mingw.tar.gz - - + - + + + + + + - + @@ -340,7 +356,7 @@ JS_ENGINES = [NODE_JS] %(_ActualVersionLines.Identity) %(_ExpectedVersionLines.Identity) - @@ -722,13 +738,14 @@ JS_ENGINES = [NODE_JS] $([MSBuild]::EnsureTrailingSlash('$(EMSDK_PATH)').Replace('\', '/')) - $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/')) + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) <_EmsdkEnvScriptPath>$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env$(ScriptExt)')) <_MonoCMakeConfigureCommand>cmake @(_MonoCMakeArgs, ' ') $(MonoCMakeExtraArgs) "$(MonoProjectRoot.TrimEnd('\/'))" <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(_MonoSkipInitCompiler)' != 'true' and '$(HostOS)' != 'windows'">sh -c 'build_arch="$(_CompilerTargetArch)" compiler="$(MonoCCompiler)" . "$(RepositoryEngineeringCommonDir)native/init-compiler.sh" && @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)' <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(_MonoSkipInitCompiler)' == 'true' and '$(HostOS)' != 'windows'">$(_MonoCCOption) $(_MonoCXXOption) @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand) - <_MonoCMakeConfigureCommand Condition="'$(TargetsWasi)' == 'true'">$(_MonoCMakeConfigureCommand) -DWASI_SDK_PREFIX=$(WASI_SDK_PATH) -DCMAKE_SYSROOT=$(WASI_SDK_PATH)share/wasi-sysroot -DCMAKE_TOOLCHAIN_FILE=$(WASI_SDK_PATH)share/cmake/wasi-sdk.cmake -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK_PATH)share/wasi-sysroot" + <_MonoCMakeConfigureCommand Condition="'$(TargetsWasi)' == 'true'">$(_MonoCMakeConfigureCommand) -DWASI_SDK_PREFIX=$(WASI_SDK22_PATH) -DCMAKE_SYSROOT=$(WASI_SDK22_PATH)share/wasi-sysroot -DCMAKE_TOOLCHAIN_FILE=$(WASI_SDK22_PATH)share/cmake/wasi-sdk.cmake -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK22_PATH)share/wasi-sysroot" <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(HostOS)' == 'windows'">call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" $(_CompilerTargetArch) && cd /D "$(MonoObjDir)" && @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand) <_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' == 'true' and '$(HostOS)' != 'windows'">bash -c 'source $(_EmsdkEnvScriptPath) 2>&1 && emcmake $(_MonoCMakeConfigureCommand)' @@ -924,7 +941,7 @@ JS_ENGINES = [NODE_JS] - + diff --git a/src/mono/wasi/build/WasiSdk.Defaults.props b/src/mono/wasi/build/WasiSdk.Defaults.props index eeebd23130e8d..4958eae7c8fdb 100644 --- a/src/mono/wasi/build/WasiSdk.Defaults.props +++ b/src/mono/wasi/build/WasiSdk.Defaults.props @@ -1,11 +1,12 @@ - $(WASI_SDK_PATH) - $([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'share', 'wasi-sysroot')) - $(WasiSdkRoot)\bin\clang + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) + $([MSBuild]::NormalizeDirectory($(WASI_SDK22_PATH), 'share', 'wasi-sysroot')) + $(WASI_SDK22_PATH)bin/clang $(WasiClang).exe - $([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'bin')) + $([MSBuild]::NormalizeDirectory($(WASI_SDK22_PATH), 'bin')) diff --git a/src/mono/wasi/provision.ps1 b/src/mono/wasi/provision.ps1 index ff336ef4bc22b..1a6f40cb462de 100644 --- a/src/mono/wasi/provision.ps1 +++ b/src/mono/wasi/provision.ps1 @@ -17,3 +17,11 @@ Invoke-WebRequest -Uri $WasiSdkUrl -OutFile ./wasi-sdk-$WasiSdkVersion.0-mingw.t tar --strip-components=1 -xzf ./wasi-sdk-$WasiSdkVersion.0-mingw.tar.gz -C $WasiSdkPath Copy-Item $WasiLocalPath/wasi-sdk-version.txt $WasiSdkPath/wasi-sdk-version.txt Remove-Item ./wasi-sdk-$WasiSdkVersion.0-mingw.tar.gz -fo + +# Temporary WASI-SDK 22 workaround #2: The version of `wasm-component-ld` that +# ships with WASI-SDK 22 contains a +# [bug](https://github.com/bytecodealliance/wasm-component-ld/issues/22) which +# has been fixed in a v0.5.3 of that utility, so we upgrade it here. +Invoke-WebRequest -Uri https://github.com/bytecodealliance/wasm-component-ld/releases/download/v0.5.3/wasm-component-ld-v0.5.3-x86_64-windows.zip -OutFile wasm-component-ld-v0.5.3-x86_64-windows.zip +Expand-Archive -LiteralPath wasm-component-ld-v0.5.3-x86_64-windows.zip -DestinationPath . +Copy-Item wasm-component-ld-v0.5.3-x86_64-windows/wasm-component-ld.exe $WasiSdkPath/bin \ No newline at end of file diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 99bf8a6ee54f8..7b50cd016833a 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -19,17 +19,18 @@ <_WasiCompileRspPath>$(NativeBinDir)src\wasi-compile.rsp <_WasiLinkRspPath>$(NativeBinDir)src\wasi-link.rsp false - $(WASI_SDK_PATH) - $(WasiSdkRoot)\bin\clang + $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) + $(WASI_SDK22_PATH)bin/clang $(WasiClang).exe - $(WasiSdkRoot)\bin\llvm-ar + $(WASI_SDK22_PATH)bin/llvm-ar $(WasiLLVMAr).exe - + @@ -205,8 +206,6 @@ $(WasiObjDir)\pinvoke-table.h $(WasiObjDir)\wasm_m2n_invoke.g.h - $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/')) - -g -Os -DDEBUG=1 -DENABLE_AOT_PROFILER=1 -Oz @@ -216,10 +215,10 @@ cmake $(MSBuildThisFileDirectory)runtime cmake -G Ninja $(MSBuildThisFileDirectory)runtime - $(CMakeBuildRuntimeConfigureCmd) --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE="$([MSBuild]::NormalizePath('$(WASI_SDK_PATH)', 'share/cmake/wasi-sdk.cmake'))" - $(CMakeBuildRuntimeConfigureCmd) -DWASI_SDK_PREFIX=$(WASI_SDK_PATH) - $(CMakeBuildRuntimeConfigureCmd) -DCMAKE_SYSROOT=$(WASI_SDK_PATH)share/wasi-sysroot - $(CMakeBuildRuntimeConfigureCmd) -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK_PATH)share/wasi-sysroot" + $(CMakeBuildRuntimeConfigureCmd) --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE="$([MSBuild]::NormalizePath('$(WASI_SDK22_PATH)', 'share/cmake/wasi-sdk.cmake'))" + $(CMakeBuildRuntimeConfigureCmd) -DWASI_SDK_PREFIX=$(WASI_SDK22_PATH) + $(CMakeBuildRuntimeConfigureCmd) -DCMAKE_SYSROOT=$(WASI_SDK22_PATH)share/wasi-sysroot + $(CMakeBuildRuntimeConfigureCmd) -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK22_PATH)share/wasi-sysroot" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_WASICC_FLAGS="$(CMakeConfigurationWasiFlags)" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_LINK_FLAGS="$(CMakeConfigurationLinkFlags)" diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs b/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs index e2cf9b3dbf8b4..25d96339c8cb2 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs @@ -23,7 +23,7 @@ internal static class EnvironmentVariables internal static readonly bool ShowBuildOutput = IsRunningOnCI || Environment.GetEnvironmentVariable("SHOW_BUILD_OUTPUT") is not null; internal static readonly bool UseWebcil = Environment.GetEnvironmentVariable("USE_WEBCIL_FOR_TESTS") is "true"; internal static readonly string? SdkDirName = Environment.GetEnvironmentVariable("SDK_DIR_NAME"); - internal static readonly string? WasiSdkPath = Environment.GetEnvironmentVariable("WASI_SDK_PATH"); + internal static readonly string? WasiSdkPath = Environment.GetEnvironmentVariable("WASI_SDK22_PATH"); internal static readonly bool WorkloadsTestPreviousVersions = Environment.GetEnvironmentVariable("WORKLOADS_TEST_PREVIOUS_VERSIONS") is "true"; } } diff --git a/src/mono/wasm/build/WasmApp.LocalBuild.props b/src/mono/wasm/build/WasmApp.LocalBuild.props index 3c81958b03722..bfdbdce919f65 100644 --- a/src/mono/wasm/build/WasmApp.LocalBuild.props +++ b/src/mono/wasm/build/WasmApp.LocalBuild.props @@ -30,7 +30,8 @@ $(RuntimeSrcDir)\artifacts\bin\ $(RuntimeSrcDir)\src\mono\browser\emsdk\ - $(RuntimeSrcDir)\src\mono\wasi\wasi-sdk\ + $([MSBuild]::NormalizeDirectory($(RuntimeSrcDir), 'src', 'mono', 'wasi', 'wasi-sdk')) + $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK22_PATH)').Replace('\', '/')) $([MSBuild]::NormalizeDirectory($(ArtifactsBinDir), 'microsoft.netcore.app.runtime.$(RuntimeIdentifier)', $(RuntimeConfig))) diff --git a/src/mono/wasm/data/aot-tests/Directory.Build.props b/src/mono/wasm/data/aot-tests/Directory.Build.props index c52f8028de5b1..4f6672b647b7d 100644 --- a/src/mono/wasm/data/aot-tests/Directory.Build.props +++ b/src/mono/wasm/data/aot-tests/Directory.Build.props @@ -10,7 +10,7 @@ <_WasmTargetsDir>$(WasmBuildSupportDir)\wasm\ <_WasmSharedDir>$(WasmBuildSupportDir)\wasm-shared\ $(WasmBuildSupportDir)\emsdk\ - $(WasmBuildSupportDir)\wasi-sdk\ + $(WasmBuildSupportDir)\wasi-sdk\ diff --git a/src/native/libs/build-native.sh b/src/native/libs/build-native.sh index d3fefa7685a97..bda22dc50d63f 100755 --- a/src/native/libs/build-native.sh +++ b/src/native/libs/build-native.sh @@ -65,18 +65,18 @@ if [[ "$__TargetOS" == browser ]]; then source "$EMSDK_PATH"/emsdk_env.sh export CLR_CC=$(which emcc) elif [[ "$__TargetOS" == wasi ]]; then - if [[ -z "$WASI_SDK_PATH" ]]; then + if [[ -z "$WASI_SDK22_PATH" ]]; then if [[ -d "$__RepoRootDir"/src/mono/wasi/wasi-sdk ]]; then - export WASI_SDK_PATH="$__RepoRootDir"/src/mono/wasi/wasi-sdk + export WASI_SDK22_PATH="$__RepoRootDir"/src/mono/wasi/wasi-sdk else - echo "Error: You need to set the WASI_SDK_PATH environment variable pointing to the WASI SDK root." + echo "Error: You need to set the WASI_SDK22_PATH environment variable pointing to the WASI SDK root." exit 1 fi fi - export WASI_SDK_PATH="${WASI_SDK_PATH%/}/" - export CLR_CC="$WASI_SDK_PATH"bin/clang + export WASI_SDK22_PATH="${WASI_SDK22_PATH%/}/" + export CLR_CC="$WASI_SDK22_PATH"bin/clang export TARGET_BUILD_ARCH=wasm - __CMakeArgs="-DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm -DWASI_SDK_PREFIX=$WASI_SDK_PATH -DCMAKE_TOOLCHAIN_FILE=$WASI_SDK_PATH/share/cmake/wasi-sdk.cmake $__CMakeArgs" + __CMakeArgs="-DCLR_CMAKE_TARGET_OS=wasi -DCLR_CMAKE_TARGET_ARCH=wasm -DWASI_SDK_PREFIX=$WASI_SDK22_PATH -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK22_PATH}share/cmake/wasi-sdk.cmake $__CMakeArgs" elif [[ "$__TargetOS" == ios || "$__TargetOS" == iossimulator ]]; then # nothing to do here true