Skip to content

Commit b00221a

Browse files
committed
wip
1 parent b2db399 commit b00221a

File tree

66 files changed

+3166
-250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3166
-250
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>

eng/testing/tests.browser.targets

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<EMSDK_PATH Condition="'$(EMSDK_PATH)' == '' and '$(ContinuousIntegrationBuild)' == 'true' and '$(MonoProjectRoot)' != ''">$([MSBuild]::NormalizeDirectory($(BrowserProjectRoot), 'emsdk'))</EMSDK_PATH>
1313

1414
<WasmEmitSymbolMap Condition="'$(WasmEmitSymbolMap)' == ''">true</WasmEmitSymbolMap>
15+
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization>
1516

1617
<_WasmMainJSFileName Condition="'$(WasmMainJSPath)' != ''">$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
1718
<_WasmStrictVersionMatch Condition="'$(ContinuousIntegrationBuild)' == 'true'">true</_WasmStrictVersionMatch>
@@ -34,6 +35,9 @@
3435
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">false</UseSystemResourceKeys>
3536
<EventSourceSupport Condition="'$(EventSourceSupport)' == ''">true</EventSourceSupport>
3637
<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">true</NullabilityInfoContextSupport>
38+
39+
<!-- TODO-WASM https://github.com/dotnet/runtime/issues/120248 -->
40+
<WasmEnableWebcil Condition="'$(RuntimeFlavor)' == 'CoreCLR'">false</WasmEnableWebcil>
3741
</PropertyGroup>
3842

3943
<!-- We expect WASM users to indicate they would like to have bigger download size by adding WasmIncludeFullIcuData, -->

eng/testing/workloads-browser.targets

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<Target Name="_GetWorkloadsToInstall" DependsOnTargets="_SetPackageVersionForWorkloadsTesting" Returns="@(WorkloadIdForTesting);@(WorkloadCombinationsToInstall)">
1010
<Error Condition="'$(RIDForWorkload)' == ''" Text="$(RIDForWorkload) is unset" />
11-
<ItemGroup>
11+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
1212
<WorkloadIdForTesting Include="wasm-tools;wasm-experimental"
1313
ManifestName="Microsoft.NET.Workload.Mono.ToolChain.Current"
1414
Variant="latest"
@@ -67,11 +67,15 @@
6767
</_DefaultRuntimePackNuGetPath>
6868
</PropertyGroup>
6969

70-
<ItemGroup>
70+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'Mono'">
7171
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
7272
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.Mono.*.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
7373
<_RuntimePackNugetAvailable Remove="@(_RuntimePackNugetAvailable)" Condition="$([System.String]::new('%(_RuntimePackNugetAvailable.FileName)').EndsWith('.symbols'))" />
7474
</ItemGroup>
75+
<ItemGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR'">
76+
<_RuntimePackNugetAvailable Include="$(LibrariesShippingPackagesDir)Microsoft.NETCore.App.Runtime.$(RIDForWorkload).*$(PackageVersionForWorkloadManifests).nupkg" />
77+
<_RuntimePackNugetAvailable Remove="@(_RuntimePackNugetAvailable)" Condition="$([System.String]::new('%(_RuntimePackNugetAvailable.FileName)').EndsWith('.symbols'))" />
78+
</ItemGroup>
7579

7680
<Error Condition="@(_RuntimePackNugetAvailable -> Count()) != 2 and @(_RuntimePackNugetAvailable -> Count()) != 1"
7781
Text="Expected to find either one or two in $(LibrariesShippingPackagesDir): @(_RuntimePackNugetAvailable->'%(FileName)%(Extension)')" />
@@ -87,7 +91,7 @@
8791
</ItemGroup>
8892

8993
<Message
90-
Condition="@(_RuntimePackNugetAvailable -> Count()) == 1"
94+
Condition="'$(RuntimeFlavor)' == 'Mono' and @(_RuntimePackNugetAvailable -> Count()) == 1"
9195
Importance="High"
9296
Text="
9397
********************

src/coreclr/hosts/corerun/CMakeLists.txt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,24 @@ 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-
-sEXPORTED_RUNTIME_METHODS=cwrap,ccall,HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAP64,HEAPU64,HEAPF32,HEAPF64,safeSetTimeout,maybeExit,exitJS,abort,lengthBytesUTF8,UTF8ToString,stringToUTF8Array
78-
-sEXPORTED_FUNCTIONS=_main,_GetDotNetRuntimeContractDescriptor
79-
-sENVIRONMENT=node,shell,web
77+
-sMODULARIZE=1
78+
-sEXPORT_ES6=1
79+
-sEXPORTED_RUNTIME_METHODS=ENV,${CMAKE_EMCC_EXPORTED_RUNTIME_METHODS}
80+
-sEXPORTED_FUNCTIONS=_main,${CMAKE_EMCC_EXPORTED_FUNCTIONS}
81+
-sEXPORT_NAME=createDotnetRuntime
82+
-sENVIRONMENT=node,web
8083
-Wl,-error-limit=0)
8184

8285
if (CORERUN_IN_BROWSER)
@@ -96,7 +99,7 @@ else()
9699
# If not running in the browser, add
97100
# Node.js file system support.
98101
target_link_options(corerun PRIVATE
99-
-lnoderawfs.js
102+
-sNODERAWFS=1
100103
-lnodefs.js)
101104
endif()
102105
endif()
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

0 commit comments

Comments
 (0)