Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug wasip2 2 #104143

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion eng/native/gen-buildsys.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ if /i "%__Arch%" == "wasm" (
set __UseEmcmake=1
)
if /i "%__Os%" == "wasi" (
set "__repoRoot=!__repoRoot:\=/!"
if "%WASI_SDK_PATH%" == "" (
if not exist "%__repoRoot%\src\mono\wasi\wasi-sdk" (
echo Error: Should set WASI_SDK_PATH environment variable pointing to WASI SDK root.
Expand All @@ -72,7 +73,7 @@ if /i "%__Arch%" == "wasm" (
set "WASI_SDK_PATH=!WASI_SDK_PATH:\=/!"
if not "!WASI_SDK_PATH:~-1!" == "/" set "WASI_SDK_PATH=!WASI_SDK_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_SDK_PATH!" "-DCMAKE_TOOLCHAIN_FILE=!__repoRoot!/src/native/external/wasi-sdk-p2.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!/share/wasi-sysroot"
)
) else (
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0"
Expand Down
3 changes: 2 additions & 1 deletion eng/native/gen-buildsys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#

scriptroot="$( cd -P "$( dirname "$0" )" && pwd )"
reporoot="$(cd "$scriptroot"/../..; pwd -P)"

if [[ "$#" -lt 4 ]]; then
echo "Usage..."
Expand Down Expand Up @@ -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_SDK_PATH -DCMAKE_TOOLCHAIN_FILE=$reporoot/src/native/external/wasi-sdk-p2.cmake" "-DCMAKE_SYSROOT=!WASI_SDK_PATH!/share/wasi-sysroot"
else
echo "target_os was not specified"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/mono/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ if(NOT AOT_TARGET_TRIPLE STREQUAL "")
elseif(AOT_TARGET_TRIPLE STREQUAL "wasm32-unknown-none")
set(TARGET_SYSTEM_NAME "emscripten")
set(TARGET_ARCH "wasm")
elseif(AOT_TARGET_TRIPLE STREQUAL "wasm32-unknown-wasi")
elseif(AOT_TARGET_TRIPLE STREQUAL "wasm32-unknown-wasip2")
set(TARGET_SYSTEM_NAME "wasi")
set(TARGET_ARCH "wasm")
elseif(AOT_TARGET_TRIPLE STREQUAL "x86_64-none-linux-android")
Expand Down
5 changes: 1 addition & 4 deletions src/mono/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@

<!-- Directory to provision and use WASI sdk if WASI_SDK_PATH env variable is not set -->
<PropertyGroup Condition="'$(TargetsWasi)' == 'true'">
<!-- force download temmporarily https://github.com/dotnet/runtime/issues/101528
<WASI_SDK_PATH Condition="'$(WASI_SDK_PATH)' == ''">$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
-->
<WASI_SDK_PATH>$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
<WASI_SDK_PATH>$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))</WASI_SDK_PATH>
<ShouldProvisionWasiSdk Condition="!Exists($(_ProvisionWasiSdkDir))">true</ShouldProvisionWasiSdk>
<ShouldProvisionWasiSdk Condition="!Exists($(WASI_SDK_PATH))">true</ShouldProvisionWasiSdk>
</PropertyGroup>

<PropertyGroup>
Expand Down
20 changes: 18 additions & 2 deletions src/mono/mono.proj
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,26 @@ JS_ENGINES = [NODE_JS]
WorkingDirectory="$(ArtifactsObjDir)"
IgnoreStandardErrorWarningFormat="true" />

<!--
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.
-->
<Exec Command="curl -L -o wasm-component-ld-v0.5.4-x86_64-linux.tar.gz https://github.com/bytecodealliance/wasm-component-ld/releases/download/v0.5.4/wasm-component-ld-v0.5.4-x86_64-linux.tar.gz &amp;&amp; mkdir -p $(WASI_SDK_PATH)/wasm-component &amp;&amp; tar --strip-components=1 -xzf wasm-component-ld-v0.5.4-x86_64-linux.tar.gz -C $(WASI_SDK_PATH)/wasm-component &amp;&amp; cp $(WASI_SDK_PATH)/wasm-component/wasm-component-ld $(WASI_SDK_PATH)/bin/wasm-component-ld"
Condition="'$(HostOS)' != 'windows'"
WorkingDirectory="$(ArtifactsObjDir)"
IgnoreStandardErrorWarningFormat="true" />

<Exec Command="powershell -NonInteractive -command &quot;&amp; $(WasiLocalPath)\provision.ps1 -WasiSdkUrl $(WasiSdkUrl) -WasiSdkVersion $(WasiSdkVersion) -WasiSdkPath $(WASI_SDK_PATH) -WasiLocalPath $(WasiLocalPath); Exit $LastExitCode &quot;"
Condition="'$(HostOS)' == 'windows'"
WorkingDirectory="$(ArtifactsObjDir)"
IgnoreStandardErrorWarningFormat="true" />

<Copy SourceFiles="$(MSBuildThisFileDirectory)/wasi/wasi-sdk/share/wasi-sysroot/include/wasm32-wasi-threads/pthread.h"
DestinationFiles="$(MSBuildThisFileDirectory)/wasi/wasi-sdk/share/wasi-sysroot/include/wasm32-wasip2/pthread.h"
/>

</Target>

<Target Name="ValidateWasiSdk" Condition="'$(SkipMonoCrossJitConfigure)' != 'true'">
Expand Down Expand Up @@ -728,7 +744,7 @@ JS_ENGINES = [NODE_JS]
<_MonoCMakeConfigureCommand>cmake @(_MonoCMakeArgs, ' ') $(MonoCMakeExtraArgs) &quot;$(MonoProjectRoot.TrimEnd('\/'))&quot;</_MonoCMakeConfigureCommand>
<_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(_MonoSkipInitCompiler)' != 'true' and '$(HostOS)' != 'windows'">sh -c 'build_arch=&quot;$(_CompilerTargetArch)&quot; compiler=&quot;$(MonoCCompiler)&quot; . &quot;$(RepositoryEngineeringCommonDir)native/init-compiler.sh&quot; &amp;&amp; @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)'</_MonoCMakeConfigureCommand>
<_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(_MonoSkipInitCompiler)' == 'true' and '$(HostOS)' != 'windows'">$(_MonoCCOption) $(_MonoCXXOption) @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)</_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>
<_MonoCMakeConfigureCommand Condition="'$(TargetsWasi)' == 'true'">$(_MonoCMakeConfigureCommand) -DWASI_SDK_PREFIX=$(WASI_SDK_PATH) -DCMAKE_SYSROOT=$(WASI_SDK_PATH)share/wasi-sysroot -DCMAKE_TOOLCHAIN_FILE=$(RepoRoot)src/native/external/wasi-sdk-p2.cmake -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK_PATH)share/wasi-sysroot"</_MonoCMakeConfigureCommand>

