Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2d2e1fb
Add WASI target support for CoreCLR WASM interpreter
lewing Apr 8, 2026
edcda02
Fix WASI CoreCLR: file loading, path resolution, and install
lewing Apr 9, 2026
3821a40
Fix WASI mmap: arena allocator for anonymous mappings
lewing Apr 9, 2026
adafc8a
Increase TPA buffer to 256KB for full framework deployment
lewing Apr 9, 2026
3d4443c
Fix duplicate AcquireWasiSdk import in libs native build
lewing Apr 10, 2026
6594cbb
Skip init-compiler.sh for WASI builds
lewing Apr 10, 2026
d8578e8
Upgrade WASI SDK 25 to 32 and fix LLVM 22 warnings
lewing Apr 10, 2026
34e6f64
Enable native WASM exceptions for WASI CoreCLR
lewing Apr 10, 2026
91e51f8
Set interpreter context for WASM exception dispatch
lewing Apr 10, 2026
6a0644a
Fix WASI arena allocator alignment and recursive mutex
lewing Apr 10, 2026
3ca3028
Remove debug printfs from WASI host and CLR initialization
lewing Apr 11, 2026
6a56938
Remove unnecessary WASM interpreter context in EH dispatch
lewing Apr 13, 2026
84ecdbe
Fix WASI available memory reporting in GC
lewing Apr 13, 2026
bb6feec
Remove separate corerun-wasi.cpp, use unified corerun.cpp
lewing Apr 13, 2026
767cac5
Remove dead sjlj code inside WASI-only block
lewing Apr 13, 2026
d267ded
Restore accidentally removed comments in unrelated code
lewing Apr 13, 2026
d9e0cab
Merge branch 'dotnet:main' into coreclr-wasi-interpreter
lewing Apr 15, 2026
8a657e8
Address PR review feedback on WASI PAL stubs
lewing Apr 16, 2026
e0a542c
Merge remote-tracking branch 'upstream/main' into coreclr-wasi-interp…
lewing May 22, 2026
cede570
Bump WASI SDK from 32 to 33
lewing May 22, 2026
e61f257
Enable FEATURE_WEBCIL for WASI and include webcildecoder.h in pregene…
lewing May 22, 2026
48653be
Drop dead WASM/WASI hunks from gc/unix/gcenv.unix.cpp
lewing May 22, 2026
8aaecb6
Document WASI sysroot shim header approach
lewing May 22, 2026
57c0396
Split arch/wasm/stubs.cpp into wasm-stubs.cpp and wasi-stubs.cpp
lewing May 22, 2026
f83ba68
Defer WASI finalization to WasiEventLoop instead of running it inline
lewing May 22, 2026
a1677ee
Don't close borrowed fds in WASI PAL cleanup routines
lewing May 22, 2026
6657291
Enable corerun self_test on WASI now that the SDK supports C++ except…
lewing May 22, 2026
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
2 changes: 1 addition & 1 deletion eng/AcquireWasiSdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-->
<Project>
<PropertyGroup>
<_WasiSdkVersion>25.0</_WasiSdkVersion>
<_WasiSdkVersion>33.0</_WasiSdkVersion>
<_RuntimeLocalWasiSdkPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'wasi-sdk'))</_RuntimeLocalWasiSdkPath>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

<_CoreCLRSupportedOS Condition="'$(TargetsAndroid)' == 'true' and '$(TargetArchitecture)' != 'x86'">true</_CoreCLRSupportedOS>
<_CoreCLRSupportedOS Condition="'$(TargetsBrowser)' == 'true'">true</_CoreCLRSupportedOS>
<_CoreCLRSupportedOS Condition="'$(TargetsWasi)' == 'true'">true</_CoreCLRSupportedOS>
<_CoreCLRSupportedOS Condition="'$(TargetsAppleMobile)' == 'true'">true</_CoreCLRSupportedOS>

