Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 0 additions & 28 deletions eng/native.props

This file was deleted.

78 changes: 78 additions & 0 deletions eng/native.wasm.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<Project>
<ItemGroup>
<PackageReference Condition="'$(TargetsWasm)' == 'true'" Include="Microsoft.NETCore.Runtime.ICU.Transport" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
<PackageReference Condition="'$(TargetsWasm)' == 'true'" Include="System.Runtime.TimeZoneData" PrivateAssets="all" Version="$(SystemRuntimeTimeZoneDataVersion)" GeneratePathProperty="true" />
</ItemGroup>

<PropertyGroup>
<_RuntimeVariant />
<_RuntimeVariant Condition="'$(WasmEnableThreads)' == 'true'">-threads</_RuntimeVariant>

<_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != '' and '$(TargetsWasm)' == 'true'">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native</_IcuDir>
<_TzdDir Condition="'$(PkgSystem_Runtime_TimeZoneData)' != '' and '$(TargetsWasm)' == 'true'">$([MSBuild]::NormalizePath('$(PkgSystem_Runtime_TimeZoneData)', 'contentFiles', 'any', 'any', 'data'))</_TzdDir>
</PropertyGroup>

<ItemGroup>
<NativeCMakeArg Condition="'$(_IcuDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_ICU_DIR=$(_IcuDir)&quot;" />
<NativeCMakeArg Condition="'$(_TzdDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_TZD_DIR=$(_TzdDir)&quot;" />
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'Mono'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_MONO=1&quot;" />
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'CoreCLR'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_CORECLR=1&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_PRODUCT_VERSION=$(ProductVersion)&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_CONTINUOUS_INTEGRATION_BUILD=$(ContinuousIntegrationBuild)&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_NET_CORE_APP_CURRENT_VERSION=$(NetCoreAppCurrentVersion)&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_BUILD_LIBRARIES_CONFIGURATION=$(LibrariesConfiguration)&quot;" />
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_BUILD_RUNTIME_CONFIGURATION=$(RuntimeConfiguration)&quot;" />
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'" Include="-cmakeargs &quot;-DBUILD_LIBS_NATIVE_BROWSER=1&quot;" />
</ItemGroup>

<Target Name="GenerateEmccExports" Condition="'$(TargetsBrowser)' == 'true'">
<ItemGroup>
<EmccExportedRuntimeMethod Include="FS" />
<EmccExportedRuntimeMethod Include="out" />
<EmccExportedRuntimeMethod Include="err" />
<EmccExportedRuntimeMethod Include="ccall" />
<EmccExportedRuntimeMethod Include="cwrap" />
<EmccExportedRuntimeMethod Include="setValue" />
<EmccExportedRuntimeMethod Include="getValue" />
<EmccExportedRuntimeMethod Include="UTF8ToString" />
<EmccExportedRuntimeMethod Include="UTF8ArrayToString" />
<EmccExportedRuntimeMethod Include="lengthBytesUTF8" />
<EmccExportedRuntimeMethod Include="stringToUTF8Array" />
<EmccExportedRuntimeMethod Include="FS_createPath" />
<EmccExportedRuntimeMethod Include="FS_createDataFile" />
<EmccExportedRuntimeMethod Include="removeRunDependency" />
<EmccExportedRuntimeMethod Include="addRunDependency" />
<EmccExportedRuntimeMethod Include="addFunction" />
<EmccExportedRuntimeMethod Include="safeSetTimeout" />
<EmccExportedRuntimeMethod Include="runtimeKeepalivePush" />
<EmccExportedRuntimeMethod Include="runtimeKeepalivePop" />
<EmccExportedRuntimeMethod Include="maybeExit" />
<EmccExportedRuntimeMethod Include="abort" />

<EmccExportedFunction Include="_free" />
<EmccExportedFunction Include="_htons" />
<EmccExportedFunction Include="_malloc" />
<EmccExportedFunction Include="_sbrk" />
<EmccExportedFunction Include="_memalign" />
<EmccExportedFunction Include="_posix_memalign" />
<EmccExportedFunction Include="_memset" />
<EmccExportedFunction Include="_ntohs" />
<EmccExportedFunction Include="stackAlloc" />
<EmccExportedFunction Include="stackRestore" />
<EmccExportedFunction Include="stackSave" />
<!-- TODO-WASM hide -->
<EmccExportedFunction Include="_GetDotNetRuntimeContractDescriptor" />
</ItemGroup>
<PropertyGroup>
<_EmccExportedRuntimeMethods>@(EmccExportedRuntimeMethod -> '%(Identity)',',')</_EmccExportedRuntimeMethods>
<_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',')</_EmccExportedFunctions>
</PropertyGroup>

