Skip to content
Merged
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
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
43 changes: 36 additions & 7 deletions docs/workflow/building/coreclr/wasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,27 @@ This will start a local HTTP server and you can open the provided URL in your br
### Console Testing

You can also run the runtime directly in Node.js:
In script below please replace `/path/to/runtime/` by a **absolute unix path** to the actual runtime repo (even on Windows).

```bash
cp /runtime3/artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Debug/runtimes/browser-wasm/lib/net10.0/*.dll /runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL
cp helloworld.dll /runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL
cd /runtime3/artifacts/bin/coreclr/browser.wasm.Debug/
node ./corerun.js -c /runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL /runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL/helloworld.dll
cp ./artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Debug/runtimes/browser-wasm/lib/net10.0/*.dll ./artifacts/bin/coreclr/browser.wasm.Debug/IL
cp helloworld.dll ./artifacts/bin/coreclr/browser.wasm.Debug/IL
cd ./artifacts/bin/coreclr/browser.wasm.Debug/
node ./corerun.js -c /path/to/runtime/artifacts/bin/coreclr/browser.wasm.Debug/IL /path/to/runtime/artifacts/bin/coreclr/browser.wasm.Debug/IL/helloworld.dll
```

Note that path in the node args need to be **absolute path** on your host file system in **unix format** (even on Windows).
### Console Testing with corehost

You can also run the corehost directly in Node.js:

```bash
cp ./artifacts/bin/microsoft.netcore.app.runtime.browser-wasm/Debug/runtimes/browser-wasm/lib/net10.0/*.dll ./artifacts/bin/coreclr/browser.wasm.Debug/corehost
cp helloworld.dll ./artifacts/bin/coreclr/browser.wasm.Debug/corehost
cd ./artifacts/bin/coreclr/browser.wasm.Debug/corehost
node ./main.mjs
```

Note that paths to assemblies are in the `src/native/corehost/browserhost/sample/dotnet.boot.js`

## Debugging

