Skip to content

Commit 11408ab

Browse files
radekdoulikkglewingjkotas
authored
[wasm] build paltests (#112404)
* Make configure pass for wasm and paltests component Disable few parts, some might need closer look later. * Fix compilation and linking on wasm * Ignore limits and dlopen(nullptr, ...) on wasm * Do not return 0 for minipal_get_current_thread_id on wasm * Add simple index.html to run paltests on wasm in browser * Forward console log and error to http server * Enable debug output temporarily * Do not create synchronization manager worker thread on wasm And also skip creating pipe to communicate with it * Temporarily override main args on wasm to simplify testing * Prototype pal test suite runner * Reload between tests to work around stack exhaustion * Shorter delay between tests; logging of exit code specifies which test it was so you can pull the test statuses out of a log file * Add mechanism for disabling tests and disable the debug_api tests * Disable another set of tests * Disable more tests and reduce run delay * Full test run completes now * Use exit runtime option To avoid error messages at the end of each run * Add summary with counts of passed, failed and disabled tests * Trap on assert to stop * Filter the tests, use paltestlist.txt as runpaltests.sh Also write missing tests * Don't output when capturing tests Also fix disabled tests count * Add notes to failing tests * Make flush instruction cache no-op on wasm, disable few MT tests * Reenable debug_api test, which is not failing Add few more notes to failing memory related tests * Do not call mmap to re-set memory protection Emscripten's mmap doesn't support that and because we don't have virtual memory in wasm, it doesn't make sense to call it there * Disable 3 exception_handling/RaiseException tests Also re-enable debug test, which works and disable few MT tests * Disable paltest_probememory_probememory_neg1 * Disable dll tests on wasm * Fix cmake warnings * Install the additional files for wasm * Use onExit instead of quit This fixes issue with newer emscripten, where Module['quit'] handling is removed. Also fix single test runs. * Add mono.emsdk subset * Remove forgotten check * Update msbuild targets to allow build of wasm paltests * Add CI build and temporarily disable all other runtime builds to save resources * Fix remaining conflict * Fix build afer merge with main * Make membarrier noop on wasm * Change subsets build order * Disable fs test which fails with chromedriver * Fix InternalCanonicalizeRealPath corner case that affects wasm pal tests * Zero memory for MEM_DECOMMIT on WASM instead of just doing nothing, to at least get slightly closer to intended behavior * Removed notes about the failing tests * Fix few new cmake warnings * Put runtime runs back * Remove unwanted changes * List disabled and failed tests when the run completed * Fix mono wasm/MT build * Remove unwanted fields Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Fix mono wasm/MT build once more * Fix windows build * Fix windows build * Feedback * More feedback * More feedback * More feedback * Feedback * Fix cmake warning * Update src/coreclr/pal/src/CMakeLists.txt Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/pal/src/CMakeLists.txt Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/pal/src/CMakeLists.txt Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Update src/coreclr/pal/src/CMakeLists.txt Co-authored-by: Jan Kotas <jkotas@microsoft.com> * Feedback --------- Co-authored-by: Katelyn Gadd <kg@luminance.org> Co-authored-by: Larry Ewing <lewing@microsoft.com> Co-authored-by: Jan Kotas <jkotas@microsoft.com>
1 parent c6a3984 commit 11408ab

File tree

38 files changed

+475
-38
lines changed

38 files changed

+475
-38
lines changed

eng/Subsets.props

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@
207207
<!-- Mono -->
208208
<SubsetName Include="Mono" Description="The Mono runtime and CoreLib. Equivalent to: $(DefaultMonoSubsets)" />
209209
<SubsetName Include="Mono.Runtime" Description="The Mono .NET runtime." />
210+
<SubsetName Include="Mono.EmSDK" Description="The emsdk provisioning." />
210211
<SubsetName Include="Mono.AotCross" Description="The cross-compiler runtime for Mono AOT." />
211212
<SubsetName Include="Mono.CoreLib" Description="The managed System.Private.CoreLib library for Mono." />
212213
<SubsetName Include="Mono.Manifests" Description="The NuGet packages with manifests defining the mobile and Blazor workloads." />
@@ -264,6 +265,11 @@
264265
</ProjectToBuild>
265266
</ItemDefinitionGroup>
266267

268+
<!-- emscripten provisioning, needs to be placed before runtime projects -->
269+
<ItemGroup Condition="$(_subset.Contains('+mono.emsdk+'))">
270+
<ProjectToBuild Include="$(MonoProjectRoot)mono.proj" AdditionalProperties="%(AdditionalProperties);ProvisionEmscriptenOnly=true" Category="mono" />
271+
</ItemGroup>
272+
267273
<!-- CoreClr sets -->
268274
<ItemGroup Condition="$(_subset.Contains('+clr.corelib+'))">
269275
<ProjectToBuild Include="$(CoreClrProjectRoot)System.Private.CoreLib\System.Private.CoreLib.csproj" Category="clr" />
@@ -325,7 +331,7 @@
325331
The cross tools are used as part of the build process with the downloaded build tools, so we need to build them for the host architecture and build them as unsanitized binaries.
326332
-->
327333
<PropertyGroup>
328-
<_BuildAnyCrossArch Condition="'$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != ''">true</_BuildAnyCrossArch>
334+
<_BuildAnyCrossArch Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)' or '$(HostOS)' != '$(TargetOS)' or '$(EnableNativeSanitizers)' != '') and '$(TargetArchitecture)' != 'wasm'">true</_BuildAnyCrossArch>
329335
<_BuildCrossComponents Condition="$(_subset.Contains('+clr.crossarchtools+'))">true</_BuildCrossComponents>
330336
<_BuildCrossComponents Condition="'$(ClrRuntimeBuildSubsets)' != '' and ('$(PrimaryRuntimeFlavor)' == 'CoreCLR' or '$(TargetsMobile)' == 'true')">true</_BuildCrossComponents>
331337
<_CrossBitwidthBuild Condition="'$(BuildArchitecture)' == 'x64' and ('$(TargetArchitecture)' == 'x86' or '$(TargetArchitecture)' == 'arm')">true</_CrossBitwidthBuild>