<ItemGroup>
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true'" Include="-cmakeargs &quot;-DCMAKE_EMCC_EXPORTED_RUNTIME_METHODS=$(_EmccExportedRuntimeMethods)&quot;" />
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true'" Include="-cmakeargs &quot;-DCMAKE_EMCC_EXPORTED_FUNCTIONS=$(_EmccExportedFunctions)&quot;" />
</ItemGroup>

</Target>

</Project>
17 changes: 10 additions & 7 deletions src/coreclr/hosts/corerun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ else()
"${STATIC_LIB_DESTINATION}/libSystem.Native.Browser.js")
set(JS_SYSTEM_BROWSER_UTILS
"${STATIC_LIB_DESTINATION}/libSystem.Browser.Utils.js")
set(JS_CORE_RUN_PRE
"${CMAKE_CURRENT_SOURCE_DIR}/wasm/libCorerun.pre.js")
set(JS_CORE_RUN
"${CMAKE_CURRENT_SOURCE_DIR}/wasm/libCorerun.extpost.js")
set_target_properties(corerun PROPERTIES
LINK_DEPENDS "${JS_CORE_RUN_PRE};${JS_SYSTEM_NATIVE_BROWSER};${JS_SYSTEM_BROWSER_UTILS};"
LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS}"
LINK_DEPENDS "${JS_CORE_RUN};${JS_SYSTEM_NATIVE_BROWSER};${JS_SYSTEM_BROWSER_UTILS};"
LINK_FLAGS "--js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS} --extern-post-js ${JS_CORE_RUN}"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
target_link_options(corerun PRIVATE
-sEXIT_RUNTIME=0
-sINITIAL_MEMORY=134217728
-sMAXIMUM_MEMORY=2147483648
-sALLOW_MEMORY_GROWTH=1
-sSTACK_SIZE=5MB
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAP64,HEAPU64,HEAPF32,HEAPF64,safeSetTimeout,maybeExit,exitJS,abort,lengthBytesUTF8,UTF8ToString,stringToUTF8Array
-sEXPORTED_FUNCTIONS=_main,_GetDotNetRuntimeContractDescriptor
-sMODULARIZE=1
-sEXPORT_ES6=1
-sEXPORTED_RUNTIME_METHODS=ENV,${CMAKE_EMCC_EXPORTED_RUNTIME_METHODS}
-sEXPORTED_FUNCTIONS=_main,${CMAKE_EMCC_EXPORTED_FUNCTIONS}
-sEXPORT_NAME=createDotnetRuntime
-sENVIRONMENT=node,shell,web
-Wl,-error-limit=0)

Expand All @@ -96,7 +99,7 @@ else()
# If not running in the browser, add
# Node.js file system support.
target_link_options(corerun PRIVATE
-lnoderawfs.js
-sNODERAWFS=1
-lnodefs.js)
endif()
endif()
Expand Down
43 changes: 43 additions & 0 deletions src/coreclr/hosts/corerun/wasm/libCorerun.extpost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/* eslint-disable no-undef */
/* eslint-disable space-before-function-paren */
/* eslint-disable @typescript-eslint/no-unused-vars */
var fetch = fetch || undefined; var dotnetNativeModuleLoaded = false; var dotnetInternals = null;
export function selfRun() {
const Module = {};
const corePreRun = () => {
// copy all node/shell env variables to emscripten env
if (globalThis.process && globalThis.process.env) {
for (const [key, value] of Object.entries(process.env)) {
Module.ENV[key] = value;
}
}

Module.ENV["DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"] = "true";
};
Module.preRun = [corePreRun];

const runtimeApi = {
Module,
INTERNAL: {},
runtimeId: 0,
runtimeBuildInfo: {
productVersion: "corerun",
gitHash: "corerun",
buildConfiguration: "corerun",
wasmEnableThreads: false,
wasmEnableSIMD: true,
wasmEnableExceptionHandling: true,
},
};
dotnetInternals = [
runtimeApi,
[],
];

createDotnetRuntime(runtimeApi.Module);
}
selfRun();
20 changes: 0 additions & 20 deletions src/coreclr/hosts/corerun/wasm/libCorerun.pre.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/coreclr/runtime.proj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
<ProjectReference Condition="'$(HasCdacBuildTool)' == 'true'" Include="tools\cdac-build-tool\cdac-build-tool.csproj" ReferenceOutputAssembly="false" GlobalPropertiesToRemove="$(NativeBuildPartitionPropertiesToRemove)" />
</ItemGroup>