<_CoreCLRSupportedArch Condition="'$(TargetArchitecture)' != 'ppc64le' and '$(TargetArchitecture)' != 's390x'">true</_CoreCLRSupportedArch>
Expand Down Expand Up @@ -64,6 +65,7 @@
<DefaultPrimaryRuntimeFlavor>CoreCLR</DefaultPrimaryRuntimeFlavor>
<DefaultPrimaryRuntimeFlavor Condition="'$(CoreCLRSupported)' != 'true'">Mono</DefaultPrimaryRuntimeFlavor>
<DefaultPrimaryRuntimeFlavor Condition="'$(TargetsBrowser)' == 'true' and !$(Subset.ToLowerInvariant().Contains('clr'))">Mono</DefaultPrimaryRuntimeFlavor>
<DefaultPrimaryRuntimeFlavor Condition="'$(TargetsWasi)' == 'true' and !$(Subset.ToLowerInvariant().Contains('clr'))">Mono</DefaultPrimaryRuntimeFlavor>
<PrimaryRuntimeFlavor Condition="'$(PrimaryRuntimeFlavor)' == ''">$(DefaultPrimaryRuntimeFlavor)</PrimaryRuntimeFlavor>
</PropertyGroup>

Expand Down Expand Up @@ -101,6 +103,7 @@
<RuntimeFlavor Condition="'$(TargetsAndroid)' == 'true' and ($(_subset.Contains('+clr+')) or $(_subset.Contains('+clr.')))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(TargetsAppleMobile)' == 'true' and ($(_subset.Contains('+clr+')) or $(_subset.Contains('+clr.')))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(TargetsBrowser)' == 'true' and ($(_subset.Contains('+clr+')) or $(_subset.Contains('+clr.')))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(TargetsWasi)' == 'true' and ($(_subset.Contains('+clr+')) or $(_subset.Contains('+clr.')))">CoreCLR</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and '$(TargetsMobile)' == 'true'">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == '' and ($(_subset.Contains('+mono+')) or $(_subset.Contains('+mono.runtime+'))) and (!$(_subset.Contains('+clr+')) and !$(_subset.Contains('+clr.runtime+')) and !$(_subset.Contains('+clr.corelib+')))">Mono</RuntimeFlavor>
<RuntimeFlavor Condition="'$(RuntimeFlavor)' == ''">$(PrimaryRuntimeFlavor)</RuntimeFlavor>
Expand All @@ -112,6 +115,7 @@
<DefaultCoreClrSubsets Condition="'$(TargetsAndroid)' == 'true'">clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsAppleMobile)' == 'true'">clr.native+clr.corelib+clr.tools+clr.nativecorelib+clr.packages+clr.nativeaotlibs+clr.crossarchtools</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsBrowser)' == 'true'">provision.emsdk+clr.native+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.crossarchtools+libs.native+host.native</DefaultCoreClrSubsets>
<DefaultCoreClrSubsets Condition="'$(TargetsWasi)' == 'true'">provision.wasisdk+clr.native+clr.corelib+clr.nativecorelib+clr.tools+clr.packages+clr.crossarchtools+libs.native+host.native</DefaultCoreClrSubsets>
<!-- Even on platforms that do not support the CoreCLR runtime, we still want to build ilasm/ildasm. -->
<DefaultCoreClrSubsets Condition="'$(RuntimeFlavor)' != 'CoreCLR'">clr.iltools+clr.packages</DefaultCoreClrSubsets>

Expand Down
6 changes: 6 additions & 0 deletions eng/native.wasm.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project>
<Import Project="$(RepositoryEngineeringDir)AcquireEmscriptenSdk.targets" />
<Import Project="$(RepositoryEngineeringDir)AcquireWasiSdk.targets" />