eng/pipelines/runtime.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ extends:
117117
eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
118118
eq(variables['isRollingBuild'], true))
119119
120+
- template: /eng/pipelines/common/platform-matrix.yml
121+
parameters:
122+
jobTemplate: /eng/pipelines/common/global-build-job.yml
123+
buildConfig: ${{ variables.debugOnPrReleaseOnRolling }}
124+
platforms:
125+
- browser_wasm
126+
jobParameters:
127+
nameSuffix: AllSubsets_CoreCLR
128+
buildArgs: -s mono.emsdk+clr.paltests -rc Release -c Release -lc $(_BuildConfig)
129+
timeoutInMinutes: 120
130+
condition: >-
131+
or(
132+
eq(stageDependencies.EvaluatePaths.evaluate_paths.outputs['SetPathVars_non_mono_and_wasm.containsChange'], true),
133+
eq(variables['isRollingBuild'], true))
134+
120135
#
121136
# Build CoreCLR and Libraries with Libraries tests
122137
# For running libraries tests and installer tests

src/coreclr/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ if(CORECLR_SET_RPATH)
2929
set(MACOSX_RPATH ON)
3030
endif(CORECLR_SET_RPATH)
3131

32-
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS)
32+
if(CLR_CMAKE_HOST_MACCATALYST OR CLR_CMAKE_HOST_IOS OR CLR_CMAKE_HOST_TVOS OR CLR_CMAKE_HOST_BROWSER)
3333
set(FEATURE_STANDALONE_GC 0)
3434
endif()
3535

@@ -148,8 +148,9 @@ endif()
148148
include_directories("pal/prebuilt/inc")
149149
include_directories(${CLR_ARTIFACTS_OBJ_DIR})
150150