<Import Project="$(RepositoryEngineeringDir)native.props" />
<Import Project="$(RepositoryEngineeringDir)native.wasm.targets" />
<Import Project="$(RepositoryEngineeringDir)nativepgo.targets" />

<Target Name="BuildRuntime"
DependsOnTargets="GetPgoDataPackagePath"
DependsOnTargets="GetPgoDataPackagePath;GenerateEmccExports"
BeforeTargets="Build">
<ItemGroup>
<_CMakeArgs Include="$(CMakeArgs)" />
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/vm/wasm/callhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ namespace
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2), ARG_IND(3), ARG_IND(4), ARG_I32(5));
}

void CallFunc_I32_I32_IND_RetVoid (PCODE pcode, int8_t *pArgs, int8_t *pRet)
{
void (*fptr)(int32_t, int32_t, int32_t) = (void (*)(int32_t, int32_t, int32_t))pcode;
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_IND(2));
}

void CallFunc_I32_I32_IND_IND_I32_RetVoid (PCODE pcode, int8_t *pArgs, int8_t *pRet)
{
void (*fptr)(int32_t, int32_t, int32_t, int32_t, int32_t) = (void (*)(int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
Expand Down Expand Up @@ -709,6 +715,7 @@ const StringToWasmSigThunk g_wasmThunks[] = {
{ "viiinn", (void*)&CallFunc_I32_I32_I32_IND_IND_RetVoid },
{ "viiinni", (void*)&CallFunc_I32_I32_I32_IND_IND_I32_RetVoid },
{ "viinni", (void*)&CallFunc_I32_I32_IND_IND_I32_RetVoid },
{ "viin", (void*)&CallFunc_I32_I32_IND_RetVoid },
{ "viinnii", (void*)&CallFunc_I32_I32_IND_IND_I32_I32_RetVoid },
{ "vil", (void*)&CallFunc_I32_I64_RetVoid },
{ "vili", (void*)&CallFunc_I32_I64_I32_RetVoid },
Expand Down Expand Up @@ -752,7 +759,7 @@ static void Call_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJo
// Lazy lookup of MethodDesc for the function export scenario.
if (!MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid)
{
LookupMethodByName("System.Threading.ThreadPool, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, System.Private.CoreLib", "BackgroundJobHandler", &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid);
LookupMethodByName("System.Threading.ThreadPool, System.Private.CoreLib", "BackgroundJobHandler", &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid);
}
ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid, nullptr, 0, nullptr);
}
Expand All @@ -768,7 +775,7 @@ static void Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler
// Lazy lookup of MethodDesc for the function export scenario.
if (!MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid)
{
LookupMethodByName("System.Threading.TimerQueue, System.Private.CoreLib, Version=10.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, System.Private.CoreLib", "TimerHandler", &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid);
LookupMethodByName("System.Threading.TimerQueue, System.Private.CoreLib", "TimerHandler", &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid);
}
ExecuteInterpretedMethodFromUnmanaged(MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid, nullptr, 0, nullptr);
}
Expand Down
8 changes: 5 additions & 3 deletions src/native/corehost/browserhost/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,12 @@ target_link_options(browserhost PRIVATE
-sMODULARIZE=1
-sEXPORT_ES6=1
-sEXIT_RUNTIME=0
-sEXPORTED_RUNTIME_METHODS=BROWSER_HOST,cwrap,ccall,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAP64,HEAPU64,HEAPF32,HEAPF64,safeSetTimeout,maybeExit,exitJS,abort,lengthBytesUTF8,UTF8ToString,stringToUTF8Array
-sEXPORTED_FUNCTIONS=_posix_memalign,_malloc,_free,stackAlloc,stackRestore,stackSave,___cpp_exception,_GetDotNetRuntimeContractDescriptor,_BrowserHost_InitializeCoreCLR,_BrowserHost_ExecuteAssembly
-sEXPORTED_RUNTIME_METHODS=BROWSER_HOST,${CMAKE_EMCC_EXPORTED_RUNTIME_METHODS}
-sEXPORTED_FUNCTIONS=_BrowserHost_InitializeCoreCLR,_BrowserHost_ExecuteAssembly,${CMAKE_EMCC_EXPORTED_FUNCTIONS}
-sEXPORT_NAME=createDotnetRuntime
-lnodefs.js)
-sENVIRONMENT=web,webview,worker,node,shell
-lnodefs.js
-Wl,-error-limit=0)