<!-- These packages provide ICU and timezone data paths for the native build (CMake).
Skip them during app-level relink (IsBrowserWasmProject) since the runtime pack
Expand Down Expand Up @@ -39,6 +40,11 @@
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_PERFTRACING_LISTEN_PORTS=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_DEFAULT_LISTEN_PORT=1&quot;" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWasi)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'">
<NativeCMakeArg Include="-cmakeargs &quot;-DGEN_PINVOKE=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_PERFTRACING_LISTEN_PORTS=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_DEFAULT_LISTEN_PORT=1&quot;" />
</ItemGroup>
<ItemGroup Condition="'$(FeatureMultithreading)' != 'true'">
<NativeCMakeArg Include="-cmakeargs &quot;-DFEATURE_PERFTRACING_DISABLE_THREADS=1&quot;" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions eng/native/build-commons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ build_native()
echo "Error: Unknown tvOS architecture $__TargetArch."
exit 1
fi
elif [[ "$targetOS" == wasi ]]; then
# Don't try to set CC/CXX in init-compiler.sh - it's handled in wasi-sdk-p2.cmake already
__Compiler="default"
fi

if [[ "$__UseNinja" == 1 ]]; then
Expand Down
3 changes: 3 additions & 0 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,9 @@ if(CLR_CMAKE_TARGET_UNIX)
if(CLR_CMAKE_TARGET_BROWSER)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_BROWSER>)
endif()
if(CLR_CMAKE_TARGET_WASI)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WASI>)
endif()
elseif(CLR_CMAKE_TARGET_WASI)
add_compile_definitions($<$<NOT:$<BOOL:$<TARGET_PROPERTY:IGNORE_DEFAULT_TARGET_OS>>>:TARGET_WASI>)
else(CLR_CMAKE_TARGET_UNIX)
Expand Down
4 changes: 3 additions & 1 deletion eng/native/configureplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ endif(CLR_CMAKE_HOST_OS STREQUAL emscripten)

if(CLR_CMAKE_TARGET_OS STREQUAL wasi)
set(CLR_CMAKE_HOST_WASI 1)
set(CLR_CMAKE_HOST_UNIX 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL wasi)

#--------------------------------------------
Expand Down Expand Up @@ -432,6 +433,7 @@ if(CLR_CMAKE_TARGET_OS STREQUAL emscripten OR CLR_CMAKE_TARGET_OS STREQUAL brows
endif(CLR_CMAKE_TARGET_OS STREQUAL emscripten OR CLR_CMAKE_TARGET_OS STREQUAL browser)

if(CLR_CMAKE_TARGET_OS STREQUAL wasi)
set(CLR_CMAKE_TARGET_UNIX 1)
set(CLR_CMAKE_TARGET_WASI 1)
endif(CLR_CMAKE_TARGET_OS STREQUAL wasi)

Expand Down Expand Up @@ -517,7 +519,7 @@ else()
add_compile_options(-msimd128)
endif()
if(CLR_CMAKE_TARGET_WASI)
add_compile_options(-fexceptions)
add_compile_options(-fwasm-exceptions)
endif()
endif()
endif()
Expand Down
33 changes: 19 additions & 14 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -560,20 +560,25 @@ function(install_clr)
foreach(destination ${destinations})
# CMake bug with executable WASM outputs - https://gitlab.kitware.com/cmake/cmake/-/issues/20745
if (CLR_CMAKE_TARGET_ARCH_WASM AND "${targetType}" STREQUAL "EXECUTABLE")
# Use install FILES since these are WASM assets that aren't executable.
install(FILES
"$<TARGET_FILE_DIR:${targetName}>/${targetName}.js"
"$<TARGET_FILE_DIR:${targetName}>/${targetName}.wasm"
DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL})

# Conditionally check for and copy any extra data file at install time.
install(CODE
"
if(EXISTS \"$<TARGET_FILE_DIR:${targetName}>/${targetName}.data\")
file(INSTALL \"$<TARGET_FILE_DIR:${targetName}>/${targetName}.data\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/${destination}\")
endif()
"
COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL})
if (CLR_CMAKE_TARGET_WASI)
# WASI SDK produces a single .wasm file without .js glue
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL})
else()
# Emscripten produces .js + .wasm assets that aren't directly executable.
install(FILES
"$<TARGET_FILE_DIR:${targetName}>/${targetName}.js"
"$<TARGET_FILE_DIR:${targetName}>/${targetName}.wasm"
DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL})