151-
add_subdirectory(tools/aot/jitinterface)
152-
151+
if (NOT CLR_CMAKE_TARGET_BROWSER)
152+
add_subdirectory(tools/aot/jitinterface)
153+
endif (NOT CLR_CMAKE_TARGET_BROWSER)
153154

154155
if(NOT CLR_CROSS_COMPONENTS_BUILD)
155156
# NativeAOT only buildable for a subset of CoreCLR-supported configurations
@@ -262,7 +263,7 @@ if(CLR_CMAKE_HOST_UNIX)
262263
add_subdirectory(nativeresources)
263264
endif(CLR_CMAKE_HOST_UNIX)
264265
265-
if(NOT CLR_CMAKE_HOST_TVOS)
266+
if(NOT CLR_CMAKE_HOST_TVOS AND NOT CLR_CMAKE_HOST_BROWSER)
266267
add_subdirectory(utilcode)
267268
add_subdirectory(inc)
268269
@@ -280,7 +281,7 @@ if(NOT CLR_CMAKE_HOST_TVOS)
280281
add_subdirectory(dlls)
281282
add_subdirectory(unwinder)
282283
add_subdirectory(interop)
283-
endif()
284+
endif(NOT CLR_CMAKE_HOST_TVOS AND NOT CLR_CMAKE_HOST_BROWSER)
284285
285286
if(NOT CLR_CMAKE_HOST_MACCATALYST AND NOT CLR_CMAKE_HOST_IOS AND NOT CLR_CMAKE_HOST_TVOS)
286287
add_subdirectory(tools)

src/coreclr/clrfeatures.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ if(CLR_CMAKE_TARGET_TIZEN_LINUX)
33
endif()
44

55
if(NOT DEFINED FEATURE_EVENT_TRACE)
6-
# To actually disable FEATURE_EVENT_TRACE, also change clr.featuredefines.props
7-
set(FEATURE_EVENT_TRACE 1)
6+
if (NOT CLR_CMAKE_TARGET_BROWSER)
7+
# To actually disable FEATURE_EVENT_TRACE, also change clr.featuredefines.props
8+
set(FEATURE_EVENT_TRACE 1)
9+
endif()
810
endif(NOT DEFINED FEATURE_EVENT_TRACE)
911

1012
if(NOT DEFINED FEATURE_PERFTRACING AND FEATURE_EVENT_TRACE)

src/coreclr/inc/volatile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
#error The Volatile type is currently only defined for Visual C++ and GNU C++
6969
#endif
7070

71-
#if defined(__GNUC__) && !defined(HOST_X86) && !defined(HOST_AMD64) && !defined(HOST_ARM) && !defined(HOST_ARM64) && !defined(HOST_LOONGARCH64) && !defined(HOST_RISCV64) && !defined(HOST_S390X) && !defined(HOST_POWERPC64)
71+
#if defined(__GNUC__) && !defined(HOST_X86) && !defined(HOST_AMD64) && !defined(HOST_ARM) && !defined(HOST_ARM64) && !defined(HOST_LOONGARCH64) && !defined(HOST_RISCV64) && !defined(HOST_S390X) && !defined(HOST_POWERPC64) && !defined(HOST_WASM)
7272
#error The Volatile type is currently only defined for GCC when targeting x86, AMD64, ARM, ARM64, LOONGARCH64, RISCV64, PPC64LE, or S390X CPUs
7373
#endif
7474

src/coreclr/interpreter/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ else()
2828
add_custom_target(interpreter_exports DEPENDS ${EXPORTS_FILE})
2929
endif()
3030

31-
add_library_clr(clrinterpreter SHARED ${INTERPRETER_SOURCES})
31+
if(CLR_CMAKE_TARGET_BROWSER)
32+
set(LIBRARY_TYPE STATIC)
33+
else()
34+
set(LIBRARY_TYPE SHARED)
35+
endif()
36+
37+
add_library_clr(clrinterpreter ${LIBRARY_TYPE} ${INTERPRETER_SOURCES})
3238

3339
add_dependencies(clrinterpreter interpreter_exports)
3440

