Skip to content

Commit 8698d3d

Browse files
pavelsavarailonatommymaraf
authored
[browser] load core assemblies first (#100141)
Co-authored-by: Ilona Tomkowicz <[email protected]> Co-authored-by: Marek Fišera <[email protected]>
1 parent 426edd0 commit 8698d3d

File tree

25 files changed

+363
-113
lines changed

25 files changed

+363
-113
lines changed

eng/testing/linker/trimmingTests.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
<Output TaskParameter="ExitCode" PropertyName="ExecutionExitCode" />
166166
</Exec>
167167

168-
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) return a non-success exit code." ContinueOnError="ErrorAndContinue" />
168+
<Error Condition="'$(ExecutionExitCode)' != '100'" Text="Error: [Failed Test]: %(TestConsoleApps.ProjectCompileItems). The Command %(TestConsoleApps.TestCommand) return a non-success exit code $(ExecutionExitCode)." ContinueOnError="ErrorAndContinue" />
169169
</Target>
170170

171171
<Target Name="Build" DependsOnTargets="ExecuteApplications" />

src/libraries/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.Shared.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
to be trimmed when Invariant=true, and allows for the Settings static cctor (on Unix) to be preserved when Invariant=false. -->
1212
<type fullname="System.Globalization.GlobalizationMode">
1313
<method signature="System.Boolean get_Invariant()" body="stub" value="true" feature="System.Globalization.Invariant" featurevalue="true" />
14+
<method signature="System.Boolean get_InvariantNoLoad()" body="stub" value="true" feature="System.Globalization.Invariant" featurevalue="true" />
1415
<method signature="System.Boolean get_PredefinedCulturesOnly()" body="stub" value="true" feature="System.Globalization.PredefinedCulturesOnly" featurevalue="true" />
1516
</type>
1617
<type fullname="System.Globalization.GlobalizationMode/Settings">

src/libraries/System.Private.CoreLib/src/System/Globalization/CultureData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ private static CultureData CreateCultureWithInvariantData()
628628
// all available calendar type(s). The first one is the default calendar
629629
invariant._waCalendars = new CalendarId[] { CalendarId.GREGORIAN };
630630