# Conditionally check for and copy any extra data file at install time.
install(CODE
"
if(EXISTS \"$<TARGET_FILE_DIR:${targetName}>/${targetName}.data\")
file(INSTALL \"$<TARGET_FILE_DIR:${targetName}>/${targetName}.data\" DESTINATION \"${CMAKE_INSTALL_PREFIX}/${destination}\")
endif()
"
COMPONENT ${INSTALL_CLR_COMPONENT} ${INSTALL_CLR_OPTIONAL})
endif()
else()
# We don't need to install the export libraries for our DLLs
# since they won't be directly linked against.
Expand Down
23 changes: 23 additions & 0 deletions eng/pipelines/common/templates/wasi-coreclr-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
parameters:
extraBuildArgs: ''
isExtraPlatformsBuild: false
platforms: []

jobs:

#
# Build CoreCLR native for WASI
#
- template: /eng/pipelines/common/platform-matrix.yml
parameters:
jobTemplate: /eng/pipelines/common/global-build-job.yml
buildConfig: Release
runtimeFlavor: coreclr
platforms: ${{ parameters.platforms }}

jobParameters:
isExtraPlatforms: ${{ parameters.isExtraPlatformsBuild }}
testGroup: innerloop
nameSuffix: _WasiCoreCLR_BuildOnly
buildArgs: -s clr.native -c $(_BuildConfig) ${{ parameters.extraBuildArgs }}
timeoutInMinutes: 120
6 changes: 6 additions & 0 deletions eng/pipelines/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,12 @@ extends:
- WasmTestOnFirefox
- WasmTestOnV8

# WASI CoreCLR native build
- template: /eng/pipelines/common/templates/wasi-coreclr-build.yml
parameters:
platforms:
- wasi_wasm

# EAT Library tests - only run on linux
- template: /eng/pipelines/common/templates/wasm-library-aot-tests.yml
parameters:
Expand Down
24 changes: 21 additions & 3 deletions src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,28 @@ if(CORECLR_SET_RPATH)
set(MACOSX_RPATH ON)
endif(CORECLR_SET_RPATH)

if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_BROWSER OR CLR_CMAKE_HOST_ANDROID)
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_BROWSER OR CLR_CMAKE_HOST_WASI OR CLR_CMAKE_HOST_ANDROID)
set(FEATURE_STANDALONE_GC 0)
endif()

if(CLR_CMAKE_TARGET_WASI)
add_compile_definitions(_WASI_EMULATED_SIGNAL)
add_compile_definitions(_WASI_EMULATED_PROCESS_CLOCKS)
add_compile_definitions(_WASI_EMULATED_MMAN)
add_compile_definitions(_WASI_EMULATED_GETPID)
# WASI doesn't define these fcntl constants — provide them as no-ops
add_compile_definitions(F_DUPFD_CLOEXEC=1030)
add_compile_definitions(O_CLOEXEC=0)
# WASI sysroot is missing entire POSIX subsystems (signal, ucontext, parts
# of pthread, sys/wait, sys/vfs, sys/resource, dlfcn, link, pwd). The shim
# headers under pal/src/include/pal/wasi/ use #include_next to layer the
# missing declarations and link-time stubs on top of the WASI sysroot
# headers. They must be visible BEFORE SYSTEM at the CoreCLR scope because
# minipal, debug, hosts and other non-PAL targets also include the affected
# headers. See pal/src/include/pal/wasi/README.md for the design rationale.
include_directories(BEFORE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/pal/src/include/pal/wasi)
endif()

OPTION(CLR_CMAKE_ENABLE_CODE_COVERAGE "Enable code coverage" OFF)

#----------------------------------------------------
Expand Down Expand Up @@ -119,7 +137,7 @@ endif()
#----------------------------------------------------
# Build the test watchdog alongside the CLR
#----------------------------------------------------
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS AND NOT CLR_CMAKE_TARGET_BROWSER)
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS AND NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI)
add_subdirectory("${CLR_SRC_NATIVE_DIR}/watchdog" test-watchdog)
endif()