src/coreclr/jit/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ elseif(CLR_CMAKE_TARGET_ARCH_LOONGARCH64)
495495
elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
496496
set(JIT_ARCH_SOURCES ${JIT_RISCV64_SOURCES})
497497
set(JIT_ARCH_HEADERS ${JIT_RISCV64_HEADERS})
498+
elseif(CLR_CMAKE_TARGET_ARCH_WASM)
499+
set(JIT_ARCH_SOURCES ${JIT_WASM32_SOURCES})
500+
set(JIT_ARCH_HEADERS ${JIT_WASM32_HEADERS})
498501
else()
499502
clr_unknown_arch()
500503
endif()

src/coreclr/pal/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ include_directories(${COREPAL_SOURCE_DIR}/inc)
66
include_directories(${COREPAL_SOURCE_DIR}/src)
77
include_directories(${COREPAL_SOURCE_DIR}/../inc)
88

9-
add_compile_options(-fexceptions)
9+
if (NOT CLR_CMAKE_TARGET_BROWSER)
10+
add_compile_options(-fexceptions)
11+
else()
12+
add_compile_options(-fwasm-exceptions)
13+
add_link_options(-fwasm-exceptions -sEXIT_RUNTIME=1)
14+
endif()
1015

1116
add_subdirectory(src)
1217
add_subdirectory(tests)

src/coreclr/pal/inc/pal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,26 @@ typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
24692469
//
24702470

24712471
} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
2472+
#elif defined(HOST_WASM)
2473+
#define CONTEXT_CONTROL 0
2474+
#define CONTEXT_INTEGER 0
2475+
#define CONTEXT_FLOATING_POINT 0
2476+
#define CONTEXT_FULL 0
2477+
2478+
#define CONTEXT_XSTATE 0
2479+
2480+
#define CONTEXT_EXCEPTION_ACTIVE 0x8000000L
2481+
#define CONTEXT_SERVICE_ACTIVE 0x10000000L
2482+
#define CONTEXT_EXCEPTION_REQUEST 0x40000000L
2483+
#define CONTEXT_EXCEPTION_REPORTING 0x80000000L
2484+
2485+
typedef struct _CONTEXT {
2486+
ULONG ContextFlags;
2487+
} CONTEXT, *PCONTEXT, *LPCONTEXT;
2488+
2489+
typedef struct _KNONVOLATILE_CONTEXT_POINTERS {
2490+
DWORD none;
2491+
} KNONVOLATILE_CONTEXT_POINTERS, *PKNONVOLATILE_CONTEXT_POINTERS;
24722492

24732493
#else
24742494
#error Unknown architecture for defining CONTEXT.
@@ -2600,6 +2620,8 @@ PALIMPORT BOOL PALAPI PAL_GetUnwindInfoSize(SIZE_T baseAddress, ULONG64 ehFrameH
26002620
#define PAL_CS_NATIVE_DATA_SIZE 96
26012621
#elif defined(__HAIKU__) && defined(__x86_64__)
26022622
#define PAL_CS_NATIVE_DATA_SIZE 56
2623+
#elif defined(HOST_WASM)
2624+
#define PAL_CS_NATIVE_DATA_SIZE 76
26032625
#else
26042626
#error PAL_CS_NATIVE_DATA_SIZE is not defined for this architecture
26052627
#endif

src/coreclr/pal/inc/rt/palrt.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,14 @@ typedef struct _DISPATCHER_CONTEXT {
10031003
DWORD Reserved;
10041004
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
10051005

1006+
#elif defined(HOST_WASM)
1007+
1008+
typedef struct _DISPATCHER_CONTEXT {
1009+
// WASM does not build the VM or JIT at this point,
1010+
// so we only provide a dummy definition.
1011+
DWORD Reserved;
1012+
} DISPATCHER_CONTEXT, *PDISPATCHER_CONTEXT;
1013+
10061014
#else
10071015

10081016
#error Unknown architecture for defining DISPATCHER_CONTEXT.

0 commit comments

Comments
 (0)