diff --git a/eng/native/gen-buildsys.cmd b/eng/native/gen-buildsys.cmd
index 6f243bd053afb1..6c46cfc5df4e55 100644
--- a/eng/native/gen-buildsys.cmd
+++ b/eng/native/gen-buildsys.cmd
@@ -61,6 +61,7 @@ if /i "%__Arch%" == "wasm" (
)
if /i "%__Os%" == "wasi" (
set "__repoRoot=!__repoRoot:\=/!"
+ if not "!__repoRoot:~-1!" == "/" 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.
@@ -73,7 +74,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" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1"
)
) else (
set __ExtraCmakeParams=%__ExtraCmakeParams% "-DCMAKE_SYSTEM_VERSION=10.0"
diff --git a/eng/native/gen-buildsys.sh b/eng/native/gen-buildsys.sh
index 91690a64837d49..c604597da05e01 100755
--- a/eng/native/gen-buildsys.sh
+++ b/eng/native/gen-buildsys.sh
@@ -94,11 +94,12 @@ if [[ "$scan_build" == "ON" && -n "$SCAN_BUILD_COMMAND" ]]; then
cmake_command="$SCAN_BUILD_COMMAND $cmake_command"
fi
+cmake_extra_defines_wasm=()
if [[ "$host_arch" == "wasm" ]]; then
if [[ "$target_os" == "browser" ]]; then
cmake_command="emcmake $cmake_command"
elif [[ "$target_os" == "wasi" ]]; then
- 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=${WASI_SDK_PATH}share/cmake/wasi-sdk.cmake" "-DCMAKE_SYSROOT=${WASI_SDK_PATH}share/wasi-sysroot"
+ cmake_extra_defines_wasm=("-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" "-DCMAKE_CROSSCOMPILING_EMULATOR=node --experimental-wasm-bigint --experimental-wasi-unstable-preview1")
else
echo "target_os was not specified"
exit 1
@@ -112,6 +113,7 @@ $cmake_command \
"-DCMAKE_INSTALL_PREFIX=$__CMakeBinDir" \
$cmake_extra_defines \
$__UnprocessedCMakeArgs \
+ "${cmake_extra_defines_wasm[@]}" \
-S "$1" \
-B "$2"
diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets
index 17fc47b5087fbe..47d68ce7abe6fb 100644
--- a/eng/testing/tests.wasi.targets
+++ b/eng/testing/tests.wasi.targets
@@ -13,7 +13,7 @@
>true
- $([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(MonoProjectRoot), 'wasi', 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
<_BundleAOTTestWasmAppForHelixDependsOn>$(_BundleAOTTestWasmAppForHelixDependsOn);PrepareForWasiBuildApp;_PrepareForAOTOnHelix
diff --git a/src/libraries/sendtohelix-wasi.targets b/src/libraries/sendtohelix-wasi.targets
index 5382266664af81..e0cd49d2534b51 100644
--- a/src/libraries/sendtohelix-wasi.targets
+++ b/src/libraries/sendtohelix-wasi.targets
@@ -46,7 +46,7 @@
false
false
- $([MSBuild]::NormalizeDirectory($(RepoRoot), 'src', 'mono', 'wasi', 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(RepoRoot), 'src', 'mono', 'wasi', 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'src', 'mono', 'wasi', 'build'))
$(HelixDependenciesStagingPath)$(WorkItemPrefix)wasi-sdk
diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt
index fac1d9fb0e33ca..8fe845296e0355 100644
--- a/src/mono/CMakeLists.txt
+++ b/src/mono/CMakeLists.txt
@@ -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")
diff --git a/src/mono/Directory.Build.props b/src/mono/Directory.Build.props
index 64b6d0288a6795..b0d654a0e5656b 100644
--- a/src/mono/Directory.Build.props
+++ b/src/mono/Directory.Build.props
@@ -34,9 +34,9 @@
- $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi', 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
- true
+ true
diff --git a/src/mono/mono.proj b/src/mono/mono.proj
index fcc05114ccbc8b..de2859eef88f49 100644
--- a/src/mono/mono.proj
+++ b/src/mono/mono.proj
@@ -324,8 +324,8 @@ JS_ENGINES = [NODE_JS]
IgnoreStandardErrorWarningFormat="true" />
@@ -339,10 +339,18 @@ JS_ENGINES = [NODE_JS]
WorkingDirectory="$(ArtifactsObjDir)"
IgnoreStandardErrorWarningFormat="true" />
-
+
+
+
+
@@ -358,6 +366,16 @@ JS_ENGINES = [NODE_JS]
+
+
+
+
+
+
@@ -743,7 +761,7 @@ JS_ENGINES = [NODE_JS]
<_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_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 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)'
@@ -866,7 +884,7 @@ JS_ENGINES = [NODE_JS]
true
wasm32-unknown-none
- wasm32-unknown-wasi
+ wasm32-unknown-wasip2
$(MonoObjCrossDir)offsets-wasm32-unknown-none.h
$(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.dylib
$(MonoLLVMDir)/$(BuildArchitecture)/lib/libclang.so
diff --git a/src/mono/mono/mini/mini-wasm.h b/src/mono/mono/mini/mini-wasm.h
index 95bafda3336c04..cef95c98ed4fe5 100644
--- a/src/mono/mono/mini/mini-wasm.h
+++ b/src/mono/mono/mini/mini-wasm.h
@@ -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
diff --git a/src/mono/sample/wasi/Directory.Build.targets b/src/mono/sample/wasi/Directory.Build.targets
index 75af1e423eef42..c40891fa247978 100644
--- a/src/mono/sample/wasi/Directory.Build.targets
+++ b/src/mono/sample/wasi/Directory.Build.targets
@@ -6,7 +6,8 @@
<_SampleProject Condition="'$(_SampleProject)' == ''">$(MSBuildProjectFile)
<_SampleAssembly Condition="'$(_SampleAssembly)' == ''">$(TargetFileName)
<_SampleProjectName>$([System.String]::Copy('$(_SampleProject)').Replace('.csproj',''))
- --env MONO_LOG_LEVEL=debug --env MONO_LOG_MASK=all
+ <_MONO_LOG_LEVEL Condition="false">--env MONO_LOG_LEVEL=debug --env MONO_LOG_MASK=all
+ <_DOTNET_WASI_PRINT_EXIT_CODE>--env DOTNET_WASI_PRINT_EXIT_CODE=1
<_ExeExt Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">.exe
@@ -14,15 +15,19 @@
-
-
-
+
+
+ <_DotnetWasmName>dotnet.wasm
+ <_DotnetWasmName Condition="'$(WasmSingleFileBundle)' == 'true'">$([System.IO.Path]::ChangeExtension($(_SampleAssembly), '.wasm'))
+ <_AppBundlePath>$([MSBuild]::NormalizeDirectory('bin/wasi-wasm/AppBundle'))
+ $(WasmtimeDir)wasmtime$(_ExeExt) $(_MONO_LOG_LEVEL) $(_DOTNET_WASI_PRINT_EXIT_CODE)
+ $(WasiCommand) --dir . $(_DotnetWasmName) $(_SampleProjectName)
+ $(WasiCommand) --dir . $(_DotnetWasmName)
+ $(WasiCommand) $(_DotnetWasmName)
+
+
+
+
diff --git a/src/mono/wasi/.gitignore b/src/mono/wasi/.gitignore
index c2313f66ee085a..fd086a6fb9c729 100644
--- a/src/mono/wasi/.gitignore
+++ b/src/mono/wasi/.gitignore
@@ -1,2 +1,2 @@
wasi-sdk/**
-wasmtime/**
+wasmtime/**
\ No newline at end of file
diff --git a/src/mono/wasi/Makefile b/src/mono/wasi/Makefile
index 7fc6904bc0702f..13e2d9cb613ea1 100644
--- a/src/mono/wasi/Makefile
+++ b/src/mono/wasi/Makefile
@@ -119,6 +119,3 @@ build-dbg-testsuite:
$(DOTNET) build $(TOP)/src/mono/wasm/debugger/DebuggerTestSuite $(MSBUILD_ARGS)
build-app-host:
$(DOTNET) build $(TOP)/src/mono/wasm/host $(_MSBUILD_WASM_BUILD_ARGS) $(MSBUILD_ARGS)
-
-patch-deterministic:
- cd emsdk/upstream/emscripten/ && patch -p1 < ../../../runtime/deterministic.diff
diff --git a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
index 0511818c5e2f33..0920103041db88 100644
--- a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
+++ b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
@@ -162,8 +162,6 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages =
{DefaultTargetFramework}
wasi-wasm
Exe
- true
- test-main.js
##EXTRA_PROPERTIES##
@@ -177,7 +175,6 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
if (buildArgs.AOT)
{
extraProperties = $"{extraProperties}\ntrue";
- extraProperties += $"\n{RuntimeInformation.IsOSPlatform(OSPlatform.Windows)}\n";
}
string projectContents = projectTemplate
@@ -265,8 +262,6 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
AssertBasicAppBundle(bundleDir,
buildArgs.ProjectName,
buildArgs.Config,
- options.MainJS ?? "test-main.js",
- options.HasV8Script,
options.TargetFramework ?? DefaultTargetFramework,
options.HasIcudt,
options.DotnetWasmFromRuntimePack ?? !buildArgs.AOT);
@@ -362,8 +357,6 @@ static void AssertRuntimePackPath(string buildOutput, string targetFramework)
protected static void AssertBasicAppBundle(string bundleDir,
string projectName,
string config,
- string mainJS,
- bool hasV8Script,
string targetFramework,
bool hasIcudt = true,
bool dotnetWasmFromRuntimePack = true)
@@ -371,14 +364,11 @@ protected static void AssertBasicAppBundle(string bundleDir,
#if false
AssertFilesExist(bundleDir, new []
{
- "index.html",
- mainJS,
"dotnet.wasm",
"_framework/blazor.boot.json",
"dotnet.js"
});
- AssertFilesExist(bundleDir, new[] { "run-v8.sh" }, expectToExist: hasV8Script);
AssertFilesExist(bundleDir, new[] { "icudt.dat" }, expectToExist: hasIcudt);
string managedDir = Path.Combine(bundleDir, "managed");
@@ -705,10 +695,9 @@ public static int Main()
protected CommandResult RunWithoutBuild(string config, string id)
{
- string runArgs = $"run --no-build -c {config}";
+ string runArgs = $"run --no-build -c {config} --forward-exit-code";
runArgs += " x y z";
- // ActiveIssue: https://github.com/dotnet/runtime/issues/82515
- int expectedExitCode = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 1 : 42;
+ int expectedExitCode = 42;
CommandResult res = new RunCommand(s_buildEnv, _testOutput, label: id)
.WithWorkingDirectory(_projectDir!)
.ExecuteWithCapturedOutput(runArgs)
@@ -740,11 +729,9 @@ public record BuildProjectOptions
bool CreateProject = true,
bool Publish = true,
bool BuildOnlyAfterPublish = true,
- bool HasV8Script = true,
string? Verbosity = null,
string? Label = null,
string? TargetFramework = null,
- string? MainJS = null,
IDictionary? ExtraBuildEnvironmentVariables = null
);
diff --git a/src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj b/src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj
index f5a98f4f0e01f4..f316261c14cdbe 100644
--- a/src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj
+++ b/src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj
@@ -92,7 +92,7 @@
-
+
diff --git a/src/mono/wasi/build/WasiApp.InTree.targets b/src/mono/wasi/build/WasiApp.InTree.targets
index 5a48423781d861..6d67a76da98035 100644
--- a/src/mono/wasi/build/WasiApp.InTree.targets
+++ b/src/mono/wasi/build/WasiApp.InTree.targets
@@ -10,14 +10,6 @@
-
- <_WasmMainJSFileName>$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))
-
-
-
-
-
-
diff --git a/src/mono/wasi/build/WasiApp.targets b/src/mono/wasi/build/WasiApp.targets
index b0e3e047eac201..ca8d1e72b83fc8 100644
--- a/src/mono/wasi/build/WasiApp.targets
+++ b/src/mono/wasi/build/WasiApp.targets
@@ -101,7 +101,7 @@
- <_ToolchainMissingErrorMessage Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/VERSION')">Could not find wasi-sdk. Install wasi-sdk and set %24(WASI_SDK_PATH) . It can be obtained from https://github.com/WebAssembly/wasi-sdk/releases
+ <_ToolchainMissingErrorMessage Condition="'$(WASI_SDK_PATH)' == '' or !Exists('$(WASI_SDK_PATH)/VERSION22PATCHED')">Could not find wasi-sdk. Install wasi-sdk and set %24(WASI_SDK_PATH) . It can be obtained from https://github.com/WebAssembly/wasi-sdk/releases
<_ToolchainMissingErrorMessage Condition="'$(_ToolchainMissingErrorMessage)' == '' and '$(_ToolchainMissingPaths)' != ''">Using WASI_SDK_PATH=$(WASI_SDK_PATH), cannot find $(_ToolchainMissingPaths) .
<_IsToolchainMissing Condition="'$(_ToolchainMissingErrorMessage)' != ''">true
@@ -185,6 +185,7 @@
<_WasiClangCommonFlags Include="$(_DefaultWasiClangFlags)" />
<_WasiClangCommonFlags Include="$(WasiClangFlags)" />
<_WasiClangCommonFlags Include="--sysroot="$(WASI_SDK_PATH.Replace('\', '/'))share/wasi-sysroot"" />
+ <_WasiClangCommonFlags Include="--target=wasm32-unknown-wasip2" />
<_WasiClangCommonFlags Include="-g" Condition="'$(WasmNativeStrip)' == 'false'" />
<_WasiClangCommonFlags Include="-v" Condition="'$(WasiClangVerbose)' != 'false'" />
@@ -325,8 +326,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)" />
diff --git a/src/mono/wasi/build/WasiSdk.Defaults.props b/src/mono/wasi/build/WasiSdk.Defaults.props
index 217cf5726cdcf4..bb73c7f5479cb0 100644
--- a/src/mono/wasi/build/WasiSdk.Defaults.props
+++ b/src/mono/wasi/build/WasiSdk.Defaults.props
@@ -1,6 +1,6 @@
- $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), '..', 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
$([MSBuild]::NormalizeDirectory($(WASI_SDK_PATH), 'share', 'wasi-sysroot'))
$(WASI_SDK_PATH)bin/clang
diff --git a/src/mono/wasi/mono-include/pthread.h b/src/mono/wasi/mono-include/pthread.h
deleted file mode 100644
index a5ea63882e7b9c..00000000000000
--- a/src/mono/wasi/mono-include/pthread.h
+++ /dev/null
@@ -1,230 +0,0 @@
-// This file is multi-licensed:
-// Apache-2.0: https://github.com/WebAssembly/wasi-libc/blob/main/LICENSE-APACHE
-// MIT: https://github.com/WebAssembly/wasi-libc/blob/main/LICENSE-MIT
-
-// This file is duplicated from https://github.com/WebAssembly/wasi-libc/blob/ad5133410f66b93a2381db5b542aad5e0964db96/libc-top-half/musl/include/pthread.h
-// with small edits for compatibility. We may be able to remove it once https://github.com/WebAssembly/wasi-libc/issues/209 is resolved
-
-// The WASI SDK doesn't include pthread.h, but the definitions are required by various parts of the Mono sources
-// On certain runtimes such as WAMR there is actually an implementation provided for the pthread APIs so threading
-// does work. However that's not yet in the WASI standard, so we're not yet relying on being able to call the ones
-// that really start up new threads.
-
-#ifndef _PTHREAD_H
-#define _PTHREAD_H
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include
-
-#define __NEED_time_t
-#define __NEED_clockid_t
-#define __NEED_struct_timespec
-#define __NEED_sigset_t
-#define __NEED_pthread_t
-#define __NEED_pthread_attr_t
-#define __NEED_pthread_mutexattr_t
-#define __NEED_pthread_condattr_t
-#define __NEED_pthread_rwlockattr_t
-#define __NEED_pthread_barrierattr_t
-#define __NEED_pthread_mutex_t
-#define __NEED_pthread_cond_t
-#define __NEED_pthread_rwlock_t
-#define __NEED_pthread_barrier_t
-#define __NEED_pthread_spinlock_t
-#define __NEED_pthread_key_t
-#define __NEED_pthread_once_t
-#define __NEED_size_t
-
-#include
-
-#include
-#include
-
-#define PTHREAD_CREATE_JOINABLE 0
-#define PTHREAD_CREATE_DETACHED 1
-
-#define PTHREAD_MUTEX_NORMAL 0
-#define PTHREAD_MUTEX_DEFAULT 0
-#define PTHREAD_MUTEX_RECURSIVE 1
-#define PTHREAD_MUTEX_ERRORCHECK 2
-
-#define PTHREAD_MUTEX_STALLED 0
-#define PTHREAD_MUTEX_ROBUST 1
-
-#define PTHREAD_PRIO_NONE 0
-#define PTHREAD_PRIO_INHERIT 1
-#define PTHREAD_PRIO_PROTECT 2
-
-#define PTHREAD_INHERIT_SCHED 0
-#define PTHREAD_EXPLICIT_SCHED 1
-
-#define PTHREAD_SCOPE_SYSTEM 0
-#define PTHREAD_SCOPE_PROCESS 1
-
-#define PTHREAD_PROCESS_PRIVATE 0
-#define PTHREAD_PROCESS_SHARED 1
-
-
-#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
-#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
-#define PTHREAD_COND_INITIALIZER {{{0}}}
-#define PTHREAD_ONCE_INIT 0
-
-
-#define PTHREAD_CANCEL_ENABLE 0
-#define PTHREAD_CANCEL_DISABLE 1
-#define PTHREAD_CANCEL_MASKED 2
-
-#define PTHREAD_CANCEL_DEFERRED 0
-#define PTHREAD_CANCEL_ASYNCHRONOUS 1
-
-#define PTHREAD_CANCELED ((void *)-1)
-
-
-#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
-
-struct sched_param;
-#define PTHREAD_NULL ((pthread_t)0)
-
-int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict);
-int pthread_detach(pthread_t);
-_Noreturn void pthread_exit(void *);
-int pthread_join(pthread_t, void **);
-
-pthread_t pthread_self(void);
-
-int pthread_equal(pthread_t, pthread_t);
-#ifndef __cplusplus
-#define pthread_equal(x,y) ((x)==(y))
-#endif
-
-int pthread_setcancelstate(int, int *);
-int pthread_setcanceltype(int, int *);
-void pthread_testcancel(void);
-int pthread_cancel(pthread_t);
-
-int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict);
-int pthread_setschedparam(pthread_t, int, const struct sched_param *);
-int pthread_setschedprio(pthread_t, int);
-
-int pthread_once(pthread_once_t *, void (*)(void));
-
-int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict);
-int pthread_mutex_lock(pthread_mutex_t *);
-int pthread_mutex_unlock(pthread_mutex_t *);
-int pthread_mutex_trylock(pthread_mutex_t *);
-int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict);
-int pthread_mutex_destroy(pthread_mutex_t *);
-int pthread_mutex_consistent(pthread_mutex_t *);
-
-int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict);
-int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict);
-
-int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict);
-int pthread_cond_destroy(pthread_cond_t *);
-int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict);
-int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict);
-int pthread_cond_broadcast(pthread_cond_t *);
-int pthread_cond_signal(pthread_cond_t *);
-
-int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict);
-int pthread_rwlock_destroy(pthread_rwlock_t *);
-int pthread_rwlock_rdlock(pthread_rwlock_t *);
-int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
-int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
-int pthread_rwlock_wrlock(pthread_rwlock_t *);
-int pthread_rwlock_trywrlock(pthread_rwlock_t *);
-int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict);
-int pthread_rwlock_unlock(pthread_rwlock_t *);
-
-int pthread_spin_init(pthread_spinlock_t *, int);
-int pthread_spin_destroy(pthread_spinlock_t *);
-int pthread_spin_lock(pthread_spinlock_t *);
-int pthread_spin_trylock(pthread_spinlock_t *);
-int pthread_spin_unlock(pthread_spinlock_t *);
-
-int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned);
-int pthread_barrier_destroy(pthread_barrier_t *);
-int pthread_barrier_wait(pthread_barrier_t *);
-
-int pthread_key_create(pthread_key_t *, void (*)(void *));
-int pthread_key_delete(pthread_key_t);
-void *pthread_getspecific(pthread_key_t);
-int pthread_setspecific(pthread_key_t, const void *);
-
-int pthread_attr_init(pthread_attr_t *);
-int pthread_attr_destroy(pthread_attr_t *);
-
-int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict);
-int pthread_attr_setguardsize(pthread_attr_t *, size_t);
-int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict);
-int pthread_attr_setstacksize(pthread_attr_t *, size_t);
-int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
-int pthread_attr_setdetachstate(pthread_attr_t *, int);
-int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict);
-int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
-int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict);
-int pthread_attr_setscope(pthread_attr_t *, int);
-int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict);
-int pthread_attr_setschedpolicy(pthread_attr_t *, int);
-int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict);
-int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict);
-int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict);
-int pthread_attr_setinheritsched(pthread_attr_t *, int);
-
-int pthread_mutexattr_destroy(pthread_mutexattr_t *);
-int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict);
-int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict);
-int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict);
-int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict);
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict);
-int pthread_mutexattr_init(pthread_mutexattr_t *);
-int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int);
-int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
-int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
-int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int);
-int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
-
-int pthread_condattr_init(pthread_condattr_t *);
-int pthread_condattr_destroy(pthread_condattr_t *);
-int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
-int pthread_condattr_setpshared(pthread_condattr_t *, int);
-int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict);
-int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict);
-
-int pthread_rwlockattr_init(pthread_rwlockattr_t *);
-int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
-int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
-int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict);
-
-int pthread_barrierattr_destroy(pthread_barrierattr_t *);
-int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict);
-int pthread_barrierattr_init(pthread_barrierattr_t *);
-int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
-
-int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
-
-int pthread_getconcurrency(void);
-int pthread_setconcurrency(int);
-
-int pthread_getcpuclockid(pthread_t, clockid_t *);
-
-struct __ptcb {
- void (*__f)(void *);
- void *__x;
- struct __ptcb *__next;
-};
-
-void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *);
-void _pthread_cleanup_pop(struct __ptcb *, int);
-
-#define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
-#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
-
-
-#ifdef __cplusplus
-}
-#endif
-#endif
diff --git a/src/mono/wasi/provision.ps1 b/src/mono/wasi/provision.ps1
index 1a6f40cb462de2..1f8286ed876a9c 100644
--- a/src/mono/wasi/provision.ps1
+++ b/src/mono/wasi/provision.ps1
@@ -18,6 +18,7 @@ tar --strip-components=1 -xzf ./wasi-sdk-$WasiSdkVersion.0-mingw.tar.gz -C $Wasi
Copy-Item $WasiLocalPath/wasi-sdk-version.txt $WasiSdkPath/wasi-sdk-version.txt
Remove-Item ./wasi-sdk-$WasiSdkVersion.0-mingw.tar.gz -fo
+# TODO https://github.com/dotnet/runtime/issues/104773
# 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
diff --git a/src/mono/wasi/runtime/CMakeLists.txt b/src/mono/wasi/runtime/CMakeLists.txt
index ec45f3aa2e488e..ff92bae2d7011b 100644
--- a/src/mono/wasi/runtime/CMakeLists.txt
+++ b/src/mono/wasi/runtime/CMakeLists.txt
@@ -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
diff --git a/src/mono/wasi/runtime/main.c b/src/mono/wasi/runtime/main.c
index 4e68d69368073e..10f87320e9a0b8 100644
--- a/src/mono/wasi/runtime/main.c
+++ b/src/mono/wasi/runtime/main.c
@@ -5,6 +5,7 @@
// This symbol's implementation is generated during the build
const char* dotnet_wasi_getentrypointassemblyname();
+char *monoeg_g_getenv(const char *variable);
#ifdef WASI_AFTER_RUNTIME_LOADED_DECLARATIONS
// This is supplied from the MSBuild itemgroup @(WasiAfterRuntimeLoaded)
@@ -110,6 +111,14 @@ int main(int argc, char * argv[]) {
mono_print_unhandled_exception(out_exc);
exit(1);
}
- return ret < 0 ? -ret : ret;
+ ret = ret < 0 ? -ret : ret;
+
+ char* dotnet_wasi_print_exit_code = monoeg_g_getenv ("DOTNET_WASI_PRINT_EXIT_CODE");
+ if (ret != 0 && dotnet_wasi_print_exit_code && strcmp(dotnet_wasi_print_exit_code, "1") == 0)
+ {
+ fprintf(stderr, "WASM EXIT %d\n", ret);
+ }
+
+ return ret;
}
#endif
diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj
index 7038b1a4136df5..a63a5dddcc5c54 100644
--- a/src/mono/wasi/wasi.proj
+++ b/src/mono/wasi/wasi.proj
@@ -19,7 +19,7 @@
<_WasiCompileRspPath>$(NativeBinDir)src\wasi-compile.rsp
<_WasiLinkRspPath>$(NativeBinDir)src\wasi-link.rsp
false
- $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(MSBuildThisFileDirectory), 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
$(WASI_SDK_PATH)bin/clang
$(WasiClang).exe
@@ -30,7 +30,7 @@
-
+
@@ -215,7 +215,7 @@
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) --no-warn-unused-cli -DCMAKE_TOOLCHAIN_FILE="$([MSBuild]::NormalizePath('$(RepoRoot)', 'src/native/external/wasi-sdk-p2.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"
diff --git a/src/mono/wasm/build/WasmApp.LocalBuild.props b/src/mono/wasm/build/WasmApp.LocalBuild.props
index dc9b562089a3a9..96689db1e19e93 100644
--- a/src/mono/wasm/build/WasmApp.LocalBuild.props
+++ b/src/mono/wasm/build/WasmApp.LocalBuild.props
@@ -30,7 +30,7 @@
$(RuntimeSrcDir)\artifacts\bin\
$(RuntimeSrcDir)\src\mono\browser\emsdk\
- $([MSBuild]::NormalizeDirectory($(RuntimeSrcDir), 'src', 'mono', 'wasi', 'wasi-sdk'))
+ $([MSBuild]::NormalizeDirectory($(RuntimeSrcDir), 'src', 'mono', 'wasi', 'wasi-sdk'))
$([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_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 22b1a645d0895a..4b449f10fb6bd8 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/mono/wasm/host/wasi/WasiEngineArguments.cs b/src/mono/wasm/host/wasi/WasiEngineArguments.cs
index 807ecb659264d7..64276047091847 100644
--- a/src/mono/wasm/host/wasi/WasiEngineArguments.cs
+++ b/src/mono/wasm/host/wasi/WasiEngineArguments.cs
@@ -3,7 +3,9 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text.Json;
+using Mono.Options;
namespace Microsoft.WebAssembly.AppHost;
@@ -12,7 +14,8 @@ internal sealed class WasiEngineArguments
public WasmHost Host => CommonConfig.Host;
public CommonConfiguration CommonConfig { get; init; }
- public IEnumerable AppArgs => CommonConfig.RemainingArgs;
+ public bool ForwardExitCode { get; private set; }
+ public string[] AppArgs { get; init; }
public bool IsSingleFileBundle =>
CommonConfig.HostProperties.Extra?.TryGetValue("singleFileBundle", out JsonElement singleFileValue) == true&&
@@ -21,6 +24,19 @@ internal sealed class WasiEngineArguments
public WasiEngineArguments(CommonConfiguration commonConfig)
{
CommonConfig = commonConfig;
+ AppArgs = GetOptions().Parse(commonConfig.RemainingArgs).ToArray();
+ ParseJsonProperties(CommonConfig.HostConfig.Properties);
+ }
+
+ private OptionSet GetOptions() => new OptionSet
+ {
+ { "forward-exit-code", "Forward process exit code via stderr", v => ForwardExitCode = true }
+ };
+
+ public void ParseJsonProperties(IDictionary? properties)
+ {
+ if (properties?.TryGetValue("forward-exit-code", out JsonElement forwardElement) == true)
+ ForwardExitCode = forwardElement.GetBoolean();
}
public void Validate()
diff --git a/src/mono/wasm/host/wasi/WasiEngineHost.cs b/src/mono/wasm/host/wasi/WasiEngineHost.cs
index bd2e3396358fd0..4c8f8bc363e230 100644
--- a/src/mono/wasm/host/wasi/WasiEngineHost.cs
+++ b/src/mono/wasm/host/wasi/WasiEngineHost.cs
@@ -60,6 +60,11 @@ private async Task RunAsync()
args.AddRange(["--dir", "."]);
};
+ if (_args.ForwardExitCode)
+ {
+ args.AddRange(["--env", "DOTNET_WASI_PRINT_EXIT_CODE=1"]);
+ };
+
args.AddRange(engineArgs);
args.Add("--");
@@ -85,11 +90,23 @@ private async Task RunAsync()
foreach (string? arg in args)
psi.ArgumentList.Add(arg!);
+ int? exitCodeOverride = null;
int exitCode = await Utils.TryRunProcess(psi,
_logger,
msg => { if (msg != null) _logger.LogInformation(msg); },
- msg => { if (msg != null) _logger.LogInformation(msg); });
-
- return exitCode;
+ msg => {
+ if (msg != null) {
+ if (_args.ForwardExitCode && msg.StartsWith("WASM EXIT "))
+ {
+ exitCodeOverride = int.Parse(msg.Substring(10));
+ }
+ else
+ {
+ _logger.LogInformation(msg);
+ }
+ }
+ });
+
+ return exitCodeOverride ?? exitCode;
}
}
diff --git a/src/native/external/wasi-sdk-p2.cmake b/src/native/external/wasi-sdk-p2.cmake
new file mode 100644
index 00000000000000..fcd2d2a20dadc8
--- /dev/null
+++ b/src/native/external/wasi-sdk-p2.cmake
@@ -0,0 +1,46 @@
+# TODO: https://github.com/dotnet/runtime/issues/104773
+# 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)
diff --git a/src/native/libs/System.Native/pal_process_wasi.c b/src/native/libs/System.Native/pal_process_wasi.c
index 1d3d6f998ec4e2..569a0066eec69e 100644
--- a/src/native/libs/System.Native/pal_process_wasi.c
+++ b/src/native/libs/System.Native/pal_process_wasi.c
@@ -17,12 +17,6 @@
#include
-#ifdef DEBUG
-#define DEBUGNOTRETURN __attribute__((noreturn))
-#else
-#define DEBUGNOTRETURN
-#endif
-
int32_t SystemNative_ForkAndExecProcess(const char* filename,
char* const argv[],
char* const envp[],
@@ -72,10 +66,9 @@ int32_t SystemNative_GetSid(int32_t pid)
return -1;
}
-DEBUGNOTRETURN
void SystemNative_SysLog(SysLogPriority priority, const char* message, const char* arg1)
{
- assert_msg(false, "Not supported on WASI", 0);
+ fprintf(stderr, message, arg1);
}
int32_t SystemNative_WaitIdAnyExitedNoHangNoWait(void)
diff --git a/src/native/libs/build-native.proj b/src/native/libs/build-native.proj
index aec082e1c0a534..1560eada03d266 100644
--- a/src/native/libs/build-native.proj
+++ b/src/native/libs/build-native.proj
@@ -26,6 +26,12 @@
+
+ $([MSBuild]::NormalizeDirectory($(RepoRoot), 'src', 'mono', 'wasi', 'wasi-sdk'))
+ $([MSBuild]::EnsureTrailingSlash('$(WASI_SDK_PATH)').Replace('\', '/'))
+ <_BuildNativeEnvironmentVariables>$(_BuildNativeEnvironmentVariables);WASI_SDK_PATH=$(WASI_SDK_PATH)
+
+
@@ -64,7 +70,7 @@
-
+
-
+
false
- true
+ true
sh
cmd
diff --git a/src/tests/build.sh b/src/tests/build.sh
index 42689057fa7233..b0ae9998c1cb36 100755
--- a/src/tests/build.sh
+++ b/src/tests/build.sh
@@ -60,7 +60,7 @@ build_Tests()
export MSBUILDDEBUGPATH
if [[ "$__SkipNative" != 1 && "$__BuildTestWrappersOnly" != 1 && "$__GenerateLayoutOnly" != 1 && "$__CopyNativeTestBinaries" != 1 && \
- "$__TargetOS" != "browser" && "$__TargetOS" != "wasi" && "$__TargetOS" != "android" && "$__TargetOS" != "ios" && "$__TargetOS" != "iossimulator" && "$__TargetOS" != "tvos" && "$__TargetOS" != "tvossimulator" ]]; then
+ "$__TargetOS" != "browser" && "$__TargetOS" != "android" && "$__TargetOS" != "ios" && "$__TargetOS" != "iossimulator" && "$__TargetOS" != "tvos" && "$__TargetOS" != "tvossimulator" ]]; then
build_native "$__TargetOS" "$__TargetArch" "$__TestDir" "$__NativeTestIntermediatesDir" "install" "$__CMakeArgs" "CoreCLR test component"
if [[ "$?" -ne 0 ]]; then
diff --git a/src/tests/run.sh b/src/tests/run.sh
index 102bc0ba38898a..5a3a1c3065aa4a 100755
--- a/src/tests/run.sh
+++ b/src/tests/run.sh
@@ -14,6 +14,7 @@ function print_usage {
echo ' : One of x64, x86, arm, arm64, loongarch64, riscv64, wasm. Defaults to current architecture.'
echo ' : One of debug, checked, release. Defaults to debug.'
echo ' android : Set build OS to Android.'
+ echo ' wasi : Set build OS to WASI.'
echo ' --test-env= : Script to set environment variables for tests'
echo ' --testRootDir= : Root directory of the test build (e.g. runtime/artifacts/tests/windows.x64.Debug).'
echo ' --coreRootDir= : Directory to the CORE_ROOT location.'
@@ -105,6 +106,9 @@ do
android)
buildOS="android"
;;
+ wasi)
+ buildOS="wasi"
+ ;;
debug|Debug)
buildConfiguration="Debug"
;;
@@ -204,8 +208,12 @@ runtestPyArguments=("-arch" "${buildArch}" "-build_type" "${buildConfiguration}"
echo "Build Architecture : ${buildArch}"
echo "Build Configuration : ${buildConfiguration}"
-if [ "$buildArch" = "wasm" ]; then
- runtestPyArguments+=("-os" "browser")
+if [ "$buildArch" = "wasm" -a -z "$buildOS" ]; then
+ buildOS="browser"
+fi
+
+if [ -n "$buildOS" ]; then
+ runtestPyArguments+=("-os" "$buildOS")
fi
if [ "$buildOS" = "android" ]; then