Expand Down Expand Up @@ -149,7 +167,7 @@ endif()
include_directories("pal/prebuilt/inc")
include_directories(${CLR_ARTIFACTS_OBJ_DIR})

if (NOT CLR_CMAKE_TARGET_BROWSER OR CLR_CROSS_COMPONENTS_BUILD)
if ((NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI) OR CLR_CROSS_COMPONENTS_BUILD)
add_subdirectory(tools/aot/jitinterface)
endif ()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
<ItemGroup Condition="'$(FeatureCominterop)' != 'true'">
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\InteropServices\ComActivator.PlatformNotSupported.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true'" >
<ItemGroup Condition="'$(TargetsUnix)' == 'true' or '$(TargetsBrowser)' == 'true' or '$(TargetsWasi)' == 'true'" >
<Compile Include="$(BclSourcesRoot)\Internal\Runtime\InteropServices\InMemoryAssemblyLoader.PlatformNotSupported.cs" />
<Compile Include="$(BclSourcesRoot)\Interop\Unix\Interop.Libraries.cs" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/clrfeatures.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(CLR_CMAKE_TARGET_TIZEN_LINUX)
endif()

if(NOT DEFINED FEATURE_EVENT_TRACE)
if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT (CLR_CROSS_COMPONENTS_BUILD AND CLR_CMAKE_TARGET_ARCH_WASM))
if (NOT CLR_CMAKE_TARGET_BROWSER AND NOT CLR_CMAKE_TARGET_WASI AND NOT (CLR_CROSS_COMPONENTS_BUILD AND CLR_CMAKE_TARGET_ARCH_WASM))
# To actually disable FEATURE_EVENT_TRACE, also change clr.featuredefines.props
set(FEATURE_EVENT_TRACE 1)
endif()
Expand Down Expand Up @@ -63,7 +63,7 @@ if(CLR_CMAKE_TARGET_ARCH_WASM)
set(FEATURE_PORTABLE_HELPERS 1)
endif(CLR_CMAKE_TARGET_ARCH_WASM)

if(CLR_CMAKE_TARGET_BROWSER)
if(CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
set(FEATURE_WEBCIL 1)
endif()

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/debug/debug-pal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ if(CLR_CMAKE_HOST_WIN32)
endif(CLR_CMAKE_HOST_WIN32)

if(CLR_CMAKE_HOST_UNIX)
set(DEBUG_PAL_REFEREENCE_DIAGNOSTICSERVER ON)
if (NOT CLR_CMAKE_TARGET_WASI)
set(DEBUG_PAL_REFEREENCE_DIAGNOSTICSERVER ON)
endif()

add_definitions(-DPAL_IMPLEMENTATION)
add_definitions(-D_POSIX_C_SOURCE=200809L)
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/debug/debug-pal/unix/twowaypipe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <pal_assert.h>
#include "twowaypipe.h"

#ifdef TARGET_WASI
static inline int mkfifo(const char *path, mode_t mode) { (void)path; (void)mode; errno = ENOTSUP; return -1; }
#endif

// Pipe names stored for use in AbortPipeServerImpl().
static char s_serverInPipeName[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH];
static char s_serverOutPipeName[MAX_DEBUGGER_TRANSPORT_PIPE_NAME_LENGTH];
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/gc/unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ elseif (HAVE_PTHREAD_IN_LIBC)
set(PTHREAD_LIBRARY c)
endif()

check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK)

check_library_exists(${PTHREAD_LIBRARY} pthread_setaffinity_np "" HAVE_PTHREAD_SETAFFINITY_NP)
if (PTHREAD_LIBRARY)
check_library_exists(${PTHREAD_LIBRARY} pthread_condattr_setclock "" HAVE_PTHREAD_CONDATTR_SETCLOCK)
check_library_exists(${PTHREAD_LIBRARY} pthread_setaffinity_np "" HAVE_PTHREAD_SETAFFINITY_NP)
endif()

