Skip to content

Commit 30af6da

Browse files
committed
wip
1 parent 69d8087 commit 30af6da

40 files changed

+372
-124
lines changed

eng/native.props

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

eng/native.wasm.targets

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<Project>
2+
<ItemGroup>
3+
<PackageReference Condition="'$(TargetsWasm)' == 'true'" Include="Microsoft.NETCore.Runtime.ICU.Transport" PrivateAssets="all" Version="$(MicrosoftNETCoreRuntimeICUTransportVersion)" GeneratePathProperty="true" />
4+
<PackageReference Condition="'$(TargetsWasm)' == 'true'" Include="System.Runtime.TimeZoneData" PrivateAssets="all" Version="$(SystemRuntimeTimeZoneDataVersion)" GeneratePathProperty="true" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<_RuntimeVariant />
9+
<_RuntimeVariant Condition="'$(WasmEnableThreads)' == 'true'">-threads</_RuntimeVariant>
10+
11+
<_IcuDir Condition="'$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)' != '' and '$(TargetsWasm)' == 'true'">$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/$(TargetOS)-$(TargetArchitecture)$(_RuntimeVariant)/native</_IcuDir>
12+
<_TzdDir Condition="'$(PkgSystem_Runtime_TimeZoneData)' != '' and '$(TargetsWasm)' == 'true'">$([MSBuild]::NormalizePath('$(PkgSystem_Runtime_TimeZoneData)', 'contentFiles', 'any', 'any', 'data'))</_TzdDir>
13+
</PropertyGroup>
14+
15+
<ItemGroup>
16+
<NativeCMakeArg Condition="'$(_IcuDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_ICU_DIR=$(_IcuDir)&quot;" />
17+
<NativeCMakeArg Condition="'$(_TzdDir)' != ''" Include="-cmakeargs &quot;-DCMAKE_TZD_DIR=$(_TzdDir)&quot;" />
18+
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'Mono'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_MONO=1&quot;" />
19+
<NativeCMakeArg Condition="'$(RuntimeFlavor)' == 'CoreCLR'" Include="-cmakeargs &quot;-DCLR_CMAKE_RUNTIME_CORECLR=1&quot;" />
20+
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_PRODUCT_VERSION=$(ProductVersion)&quot;" />
21+
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_CONTINUOUS_INTEGRATION_BUILD=$(ContinuousIntegrationBuild)&quot;" />
22+
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_NET_CORE_APP_CURRENT_VERSION=$(NetCoreAppCurrentVersion)&quot;" />
23+
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_BUILD_LIBRARIES_CONFIGURATION=$(LibrariesConfiguration)&quot;" />
24+
<NativeCMakeArg Include="-cmakeargs &quot;-DCMAKE_BUILD_RUNTIME_CONFIGURATION=$(RuntimeConfiguration)&quot;" />
25+
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true' and '$(RuntimeFlavor)' == 'CoreCLR'" Include="-cmakeargs &quot;-DBUILD_LIBS_NATIVE_BROWSER=1&quot;" />
26+
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true'" Include="-cmakeargs &quot;-DBUILD_LIBS_NATIVE_BROWSER=1&quot;" />
27+
</ItemGroup>
28+
29+
<Target Name="GenerateEmccExports" Condition="'$(TargetsBrowser)' == 'true'">
30+
<ItemGroup>
31+
<EmccExportedRuntimeMethod Include="FS" />
32+
<EmccExportedRuntimeMethod Include="out" />
33+
<EmccExportedRuntimeMethod Include="err" />
34+
<EmccExportedRuntimeMethod Include="ccall" />
35+
<EmccExportedRuntimeMethod Include="cwrap" />
36+
<EmccExportedRuntimeMethod Include="setValue" />
37+
<EmccExportedRuntimeMethod Include="getValue" />
38+
<EmccExportedRuntimeMethod Include="UTF8ToString" />
39+
<EmccExportedRuntimeMethod Include="UTF8ArrayToString" />
40+
<EmccExportedRuntimeMethod Include="lengthBytesUTF8" />
41+
<EmccExportedRuntimeMethod Include="stringToUTF8Array" />
42+
<EmccExportedRuntimeMethod Include="FS_createPath" />
43+
<EmccExportedRuntimeMethod Include="FS_createDataFile" />
44+
<EmccExportedRuntimeMethod Include="removeRunDependency" />
45+
<EmccExportedRuntimeMethod Include="addRunDependency" />
46+
<EmccExportedRuntimeMethod Include="addFunction" />
47+
<EmccExportedRuntimeMethod Include="safeSetTimeout" />
48+
<EmccExportedRuntimeMethod Include="runtimeKeepalivePush" />
49+
<EmccExportedRuntimeMethod Include="runtimeKeepalivePop" />
50+
<EmccExportedRuntimeMethod Include="maybeExit" />
51+
<EmccExportedRuntimeMethod Include="abort" />
52+
53+
<EmccExportedFunction Include="_free" />
54+
<EmccExportedFunction Include="_htons" />
55+
<EmccExportedFunction Include="_malloc" />
56+
<EmccExportedFunction Include="_sbrk" />
57+
<EmccExportedFunction Include="_memalign" />
58+
<EmccExportedFunction Include="_posix_memalign" />
59+
<EmccExportedFunction Include="_memset" />
60+
<EmccExportedFunction Include="_ntohs" />
61+
<EmccExportedFunction Include="stackAlloc" />
62+
<EmccExportedFunction Include="stackRestore" />
63+
<EmccExportedFunction Include="stackSave" />
64+
<!-- TODO-WASM hide -->
65+
<EmccExportedFunction Include="_GetDotNetRuntimeContractDescriptor" />
66+
</ItemGroup>
67+
<PropertyGroup>
68+
<_EmccExportedRuntimeMethods>@(EmccExportedRuntimeMethod -> '%(Identity)',',')</_EmccExportedRuntimeMethods>
69+
<_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',')</_EmccExportedFunctions>
70+
</PropertyGroup>
71+
72+
<ItemGroup>
73+
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true'" Include="-cmakeargs &quot;-DCMAKE_EMCC_EXPORTED_RUNTIME_METHODS=$(_EmccExportedRuntimeMethods)&quot;" />
74+
<NativeCMakeArg Condition="'$(TargetsBrowser)' == 'true'" Include="-cmakeargs &quot;-DCMAKE_EMCC_EXPORTED_FUNCTIONS=$(_EmccExportedFunctions)&quot;" />
75+
</ItemGroup>
76+
77+
</Target>
78+
79+
</Project>

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,23 @@ else()
6262
"${STATIC_LIB_DESTINATION}/libSystem.Native.Browser.js")
6363
set(JS_SYSTEM_BROWSER_UTILS
6464
"${STATIC_LIB_DESTINATION}/libSystem.Browser.Utils.js")
65-
set(JS_CORE_RUN_PRE
66-
"${CMAKE_CURRENT_SOURCE_DIR}/wasm/libCorerun.pre.js")
65+
set(JS_CORE_RUN
66+
"${CMAKE_CURRENT_SOURCE_DIR}/wasm/libCorerun.extpost.js")
6767
set_target_properties(corerun PROPERTIES
68-
LINK_DEPENDS "${JS_CORE_RUN_PRE};${JS_SYSTEM_NATIVE_BROWSER};${JS_SYSTEM_BROWSER_UTILS};"
69-
LINK_FLAGS "--pre-js ${JS_CORE_RUN_PRE} --js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS}"
68+
LINK_DEPENDS "${JS_CORE_RUN};${JS_SYSTEM_NATIVE_BROWSER};${JS_SYSTEM_BROWSER_UTILS};"
69+
LINK_FLAGS "--js-library ${JS_SYSTEM_NATIVE_BROWSER} --js-library ${JS_SYSTEM_BROWSER_UTILS} --extern-post-js ${JS_CORE_RUN}"
7070
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
7171
target_link_options(corerun PRIVATE
7272
-sEXIT_RUNTIME=0
7373
-sINITIAL_MEMORY=134217728
7474
-sMAXIMUM_MEMORY=2147483648
7575
-sALLOW_MEMORY_GROWTH=1
7676
-sSTACK_SIZE=5MB
77-
-sWASM_BIGINT=1
78-
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAP64,HEAPU64,HEAPF32,HEAPF64,safeSetTimeout,maybeExit,exitJS,abort,lengthBytesUTF8,UTF8ToString,stringToUTF8Array
79-
-sEXPORTED_FUNCTIONS=_main,_GetDotNetRuntimeContractDescriptor
77+
-sMODULARIZE=1
78+
-sEXPORT_ES6=1
79+
-sEXPORTED_RUNTIME_METHODS=${CMAKE_EMCC_EXPORTED_RUNTIME_METHODS}
80+
-sEXPORTED_FUNCTIONS=_main,${CMAKE_EMCC_EXPORTED_FUNCTIONS}
81+
-sEXPORT_NAME=createDotnetRuntime
8082
-sENVIRONMENT=node,shell,web
8183
-Wl,-error-limit=0)
8284

@@ -86,6 +88,7 @@ else()
8688
set(WASM_PRELOAD_DIR "${CMAKE_INSTALL_PREFIX}/IL")
8789
if (EXISTS "${WASM_PRELOAD_DIR}")
8890
target_link_options(corerun PRIVATE
91+
-sWASM_BIGINT=1
8992
--preload-file ${WASM_PRELOAD_DIR}@/)
9093
endif()
9194
else()
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//
2+
// Licensed to the .NET Foundation under one or more agreements.
3+
// The .NET Foundation licenses this file to you under the MIT license.
4+
5+
/* eslint-disable no-undef */
6+
/* eslint-disable space-before-function-paren */
7+
/* eslint-disable @typescript-eslint/no-unused-vars */
8+
var fetch = fetch || undefined; var dotnetNativeModuleLoaded = false; var dotnetInternals = null;
9+
export function selfRun() {
10+
const corePreRun = () => {
11+
// copy all node/shell env variables to emscripten env
12+
if (globalThis.process && globalThis.process.env) {
13+
for (const [key, value] of Object.entries(process.env)) {
14+
Module.ENV[key] = value;
15+
}
16+
}
17+
18+
Module.ENV["DOTNET_SYSTEM_GLOBALIZATION_INVARIANT"] = "true";
19+
};
20+
const Module = {
21+
preRun: [corePreRun]
22+
};
23+
const runtimeApi = {
24+
Module: Module,
25+
INTERNAL: {},
26+
runtimeId: 0,
27+
runtimeBuildInfo: {
28+
productVersion: "corerun",
29+
gitHash: "corerun",
30+
buildConfiguration: "corerun",
31+
wasmEnableThreads: false,
32+
wasmEnableSIMD: true,
33+
wasmEnableExceptionHandling: true,
34+
},
35+
};
36+
dotnetInternals = [
37+
runtimeApi,
38+
[],
39+
];
40+
41+
createDotnetRuntime(runtimeApi.Module);
42+
}
43+
selfRun();

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

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

src/coreclr/runtime.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<ProjectReference Condition="'$(HasCdacBuildTool)' == 'true'" Include="tools\cdac-build-tool\cdac-build-tool.csproj" ReferenceOutputAssembly="false" GlobalPropertiesToRemove="$(NativeBuildPartitionPropertiesToRemove)" />
1212
</ItemGroup>
1313

14-
<Import Project="$(RepositoryEngineeringDir)native.props" />
14+
<Import Project="$(RepositoryEngineeringDir)native.wasm.targets" />
1515
<Import Project="$(RepositoryEngineeringDir)nativepgo.targets" />
1616

1717
<Target Name="BuildRuntime"
18-
DependsOnTargets="GetPgoDataPackagePath"
18+
DependsOnTargets="GetPgoDataPackagePath;GenerateEmccExports"
1919
BeforeTargets="Build">
2020
<ItemGroup>
2121
<_CMakeArgs Include="$(CMakeArgs)" />

src/coreclr/vm/wasm/callhelpers.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,12 @@ namespace
484484
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_I32(2), ARG_IND(3), ARG_IND(4), ARG_I32(5));
485485
}
486486