target_link_libraries(browserhost PUBLIC
BrowserHost-Static
Expand Down
4 changes: 2 additions & 2 deletions src/native/corehost/browserhost/browserhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ static const void* pinvoke_override(const char* library_name, const char* entry_
{
return SystemResolveDllImport(entry_point_name);
}
if (strcmp(library_name, "libSystem.JavaScript") == 0)
if (strcmp(library_name, "libSystem.JavaScript.Native") == 0)
{
return SystemJSResolveDllImport(entry_point_name);
}
if (strcmp(library_name, "libSystem.Runtime.InteropServices.JavaScript") == 0)
if (strcmp(library_name, "libSystem.Runtime.InteropServices.JavaScript.Native") == 0)
{
return SystemJSInteropResolveDllImport(entry_point_name);
}
Expand Down
45 changes: 42 additions & 3 deletions src/native/corehost/browserhost/host/host.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import type { CharPtr, VoidPtr, VoidPtrPtr } from "./types";
import type { CharPtr, VfsAsset, VoidPtr, VoidPtrPtr } from "./types";
import { } from "./cross-linked"; // ensure ambient symbols are declared

const loadedAssemblies: Map<string, { ptr: number, length: number }> = new Map();

export function registerDllBytes(bytes: Uint8Array, asset: { name: string }) {
export function registerDllBytes(bytes: Uint8Array, asset: { name: string, virtualPath: string }) {
const sp = Module.stackSave();
try {
const sizeOfPtr = 4;
Expand All @@ -16,13 +16,52 @@ export function registerDllBytes(bytes: Uint8Array, asset: { name: string }) {
}

const ptr = Module.HEAPU32[ptrPtr as any >>> 2];
Module.HEAPU8.set(bytes, ptr);
Module.HEAPU8.set(bytes, ptr >>> 0);
loadedAssemblies.set(asset.name, { ptr, length: bytes.length });
loadedAssemblies.set(asset.virtualPath, { ptr, length: bytes.length });
} finally {
Module.stackRestore(sp);
}
}

export function installVfsFile(bytes: Uint8Array, asset: VfsAsset) {
const virtualName: string = typeof (asset.virtualPath) === "string"
? asset.virtualPath
: asset.name;
const lastSlash = virtualName.lastIndexOf("/");
let parentDirectory = (lastSlash > 0)
? virtualName.substring(0, lastSlash)
: null;
let fileName = (lastSlash > 0)
? virtualName.substring(lastSlash + 1)
: virtualName;
if (fileName.startsWith("/"))
fileName = fileName.substring(1);
if (parentDirectory) {
if (!parentDirectory.startsWith("/"))
parentDirectory = "/" + parentDirectory;

if (parentDirectory.startsWith("/managed")) {
throw new Error("Cannot create files under /managed virtual directory as it is reserved for NodeFS mounting");
}

dotnetLogger.debug(`Creating directory '${parentDirectory}'`);

Module.FS_createPath(
"/", parentDirectory, true, true // fixme: should canWrite be false?
);
} else {
parentDirectory = "/";
}

dotnetLogger.debug(`Creating file '${fileName}' in directory '${parentDirectory}'`);

Module.FS_createDataFile(
parentDirectory, fileName,
bytes, true /* canRead */, true /* canWrite */, true /* canOwn */
);
}

// bool BrowserHost_ExternalAssemblyProbe(const char* pathPtr, /*out*/ void **outDataStartPtr, /*out*/ int64_t* outSize);
export function BrowserHost_ExternalAssemblyProbe(pathPtr: CharPtr, outDataStartPtr: VoidPtrPtr, outSize: VoidPtr) {
const path = Module.UTF8ToString(pathPtr);
Expand Down
Loading
Loading