check_cxx_symbol_exists(_SC_PHYS_PAGES unistd.h HAVE__SC_PHYS_PAGES)
check_cxx_symbol_exists(_SC_AVPHYS_PAGES unistd.h HAVE__SC_AVPHYS_PAGES)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/gc/unix/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
namespace
{

#if HAVE_PTHREAD_CONDATTR_SETCLOCK
#if HAVE_PTHREAD_CONDATTR_SETCLOCK || defined(_WASI_EMULATED_PROCESS_CLOCKS)
void TimeSpecAdd(timespec* time, uint32_t milliseconds)
{
uint64_t nsec = time->tv_nsec + (uint64_t)milliseconds * tccMilliSecondsToNanoSeconds;
Expand All @@ -26,7 +26,7 @@ void TimeSpecAdd(timespec* time, uint32_t milliseconds)

time->tv_nsec = nsec;
}
#endif // HAVE_PTHREAD_CONDATTR_SETCLOCK
#endif // HAVE_PTHREAD_CONDATTR_SETCLOCK || _WASI_EMULATED_PROCESS_CLOCKS

#if HAVE_CLOCK_GETTIME_NSEC_NP
// Convert nanoseconds to the timespec structure
Expand Down Expand Up @@ -129,7 +129,7 @@ class GCEvent::Impl
NanosecondsToTimeSpec(nanoseconds, &endTime);
endMachTime = clock_gettime_nsec_np(CLOCK_UPTIME_RAW) + nanoseconds;
}
#elif HAVE_PTHREAD_CONDATTR_SETCLOCK
#elif HAVE_PTHREAD_CONDATTR_SETCLOCK || defined(_WASI_EMULATED_PROCESS_CLOCKS)
if (milliseconds != INFINITE)
{
clock_gettime(CLOCK_MONOTONIC, &endTime);
Expand Down
23 changes: 19 additions & 4 deletions src/coreclr/hosts/corerun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set(CORERUN_IN_BROWSER 0)

if(CLR_CMAKE_HOST_WIN32)
add_definitions(-DFX_VER_INTERNALNAME_STR=corerun.exe)
else()
elseif(NOT CLR_CMAKE_TARGET_WASM)
include(configure.cmake)
endif()

Expand Down Expand Up @@ -36,9 +36,13 @@ if(CLR_CMAKE_HOST_WIN32)
target_link_options(corerun PRIVATE "/CETCOMPAT")
endif()
else()
target_link_libraries(corerun PRIVATE ${CMAKE_DL_LIBS})
# Required to expose symbols for global symbol discovery
target_link_libraries(corerun PRIVATE -rdynamic)
if(NOT CLR_CMAKE_TARGET_ARCH_WASM)
target_link_libraries(corerun PRIVATE ${CMAKE_DL_LIBS})
# Required to expose symbols for global symbol discovery
target_link_libraries(corerun PRIVATE -rdynamic)
elseif(CLR_CMAKE_TARGET_WASI)
target_link_libraries(corerun PRIVATE -ldl)
endif()

# Android implements pthread natively.
# WASM, linking against pthreads indicates Node.js workers are
Expand Down Expand Up @@ -114,6 +118,17 @@ else()
-sNODERAWFS=1
-lnodefs.js)
endif()
elseif (CLR_CMAKE_TARGET_WASI)
target_link_options(corerun PRIVATE
-fwasm-exceptions
-Wl,-z,stack-size=8388608
-Wl,--initial-memory=52428800
-L$ENV{WASI_SDK_PATH}/share/wasi-sysroot/lib/wasm32-wasip2)
target_link_libraries(corerun PRIVATE
-lwasi-emulated-process-clocks
-lwasi-emulated-signal
-lwasi-emulated-getpid
-lunwind)
endif()

if (CORERUN_IN_BROWSER)
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/hosts/corerun/corerun.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,12 @@ class platform_specific_actions final
#endif

// CMake generated
#ifndef TARGET_WASM
#include <config.h>
#else
#define HAVE_GETAUXVAL 0
#define HAVE_DIRENT_D_TYPE 1
#endif
#include <minipal/getexepath.h>

#if __GNUC__ >= 4
Expand Down
Loading
Loading