487+
void CallFunc_I32_I32_IND_RetVoid (PCODE pcode, int8_t *pArgs, int8_t *pRet)
488+
{
489+
void (*fptr)(int32_t, int32_t, int32_t) = (void (*)(int32_t, int32_t, int32_t))pcode;
490+
(*fptr)(ARG_I32(0), ARG_I32(1), ARG_IND(2));
491+
}
492+
487493
void CallFunc_I32_I32_IND_IND_I32_RetVoid (PCODE pcode, int8_t *pArgs, int8_t *pRet)
488494
{
489495
void (*fptr)(int32_t, int32_t, int32_t, int32_t, int32_t) = (void (*)(int32_t, int32_t, int32_t, int32_t, int32_t))pcode;
@@ -708,7 +714,8 @@ const StringToWasmSigThunk g_wasmThunks[] = {
708714
{ "viiili", (void*)&CallFunc_I32_I32_I32_I64_I32_RetVoid },
709715
{ "viiinn", (void*)&CallFunc_I32_I32_I32_IND_IND_RetVoid },
710716
{ "viiinni", (void*)&CallFunc_I32_I32_I32_IND_IND_I32_RetVoid },
711-
{ "viinni", (void*)&CallFunc_I32_I32_IND_IND_I32_RetVoid },
717+
{ "viinni", (void*)&CallFunc_I32_I32_IND_IND_I32_RetVoid },
718+
{ "viin", (void*)&CallFunc_I32_I32_IND_RetVoid },
712719
{ "viinnii", (void*)&CallFunc_I32_I32_IND_IND_I32_I32_RetVoid },
713720
{ "vil", (void*)&CallFunc_I32_I64_RetVoid },
714721
{ "vili", (void*)&CallFunc_I32_I64_I32_RetVoid },

src/coreclr/vm/wasm/helpers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,10 @@ namespace
618618
if (!GetSignatureKey(sig, keyBuffer, keyBufferLen))
619619
return NULL;
620620

621+
void* thunk = LookupThunk(keyBuffer);
622+
if (thunk == NULL)
623+
printf("WASM Calli missing for Key: %s\n", keyBuffer);
624+
621625
return LookupThunk(keyBuffer);
622626
}
623627
}