631-
if (!GlobalizationMode.Invariant)
631+
if (!GlobalizationMode.InvariantNoLoad)
632632
{
633633
// Store for specific data about each calendar
634634
invariant._calendars = new CalendarData[CalendarData.MAX_CALENDARS];
@@ -646,7 +646,7 @@ private static CultureData CreateCultureWithInvariantData()
646646
invariant._iDefaultMacCodePage = 10000; // default macintosh code page
647647
invariant._iDefaultEbcdicCodePage = 037; // default EBCDIC code page
648648

649-
if (GlobalizationMode.Invariant)
649+
if (GlobalizationMode.InvariantNoLoad)
650650
{
651651
invariant._sLocalizedCountry = invariant._sNativeCountry;
652652
}
@@ -2228,7 +2228,7 @@ private string[] GetNativeDigits()
22282228

22292229
internal void GetNFIValues(NumberFormatInfo nfi)
22302230
{
2231-
if (GlobalizationMode.Invariant || IsInvariantCulture)
2231+
if (GlobalizationMode.InvariantNoLoad || IsInvariantCulture)
22322232
{
22332233
nfi._positiveSign = _sPositiveSign!;
22342234
nfi._negativeSign = _sNegativeSign!;

src/libraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ private static partial class Settings
2525
// This allows for the whole Settings nested class to be trimmed when Invariant=true, and allows for the Settings
2626
// static cctor (on Unix) to be preserved when Invariant=false.
2727
internal static bool Invariant => Settings.Invariant;
28+
29+
// same as GlobalizationMode.Invariant but doesn't trigger ICU load in GlobalizationMode.Settings.cctor
30+
// during runtime startup on Browser platform
31+
internal static bool InvariantNoLoad
32+
{
33+
get
34+
{
35+
#if TARGET_BROWSER
36+
return AppContextConfigHelper.GetBooleanConfig("System.Globalization.Invariant", "DOTNET_SYSTEM_GLOBALIZATION_INVARIANT");
37+
#else
38+
return Settings.Invariant;
39+
#endif
40+
}
41+
}
42+
2843
#if TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS || TARGET_BROWSER
2944
internal static bool Hybrid => Settings.Hybrid;
3045
#endif

src/mono/browser/build/BrowserWasmApp.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@
156156
RuntimeAssetsLocation="$(WasmRuntimeAssetsLocation)"
157157
CacheBootResources="$(BlazorCacheBootResources)"
158158
RuntimeConfigJsonPath="$(_WasmRuntimeConfigFilePath)"
159+
IsAot="$(RunAOTCompilation)"
160+
IsMultiThreaded="$(WasmEnableThreads)"
159161
>
160162
<Output TaskParameter="FileWrites" ItemName="FileWrites" />
161163
</WasmAppBuilder>

src/mono/browser/runtime/assets.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8A
5252
if (fileName.startsWith("/"))
5353
fileName = fileName.substring(1);
5454
if (parentDirectory) {
55+
if (!parentDirectory.startsWith("/"))
56+
parentDirectory = "/" + parentDirectory;
57+
5558
mono_log_debug(`Creating directory '${parentDirectory}'`);
5659

5760
Module.FS_createPath(
@@ -85,8 +88,7 @@ export function instantiate_asset (asset: AssetEntry, url: string, bytes: Uint8A
8588
} else if (asset.behavior === "pdb") {
8689
cwraps.mono_wasm_add_assembly(virtualName, offset!, bytes.length);
8790
} else if (asset.behavior === "icu") {
88-
if (!mono_wasm_load_icu_data(offset!))
89-
Module.err(`Error loading ICU asset ${asset.name}`);
91+
mono_wasm_load_icu_data(offset!);
9092
} else if (asset.behavior === "resource") {
9193
cwraps.mono_wasm_add_satellite_assembly(virtualName, asset.culture || "", offset!, bytes.length);
9294
}

src/mono/browser/runtime/dotnet.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,10 @@ type ResourceExtensions = {
243243
};
244244
interface ResourceGroups {
245245
hash?: string;
246+
coreAssembly?: ResourceList;
246247
assembly?: ResourceList;
247248
lazyAssembly?: ResourceList;
249+
corePdb?: ResourceList;
248250
pdb?: ResourceList;
249251
jsModuleWorker?: ResourceList;
250252
jsModuleNative: ResourceList;
@@ -258,6 +260,9 @@ interface ResourceGroups {
258260
modulesAfterConfigLoaded?: ResourceList;
259261
modulesAfterRuntimeReady?: ResourceList;
260262
extensions?: ResourceExtensions;
263+
coreVfs?: {
264+
[virtualPath: string]: ResourceList;
265+
};
261266
vfs?: {
262267
[virtualPath: string]: ResourceList;
263268
};

src/mono/browser/runtime/globals.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,16 @@ export function setRuntimeGlobals (globalObjects: GlobalObjects) {
5757

5858
const rh: Partial<RuntimeHelpers> = {
5959
gitHash,
60+
coreAssetsInMemory: createPromiseController<void>(),
6061
allAssetsInMemory: createPromiseController<void>(),
6162
dotnetReady: createPromiseController<any>(),
6263
afterInstantiateWasm: createPromiseController<void>(),
6364
beforePreInit: createPromiseController<void>(),
6465
afterPreInit: createPromiseController<void>(),
6566
afterPreRun: createPromiseController<void>(),
6667
beforeOnRuntimeInitialized: createPromiseController<void>(),
67-
afterMonoStarted: createPromiseController<GCHandle | undefined>(),
68+
afterMonoStarted: createPromiseController<void>(),
69+
afterDeputyReady: createPromiseController<GCHandle | undefined>(),
6870
afterIOStarted: createPromiseController<void>(),
6971
afterOnRuntimeInitialized: createPromiseController<void>(),
7072
afterPostRun: createPromiseController<void>(),

src/mono/browser/runtime/icu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import cwraps from "./cwraps";
55
import { VoidPtr } from "./types/emscripten";
66

7-
// @offset must be the address of an ICU data archive in the native heap.
8-
// returns true on success.
9-
export function mono_wasm_load_icu_data (offset: VoidPtr): boolean {
10-
return (cwraps.mono_wasm_load_icu_data(offset)) === 1;
7+
export function mono_wasm_load_icu_data (offset: VoidPtr) {
8+
if (!cwraps.mono_wasm_load_icu_data(offset)) {
9+
throw new Error("Failed to load ICU data");
10+
}
1111
}

0 commit comments

Comments
 (0)