Expand Down Expand Up @@ -97,6 +109,9 @@ VS Code, through Node.js, provides a good debugging option for WebAssembly CoreC
- [WebAssembly Dwarf Debugging](https://marketplace.visualstudio.com/items?itemName=ms-vscode.wasm-dwarf-debugging)

2. **Create a launch.json configuration:**

In config below please replace `/path/to/runtime/` by a **absolute unix path** to the actual runtime repo (even on Windows).

```json
{
"version": "0.2.0",
Expand All @@ -111,12 +126,26 @@ VS Code, through Node.js, provides a good debugging option for WebAssembly CoreC
"outputCapture": "std",
"program": "corerun.js",
"env": {
"CORE_ROOT":"/runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL/"
"CORE_ROOT":"/path/to/runtime/artifacts/bin/coreclr/browser.wasm.Debug/IL/"
},
"args": [
"/runtime3/artifacts/bin/coreclr/browser.wasm.Debug/IL/helloworld.dll"
"/path/to/runtime/artifacts/bin/coreclr/browser.wasm.Debug/IL/helloworld.dll"
],
"cwd": "${workspaceFolder}/artifacts/bin/coreclr/browser.wasm.Debug/"
},
{
"name": "browserhost",
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"args": [
"HelloWorld.dll"
],
"outputCapture": "std",
"cwd": "${workspaceFolder}/artifacts/bin/coreclr/browser.wasm.Debug/corehost",
"program": "main.mjs",
}
]
}
Expand Down
8 changes: 8 additions & 0 deletions eng/pipelines/common/evaluate-default-paths.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ parameters:
src/tasks/Microsoft.NET.WebAssembly.Webcil/*
src/tests/Common/wasm-test-runner/*
src/coreclr/vm/wasm/*
src/native/corehost/browserhost/*
src/native/libs/Common/JavaScript/*
src/native/libs/System.Native.Browser/*
src/native/libs/System.Runtime.InteropServices.JavaScript.Native/*
]
_wasm_pipelines: [
eng/pipelines/**/*wasm*
Expand All @@ -57,6 +61,10 @@ parameters:
src/native/libs/System.Globalization.Native/*
src/native/libs/System.IO.Compression.Native/*
src/native/libs/System.Native/*
src/native/corehost/browserhost/*
src/native/libs/Common/JavaScript/*
src/native/libs/System.Native.Browser/*
src/native/libs/System.Runtime.InteropServices.JavaScript.Native/*
]
_wasm_chrome: [
eng/testing/bump-chrome-version.proj
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ if(NOT CLR_CROSS_COMPONENTS_BUILD AND NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT C
add_dependencies(runtime singlefilehost)
else()
if(CLR_CMAKE_TARGET_BROWSER)
# TODOWASM set GEN_PINVOKE to 1 once we generate them. static entrypoint.c prevents C linker from trimming, when IL trimming trims PInvokes
# WASM-TODO set GEN_PINVOKE to 1 once we generate them. static entrypoint.c prevents C linker from trimming, when IL trimming trims PInvokes
set(GEN_PINVOKE 0)
# WASM-TODO should we start using System.Native.Browser and System.Runtime.InteropServices.JavaScript.Native also for Mono ?
set(BUILD_LIBS_NATIVE_BROWSER 1)
add_subdirectory(${CLR_SRC_NATIVE_DIR}/corehost browserhost)
add_dependencies(runtime browserhost)
endif()
endif()

Expand Down
13 changes: 11 additions & 2 deletions src/coreclr/hosts/corerun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,24 @@ else(CLR_CMAKE_HOST_WIN32)
# linker options for NodeJs, link in JavaScript helper, access to local filesystem
if (CLR_CMAKE_TARGET_BROWSER)
target_compile_options(corerun PRIVATE -fwasm-exceptions)
target_link_libraries(corerun PRIVATE
System.Native.Browser-Static)
set(JS_SYSTEM_NATIVE_BROWSER
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Native.Browser.js")
set(JS_CORE_RUN_PRE
"${CMAKE_CURRENT_SOURCE_DIR}/libCorerun.pre.js")
set_target_properties(corerun PROPERTIES
LINK_DEPENDS "${JS_CORE_RUN_PRE};${JS_SYSTEM_NATIVE_BROWSER};"
LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
target_link_options(corerun PRIVATE
-fwasm-exceptions
-sEXPORTED_RUNTIME_METHODS=FS
-sEXIT_RUNTIME=1
-sINITIAL_MEMORY=134217728
-sENVIRONMENT=node,shell
-sSTACK_SIZE=5MB
-lnoderawfs.js
-lnodefs.js
--pre-js ${CMAKE_CURRENT_SOURCE_DIR}/corerun.js
-Wl,-error-limit=0)
endif()
endif()
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/hosts/corerun/corerun.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/coreclr/hosts/corerun/libCorerun.pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var dotnetInternals = {
runtimeApi: {
Module: Module,
},
updates: [],
};
Module.preRun = () => {
// copy all node/shell env variables to emscripten env
if (globalThis.process && globalThis.process.env) {
for (const [key, value] of Object.entries(process.env)) {
ENV[key] = value;
}
}
};
10 changes: 10 additions & 0 deletions src/coreclr/hosts/corewasmrun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ target_include_directories(corewasmrun PRIVATE
)

target_compile_options(corewasmrun PRIVATE -fwasm-exceptions)

set(JS_SYSTEM_NATIVE_BROWSER
"${CLR_ARTIFACTS_OBJ_DIR}/native/browser-${CMAKE_BUILD_TYPE}-wasm/System.Native.Browser/libSystem.Native.Browser.js")
set(JS_CORE_WASM_RUN_PRE
"${CMAKE_CURRENT_SOURCE_DIR}/libCorewasmrun.pre.js")
set_target_properties(corewasmrun PROPERTIES
LINK_DEPENDS "${JS_CORE_WASM_RUN_PRE};${JS_SYSTEM_NATIVE_BROWSER};"
LINK_FLAGS "--pre-js ${JS_CORE_WASM_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
target_link_options(corewasmrun PRIVATE
-fwasm-exceptions
-sEXIT_RUNTIME=1
Expand All @@ -27,6 +36,7 @@ target_link_options(corewasmrun PRIVATE
-Wl,-error-limit=0)
target_link_libraries(corewasmrun PRIVATE
coreclr_static
System.Native.Browser-Static
System.Native-Static
System.Native.TimeZoneData)

Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/hosts/corewasmrun/libCorewasmrun.pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var dotnetInternals = {
runtimeApi: {
Module: Module,
},
updates: [],
};
2 changes: 1 addition & 1 deletion src/coreclr/vm/dllimportcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ UMEntryThunkData* UMEntryThunkData::CreateUMEntryThunk()
pData = (UMEntryThunkData *)pamTracker->Track(pLoaderAllocator->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(UMEntryThunkData))));
UMEntryThunk* pThunk;
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
PORTABILITY_ASSERT("WASMTODO: Marshalled delegates are not supported with wasm.");
PORTABILITY_ASSERT("WASM-TODO: Marshalled delegates are not supported with wasm.");
pThunk = NULL;
#else // !FEATURE_PORTABLE_ENTRYPOINTS
pThunk = (UMEntryThunk*)pamTracker->Track(pLoaderAllocator->GetNewStubPrecodeHeap()->AllocStub());
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/interpexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2300,7 +2300,7 @@ void InterpExecMethod(InterpreterFrame *pInterpreterFrame, InterpMethodContextFr
{
PCODE calliFunctionPointer = LOCAL_VAR(calliFunctionPointerVar, PCODE);
#ifdef FEATURE_PORTABLE_ENTRYPOINTS
// WASMTODO: We may end up here with native JIT helper entrypoint without MethodDesc
// WASM-TODO: We may end up here with native JIT helper entrypoint without MethodDesc
// that CALL_INTERP_METHOD is not able to handle. This is a potential problem for
// interpreter<->native code stub generator.
// https://github.com/dotnet/runtime/pull/119516#discussion_r2337631271
Expand Down
10 changes: 2 additions & 8 deletions src/coreclr/vm/wasm/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,6 @@ void _DacGlobals::Initialize()
// Incorrectly typed temporary symbol to satisfy the linker.
int g_pDebugger;

extern "C" int32_t SystemJS_RandomBytes(uint8_t* buffer, int32_t bufferLength)
{
PORTABILITY_ASSERT("SystemJS_RandomBytes is not implemented");
return -1;
}

void InvokeCalliStub(PCODE ftn, void* cookie, int8_t *pArgs, int8_t *pRet)
{
_ASSERTE(ftn != (PCODE)NULL);
Expand All @@ -399,7 +393,7 @@ void InvokeUnmanagedCalli(PCODE ftn, void *cookie, int8_t *pArgs, int8_t *pRet)
_ASSERTE(ftn != (PCODE)NULL);
_ASSERTE(cookie != NULL);

// WASMTODO: Reconcile calling conventions.
// WASM-TODO: Reconcile calling conventions.
((void(*)(PCODE, int8_t*, int8_t*))cookie)(ftn, pArgs, pRet);
}

Expand Down Expand Up @@ -571,7 +565,7 @@ namespace
case ELEMENT_TYPE_VALUETYPE:
{
// In WASM, values types that are larger than pointer size or have multiple fields are passed indirectly.
// WASMTODO: Single fields may not always be passed as i32. Floats and doubles are passed as f32 and f64 respectively.
// WASM-TODO: Single fields may not always be passed as i32. Floats and doubles are passed as f32 and f64 respectively.
TypeHandle vt = isReturn
? sig.GetRetTypeHandleThrowing()
: sig.GetLastTypeHandleThrowing();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.so" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Native.Browser.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Runtime.InteropServices.JavaScript.Native.a" IsNative="true" />
<PlatformManifestFileEntry Include="coreclr.dll" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclr.so" IsNative="true" />
<PlatformManifestFileEntry Include="libcoreclr.dylib" IsNative="true" />
Expand Down
3 changes: 3 additions & 0 deletions src/native/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
./corehost/browserhost/loader/dotnet.d.ts
./**/*.js
./**/*.mjs
65 changes: 65 additions & 0 deletions src/native/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = {
"env": {
"browser": true,
"es2021": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"ignorePatterns": [
"node_modules/**/*.*",
"bin/**/*.*",
"obj/**/*.*",
"**/*.js",
"**/*.mjs",
"dotnet.d.ts",
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-loss-of-precision": "off",
"indent": [
"error",
4,
{
SwitchCase: 1,
"ignoredNodes": ["VariableDeclaration[declarations.length=0]"] // fixes https://github.com/microsoft/vscode-eslint/issues/1149
}
],
"no-multi-spaces": ["error"],
"no-console": ["error"],
"arrow-spacing": ["error"],
"block-spacing": ["error"],
"comma-spacing": ["error"],
"quotes": [
"error",
"double"
],
"semi": [
"error",
"always"
],
"brace-style": ["error"],
"eol-last": ["error"],
"space-before-blocks": ["error"],
"semi-spacing": ["error"],
"keyword-spacing": ["error"],
"no-trailing-spaces": ["error"],
"object-curly-spacing": ["error", "always"],
"array-bracket-spacing": ["error"],
"space-infix-ops": ["error"],
"func-call-spacing": ["error", "never"],
"space-before-function-paren": ["error", "never"],
}
};
File renamed without changes.
37 changes: 21 additions & 16 deletions src/native/corehost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,30 @@ if(CLR_CMAKE_TARGET_LINUX OR CLR_CMAKE_TARGET_SUNOS)
add_link_options(LINKER:-Bsymbolic)
endif()

add_library(fxr_resolver INTERFACE)
target_sources(fxr_resolver INTERFACE fxr_resolver.cpp)
target_include_directories(fxr_resolver INTERFACE fxr)
if(NOT CLR_CMAKE_TARGET_BROWSER)
add_library(fxr_resolver INTERFACE)
target_sources(fxr_resolver INTERFACE fxr_resolver.cpp)
target_include_directories(fxr_resolver INTERFACE fxr)

add_compile_definitions(RAPIDJSON_HAS_CXX17)
add_compile_definitions(RAPIDJSON_HAS_CXX17)

if ((NOT DEFINED CLR_CMAKE_USE_SYSTEM_RAPIDJSON) OR (NOT CLR_CMAKE_USE_SYSTEM_RAPIDJSON))
include_directories(${CLR_SRC_NATIVE_DIR}/external/)
endif()

add_subdirectory(hostcommon)
add_subdirectory(hostmisc)
add_subdirectory(fxr)
add_subdirectory(hostpolicy)
if ((NOT DEFINED CLR_CMAKE_USE_SYSTEM_RAPIDJSON) OR (NOT CLR_CMAKE_USE_SYSTEM_RAPIDJSON))
include_directories(${CLR_SRC_NATIVE_DIR}/external/)
endif()

add_subdirectory(apphost)
add_subdirectory(dotnet)
add_subdirectory(nethost)
add_subdirectory(test)
add_subdirectory(hostcommon)
add_subdirectory(hostmisc)
add_subdirectory(fxr)
add_subdirectory(hostpolicy)

add_subdirectory(apphost)
add_subdirectory(dotnet)
add_subdirectory(nethost)
add_subdirectory(test)
else()
add_subdirectory(hostmisc)
add_subdirectory(browserhost)
endif()

# If there's a dynamic ASAN runtime, then install it in the directories where we put our executables.
if (NOT "${ASAN_RUNTIME}" STREQUAL "")
Expand Down
Loading
Loading