src/libraries/pretest.proj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
<ProjectReference Include="$(CommonTestPath)AppleTestRunner\AppleTestRunner.csproj" Condition="'$(TargetOS)' == 'maccatalyst' or '$(TargetOS)' == 'ios' or '$(TargetOS)' == 'iossimulator' or '$(TargetOS)' == 'tvos' or '$(TargetOS)' == 'tvossimulator'"/>
2121
<ProjectReference Include="$(CommonTestPath)AndroidTestRunner\AndroidTestRunner.csproj" Condition="'$(TargetOS)' == 'android'" />
22-
<ProjectReference Include="$(CommonTestPath)WasmTestRunner\WasmTestRunner.csproj" Condition="('$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi') and '$(RuntimeFlavor)' == 'Mono'" />
23-
<ProjectReference Include="$(MonoProjectRoot)wasm\symbolicator\WasmSymbolicator.csproj" Condition="'$(TargetOS)' == 'browser' and '$(RuntimeFlavor)' == 'Mono'" />
22+
<ProjectReference Include="$(CommonTestPath)WasmTestRunner\WasmTestRunner.csproj" Condition="('$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi')" />
23+
<ProjectReference Include="$(MonoProjectRoot)wasm\symbolicator\WasmSymbolicator.csproj" Condition="'$(TargetOS)' == 'browser'" />
2424

2525
<!-- needed to test workloads for wasm -->
2626
<ProjectReference Include="$(InstallerProjectRoot)pkg\sfx\Microsoft.NETCore.App\Microsoft.NETCore.App.Runtime.Mono.sfxproj"

src/mono/browser/test-main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Run runtime tests under a JS shell or a browser
66
//
77
import { dotnet, exit } from './_framework/dotnet.js';
8+
import { config } from './_framework/dotnet.boot.js';
89

910

1011
/*****************************************************************************
@@ -253,6 +254,7 @@ globalThis.App = App; // Necessary as tests use it
253254

254255
function configureRuntime(dotnet, runArgs) {
255256
dotnet
257+
.withConfig(config)
256258
.withVirtualWorkingDirectory(runArgs.workingDirectory)
257259
.withEnvironmentVariables(runArgs.environmentVariables)
258260
.withDiagnosticTracing(runArgs.diagnosticTracing)

0 commit comments

Comments
 (0)