<_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' != 'true' and '$(TargetsWasi)' != 'true' and '$(HostOS)' == 'windows'">call &quot;$(RepositoryEngineeringDir)native\init-vs-env.cmd&quot; $(_CompilerTargetArch) &amp;&amp; cd /D &quot;$(MonoObjDir)&quot; &amp;&amp; @(_MonoBuildEnv, ' ') $(_MonoCMakeConfigureCommand)</_MonoCMakeConfigureCommand>
<_MonoCMakeConfigureCommand Condition="'$(TargetsBrowser)' == 'true' and '$(HostOS)' != 'windows'">bash -c 'source $(_EmsdkEnvScriptPath) 2>&amp;1 &amp;&amp; emcmake $(_MonoCMakeConfigureCommand)'</_MonoCMakeConfigureCommand>
Expand Down Expand Up @@ -851,7 +867,7 @@ JS_ENGINES = [NODE_JS]
<PropertyGroup Condition="'$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'">
<MonoUseCrossTool>true</MonoUseCrossTool>
<MonoAotAbi Condition="'$(TargetsBrowser)' == 'true'">wasm32-unknown-none</MonoAotAbi>
<MonoAotAbi Condition="'$(TargetsWasi)' == 'true'">wasm32-unknown-wasi</MonoAotAbi>
<MonoAotAbi Condition="'$(TargetsWasi)' == 'true'">wasm32-unknown-wasip2</MonoAotAbi>
<MonoAotOffsetsFile>$(MonoObjCrossDir)offsets-wasm32-unknown-none.h</MonoAotOffsetsFile>
<MonoLibClang Condition="$([MSBuild]::IsOSPlatform('OSX'))">$(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.dylib</MonoLibClang>
<MonoLibClang Condition="$([MSBuild]::IsOSPlatform('Linux'))">$(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.so</MonoLibClang>
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/mini-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef struct {
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-m:e-p:32:32-i64:64-n32:64-S128"
#ifdef TARGET_WASI
#define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-wasi"
#define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-wasip2"
#else
#define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-emscripten"
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/tools/offsets-tool/offsets-tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def require_emscipten_path (args):
if "wasm" in args.abi:
if args.wasi_path != None:
require_sysroot (args)
self.sys_includes = [args.wasi_path + "/share/wasi-sysroot/include", args.wasi_path + "/lib/clang/18/include", args.mono_path + "/wasi/mono-include"]
self.sys_includes = [args.wasi_path + "/share/wasi-sysroot/include/wasm32-wasip2", args.wasi_path + "/lib/clang/18/include", args.mono_path + "/wasi/mono-include"]
self.target = Target ("TARGET_WASI", None, ["TARGET_WASM"] + WASI_DEFINES)
self.target_args += ["-target", args.abi]
self.target_args += ["--sysroot", args.sysroot]
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasi/build/WasiApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
</Target>

<Target Name="_PrepareForWasiBuildNative">
<Error Condition="'$(_IsToolchainMissing)' == 'true'"

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime (Build wasi-wasm linux Release LibraryTests_Smoke)

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.

Check failure on line 116 in src/mono/wasi/build/WasiApp.targets

View check run for this annotation

Azure Pipelines / runtime

src/mono/wasi/build/WasiApp.targets#L116

src/mono/wasi/build/WasiApp.targets(116,5): error : (NETCORE_ENGINEERING_TELEMETRY=Build) Using WASI_SDK_PATH=/__w/1/s/src/mono/wasi/wasi/wasi-sdk/, cannot find $(WasiClang)=/bin/clang . SDK is required for building native files.
Text="$(_ToolchainMissingErrorMessage) SDK is required for building native files." />

<PropertyGroup>
Expand Down Expand Up @@ -323,8 +323,8 @@
<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmEHLibToExclude)" />
<_WasmNativeFileForLinking Remove="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(_WasmSIMDLibToExclude)" />

<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++.a" />
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasi\libc++abi.a" />
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasip2\libc++.a" />
<_WasmNativeFileForLinking Include="$(WasiSysRoot)\lib\wasm32-wasip2\libc++abi.a" />

<_WasmNativeFileForLinking Include="@(NativeFileReference)" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasi/build/WasiSdk.Defaults.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<PropertyGroup>
<WasiSdkRoot Condition="'$(WasiSdkRoot)' == ''">$(WASI_SDK_PATH)</WasiSdkRoot>
<WASI_SDK_PATH>$([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'wasi', 'wasi-sdk'))</WASI_SDK_PATH>
<WASI_SDK_PATH>$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))</WASI_SDK_PATH>
<WasiSysRoot>$([MSBuild]::NormalizeDirectory($(WasiSdkRoot), 'share', 'wasi-sysroot'))</WasiSysRoot>
<WasiClang>$(WasiSdkRoot)\bin\clang</WasiClang>
<WasiClang Condition="$([MSBuild]::IsOSPlatform('Windows'))">$(WasiClang).exe</WasiClang>
Expand Down
8 changes: 8 additions & 0 deletions src/mono/wasi/provision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions src/mono/wasi/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ set_target_properties(dotnet PROPERTIES COMPILE_FLAGS ${CONFIGURATION_WASICC_FLA

target_link_libraries(dotnet
PRIVATE
${CMAKE_SYSROOT}/lib/wasm32-wasi/libc++.a
${CMAKE_SYSROOT}/lib/wasm32-wasi/libc++abi.a
${CMAKE_SYSROOT}/lib/wasm32-wasip2/libc++.a
${CMAKE_SYSROOT}/lib/wasm32-wasip2/libc++abi.a
${ICU_LIB_DIR}/libicudata.a
${ICU_LIB_DIR}/libicuuc.a
${ICU_LIB_DIR}/libicui18n.a
Expand Down
5 changes: 4 additions & 1 deletion src/mono/wasi/wasi.proj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
</PropertyGroup>

<Target Name="CheckEnv">
<Message Importance="high" Text="[DEBUG] WASI_SDK_PATH=$(WASI_SDK_PATH); WasiSdkRoot=$(WasiSdkRoot); WasiClang=$(WasiClang)"/>
<Error Condition="'$(TargetArchitecture)' != 'wasm'" Text="Expected TargetArchitecture==wasm, got '$(TargetArchitecture)'"/>
<Error Condition="'$(TargetOS)' != 'wasi'" Text="Expected TargetOS==wasi, got '$(TargetOS)'"/>
<Error Condition="'$(WASI_SDK_PATH)' == ''" Text="The WASI_SDK_PATH environment variable should be set pointing to the WASI SDK root dir."/>
Expand Down Expand Up @@ -210,12 +211,14 @@
<CMakeConfigurationWasiFlags Condition="'$(Configuration)' == 'Release'">-Oz </CMakeConfigurationWasiFlags>

<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Debug'" >$(CMakeConfigurationWasiFlags)</CMakeConfigurationLinkFlags>
<!-- wasm-opt doesn't know how to parse wasm component
<CMakeConfigurationLinkFlags Condition="'$(Configuration)' == 'Release'">-O2</CMakeConfigurationLinkFlags>
-->

<CMakeBuildRuntimeConfigureCmd>cmake $(MSBuildThisFileDirectory)runtime</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd Condition="'$(OS)' == 'Windows_NT'">cmake -G Ninja $(MSBuildThisFileDirectory)runtime</CMakeBuildRuntimeConfigureCmd>

<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=&quot;$([MSBuild]::NormalizePath('$(WASI_SDK_PATH)', 'share/cmake/wasi-sdk.cmake'))&quot;</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE=&quot;$([MSBuild]::NormalizePath('$(RepoRoot)', 'src/native/external/wasi-sdk-p2.cmake'))&quot;</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) -DWASI_SDK_PREFIX=$(WASI_SDK_PATH)</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) -DCMAKE_SYSROOT=$(WASI_SDK_PATH)share/wasi-sysroot</CMakeBuildRuntimeConfigureCmd>
<CMakeBuildRuntimeConfigureCmd>$(CMakeBuildRuntimeConfigureCmd) -DCMAKE_CXX_FLAGS="--sysroot=$(WASI_SDK_PATH)share/wasi-sysroot"</CMakeBuildRuntimeConfigureCmd>
Expand Down
45 changes: 45 additions & 0 deletions src/native/external/wasi-sdk-p2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# TODO: WASI-SDK doesn't provide a CMake toolchain file for `wasm32-wasip2`, so
# we must provide it ourselves. Once
# https://github.com/WebAssembly/wasi-sdk/pull/430 is merged and included in an
# upcoming release, we'll be able to remove this file and use that instead.

# Cmake toolchain description file for the Makefile

# This is arbitrary, AFAIK, for now.
cmake_minimum_required(VERSION 3.5.0)

# Until Platform/WASI.cmake is upstream we need to inject the path to it
# into CMAKE_MODULE_PATH.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

set(CMAKE_SYSTEM_NAME WASI)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR wasm32)
set(triple wasm32-wasip2)

if(WIN32)
set(WASI_HOST_EXE_SUFFIX ".exe")
else()
set(WASI_HOST_EXE_SUFFIX "")
endif()

# When building from source, WASI_SDK_PREFIX represents the generated directory
if(NOT WASI_SDK_PREFIX)
set(WASI_SDK_PREFIX ${CMAKE_CURRENT_LIST_DIR}/../../)
endif()

set(CMAKE_C_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
set(CMAKE_CXX_COMPILER ${WASI_SDK_PREFIX}/bin/clang++${WASI_HOST_EXE_SUFFIX})
set(CMAKE_ASM_COMPILER ${WASI_SDK_PREFIX}/bin/clang${WASI_HOST_EXE_SUFFIX})
set(CMAKE_AR ${WASI_SDK_PREFIX}/bin/llvm-ar${WASI_HOST_EXE_SUFFIX})
set(CMAKE_RANLIB ${WASI_SDK_PREFIX}/bin/llvm-ranlib${WASI_HOST_EXE_SUFFIX})
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_ASM_COMPILER_TARGET ${triple})

# Don't look in the sysroot for executables to run during the build
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# Only look in the sysroot (not in the host paths) for the rest
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
Loading