Skip to content

Commit e572463

Browse files
Remove corewasmrun (#120541)
Update corerun to operate like corewasmrun when manually setting `CORERUN_IN_BROWSER` to `1` in src\coreclr\hosts\corerun\CMakeLists.txt. This allows corerun to operate in the same mode as corewasmrun.
1 parent 4839d27 commit e572463

File tree

10 files changed

+82
-183
lines changed

10 files changed

+82
-183
lines changed

docs/workflow/building/coreclr/wasm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ dotnet tool install --global dotnet-serve
4848

4949
**Linux/macOS:**
5050
```bash
51-
dotnet-serve --directory "artifacts/bin/coreclr/browser.wasm.Debug/corewasmrun"
51+
dotnet-serve --directory "artifacts/bin/coreclr/browser.wasm.Debug"
5252
```
5353

5454
**Windows:**
5555
```cmd
56-
dotnet-serve --directory "artifacts\bin\coreclr\browser.wasm.Debug\corewasmrun"
56+
dotnet-serve --directory "artifacts\bin\coreclr\browser.wasm.Debug"
5757
```
5858

5959
This will start a local HTTP server and you can open the provided URL in your browser.
@@ -155,7 +155,7 @@ Note that for `corerun` path in the `args` and `CORE_ROOT` need to be **absolute
155155

156156
3. **Copy managed DLLs** `System.Runtime.dll` and `helloworld.dll` into `artifacts/bin/coreclr/browser.wasm.Debug/IL/`.
157157

158-
4. **Set breakpoints** in `corewasmrun.js` in one of the `put_char` functions (the `stdout`/`stderr` implementation)
158+
4. **Set breakpoints** in `corerun.js` in one of the `put_char` functions (the `stdout`/`stderr` implementation)
159159

160160
5. **Start debugging** and step through the WebAssembly code using the call stack
161161

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ project(corerun)
22

33
set(CMAKE_INCLUDE_CURRENT_DIR ON)
44

5+
set(CORERUN_IN_BROWSER 0)
6+
57
if(CLR_CMAKE_HOST_WIN32)
68
add_definitions(-DFX_VER_INTERNALNAME_STR=corerun.exe)
7-
else(CLR_CMAKE_HOST_WIN32)
9+
else()
810
include(configure.cmake)
9-
endif(CLR_CMAKE_HOST_WIN32)
11+
endif()
1012

11-
#Required to expose symbols for global symbol discovery.
13+
# Required to expose symbols for global symbol discovery.
1214
set(CLR_CMAKE_KEEP_NATIVE_SYMBOLS TRUE)
1315

1416
add_executable_clr(corerun
@@ -33,36 +35,39 @@ if(CLR_CMAKE_HOST_WIN32)
3335
if (CLR_CMAKE_HOST_ARCH_AMD64)
3436
target_link_options(corerun PRIVATE "/CETCOMPAT")
3537
endif()
36-
else(CLR_CMAKE_HOST_WIN32)
38+
else()
3739
target_link_libraries(corerun PRIVATE ${CMAKE_DL_LIBS})
3840
# Required to expose symbols for global symbol discovery
3941
target_link_libraries(corerun PRIVATE -rdynamic)
4042

41-
# Android implements pthread natively
43+
# Android implements pthread natively.
44+
# WASM, linking against pthreads indicates Node.js workers are
45+
# enabled and not suitable for the browser.
4246
if(NOT CLR_CMAKE_TARGET_ANDROID AND NOT CLR_CMAKE_TARGET_ARCH_WASM)
4347
target_link_libraries(corerun PRIVATE pthread)
4448
endif()
4549
# Static linking
4650
if (CLR_CMAKE_TARGET_ARCH_WASM)
47-
target_sources(corerun PRIVATE corerun.wasm.cpp)
51+
target_sources(corerun PRIVATE ./wasm/pinvoke_override.cpp)
52+
target_include_directories(corerun PRIVATE ./wasm/)
4853
target_link_libraries(corerun PRIVATE
49-
coreclr_static
50-
System.Native-Static
51-
System.Native.TimeZoneData)
54+
coreclr_static
55+
System.Native-Static
56+
System.Native.TimeZoneData)
5257
# linker options for NodeJs, link in JavaScript helper, access to local filesystem
5358
if (CLR_CMAKE_TARGET_BROWSER)
54-
target_compile_options(corerun PRIVATE
59+
target_compile_options(corerun PRIVATE
5560
-fwasm-exceptions
5661
-msimd128
5762
)
58-
target_link_libraries(corerun PRIVATE
63+
target_link_libraries(corerun PRIVATE
5964
System.Native.Browser-Static)
6065
set(JS_SYSTEM_NATIVE_BROWSER
6166
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Native.Browser.js")
6267
set(JS_SYSTEM_BROWSER_UTILS
6368
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Browser.Utils.js")
6469
set(JS_CORE_RUN_PRE
65-
"${CMAKE_CURRENT_SOURCE_DIR}/libCorerun.pre.js")
70+
"${CMAKE_CURRENT_SOURCE_DIR}/wasm/libCorerun.pre.js")
6671
set_target_properties(corerun PROPERTIES
6772
LINK_DEPENDS "${JS_CORE_RUN_PRE};${JS_SYSTEM_NATIVE_BROWSER};${JS_SYSTEM_BROWSER_UTILS};"
6873
LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS}"
@@ -71,11 +76,30 @@ else(CLR_CMAKE_HOST_WIN32)
7176
-fwasm-exceptions
7277
-sEXIT_RUNTIME=1
7378
-sINITIAL_MEMORY=134217728
74-
-sENVIRONMENT=node,shell
7579
-sSTACK_SIZE=5MB
76-
-lnoderawfs.js
77-
-lnodefs.js
80+
-sENVIRONMENT=node,shell,web
7881
-Wl,-error-limit=0)
82+
83+
if (CORERUN_IN_BROWSER)
84+
# Include the virtual file system data for the
85+
# browser scenario.
86+
set(WASM_PRELOAD_DIR "${CMAKE_INSTALL_PREFIX}/IL")
87+
if (EXISTS "${WASM_PRELOAD_DIR}")
88+
target_link_options(corerun PRIVATE
89+
--preload-file ${WASM_PRELOAD_DIR}@/)
90+
endif()
91+
else()
92+
# If not running in the browser, add
93+
# Node.js file system support.
94+
target_link_options(corerun PRIVATE
95+
-lnoderawfs.js
96+
-lnodefs.js)
97+
endif()
98+
endif()
99+
100+
if (CORERUN_IN_BROWSER)
101+
# Install the HTML file for running in the browser.
102+
install(FILES "./wasm/corerun.html" DESTINATION . COMPONENT hosts)
79103
endif()
80104
endif()
81105
endif(CLR_CMAKE_HOST_WIN32)

src/coreclr/hosts/corerun/corerun.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
#include "dotenv.hpp"
1111

1212
#ifdef TARGET_WASM
13-
#include "corerun.wasm.hpp"
14-
#endif
13+
#include <pinvoke_override.hpp>
14+
#endif // TARGET_WASM
1515

1616
#include <fstream>
1717

@@ -79,6 +79,7 @@ namespace envvar
7979
// - PROPERTY: corerun will pass the paths vias the TRUSTED_PLATFORM_ASSEMBLIES property
8080
// - EXTERNAL: corerun will pass an external assembly probe to the runtime for app assemblies
8181
// - Not set: same as PROPERTY
82+
// - The TPA list as a platform delimited list of paths. The same format as the system's PATH env var.
8283
const char_t* appAssemblies = W("APP_ASSEMBLIES");
8384
}
8485

@@ -167,7 +168,7 @@ static bool try_get_export(pal::mod_t mod, const char* symbol, void** fptr)
167168
*fptr = pal::get_module_symbol(mod, symbol);
168169
if (*fptr != nullptr)
169170
return true;
170-
#else // !TARGET_WASM
171+
#else // !TARGET_WASM
171172
if (!strcmp(symbol, "coreclr_initialize")){
172173
*fptr = (void*)coreclr_initialize;
173174
return true;
@@ -380,8 +381,7 @@ static int run(const configuration& config)
380381
}
381382
else
382383
{
383-
pal::fprintf(stderr, W("Unknown value for APP_ASSEMBLIES environment variable: %s\n"), app_assemblies_env.c_str());
384-
return -1;
384+
tpa_list = std::move(app_assemblies_env);
385385
}
386386

387387
{
@@ -492,8 +492,8 @@ static int run(const configuration& config)
492492

493493
#ifdef TARGET_WASM
494494
// install the pinvoke override callback to resolve p/invokes to statically linked libraries
495-
wasm_add_pinvoke_override();
496-
#endif
495+
add_pinvoke_override();
496+
#endif // TARGET_WASM
497497

498498
int result;
499499
result = coreclr_init_func(

src/coreclr/hosts/corewasmrun/index.html renamed to src/coreclr/hosts/corerun/wasm/corerun.html

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<title>corewasmrun</title>
5+
<title>corerun-wasm</title>
66
</head>
77
<body>
8-
<h1>corewasmrun</h1>
8+
<h1>corerun-wasm</h1>
99
<pre id="log"></pre>
1010
<script>
1111
Module = {
12+
arguments: [
13+
"HelloWorld.dll"
14+
],
1215
preRun: [ function () {
13-
ENV.PAL_DBG_CHANNELS="+all.all";
14-
// ENV.PAL_DBG_CHANNELS="+all.ERROR";
15-
}],
16+
// Build the TPA list and set the APP_ASSEMBLIES environment variable.
17+
const path = "/";
18+
let tpaList = "";
19+
let files = FS.readdir(path);
20+
files.forEach(function(file) {
21+
if (file.endsWith(".dll")) {
22+
tpaList += (tpaList.length > 0 ? ":" : "") + path + file;
23+
}
24+
});
25+
26+
ENV["APP_ASSEMBLIES"] = tpaList;
27+
} ],
1628
onExit: function (code) {
1729
console.log("onExit, code: " + code);
1830
},
@@ -21,7 +33,7 @@ <h1>corewasmrun</h1>
2133
const originalConsoleLog = console.log;
2234
console.log = function(message) {
2335
originalConsoleLog(message);
24-
fetch('/log=corewasmrun-log.txt', {
36+
fetch('/log=corerun-wasm-log.txt', {
2537
method: 'POST',
2638
body: ('stdout: ' + message),
2739
headers: {
@@ -35,7 +47,7 @@ <h1>corewasmrun</h1>
3547
const originalConsoleError = console.error;
3648
console.error = function(message) {
3749
originalConsoleError(message);
38-
fetch('/log=corewasmrun-log.txt', {
50+
fetch('/log=corerun-wasm-log.txt', {
3951
method: 'POST',
4052
body: ('stderr: ' + message),
4153
headers: {
@@ -48,5 +60,5 @@ <h1>corewasmrun</h1>
4860
document.querySelector("#log").appendChild(elt);
4961
};
5062
</script>
51-
<script src="corewasmrun.js"></script>
63+
<script src="corerun.js"></script>
5264
</body>

src/coreclr/hosts/corerun/libCorerun.pre.js renamed to src/coreclr/hosts/corerun/wasm/libCorerun.pre.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ var dotnetInternals = [
44
},
55
[],
66
];
7-
Module.preRun = () => {
7+
var basePreRun = () => {
88
// copy all node/shell env variables to emscripten env
99
if (globalThis.process && globalThis.process.env) {
1010
for (const [key, value] of Object.entries(process.env)) {
1111
ENV[key] = value;
1212
}
1313
}
14+
1415
ENV["DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"] = "true";
15-
};
16+
};
17+
18+
// Append to or set the preRun array
19+
Module.preRun = Module.preRun || [];
20+
Module.preRun.push(basePreRun);

src/coreclr/hosts/corerun/corerun.wasm.cpp renamed to src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ extern "C" const void* SystemResolveDllImport(const char* name);
1111

1212
// pinvoke_override:
1313
// Check if given function belongs to one of statically linked libraries and return a pointer if found.
14-
const void* pinvoke_override(const char* library_name, const char* entry_point_name)
14+
static const void* pinvoke_override(const char* library_name, const char* entry_point_name)
1515
{
1616
// This function is only called with the library name specified for a p/invoke, not any variations.
1717
// It must handle exact matches to the names specified. See Interop.Libraries.cs for each platform.
@@ -23,7 +23,7 @@ const void* pinvoke_override(const char* library_name, const char* entry_point_n
2323
return nullptr;
2424
}
2525

26-
void wasm_add_pinvoke_override()
26+
void add_pinvoke_override()
2727
{
2828
PInvokeOverride::SetPInvokeOverride(pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration);
2929
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
#ifndef __CORERUN_WASM_HPP__
5-
#define __CORERUN_WASM_HPP__
4+
#ifndef __PINVOKE_OVERRIDE_HPP__
5+
#define __PINVOKE_OVERRIDE_HPP__
66

7-
void wasm_add_pinvoke_override();
7+
void add_pinvoke_override();
88

9-
#endif // __CORERUN_WASM_HPP__
9+
#endif // __PINVOKE_OVERRIDE_HPP__

src/coreclr/hosts/corewasmrun/CMakeLists.txt

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)