Skip to content

Commit ac0e359

Browse files
committed
rebase
1 parent dd75c45 commit ac0e359

File tree

22 files changed

+286
-89
lines changed

22 files changed

+286
-89
lines changed

eng/testing/scenarios/BuildWasmAppsJobsList.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,5 @@ Wasm.Build.Tests.WorkloadTests
4747
Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests
4848
Wasm.Build.Tests.DebugLevelTests
4949
Wasm.Build.Tests.PreloadingTests
50+
Wasm.Build.Tests.EnvVariablesTests
51+
Wasm.Build.Tests.HttpTests

src/mono/browser/browser.proj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
"PropertiesThatTriggerRelinking": [
336336
{ "identity": "InvariantTimezone", "defaultValueInRuntimePack": "$(InvariantTimezone)" },
337337
{ "identity": "InvariantGlobalization", "defaultValueInRuntimePack": "$(InvariantGlobalization)" },
338-
{ "identity": "WasmEnableStreamingResponse", "defaultValueInRuntimePack": "$(WasmEnableStreamingResponse)" },
339338
{ "identity": "WasmNativeStrip", "defaultValueInRuntimePack": "$(WasmNativeStrip)" },
340339
{ "identity": "WasmSingleFileBundle", "defaultValueInRuntimePack": "$(WasmSingleFileBundle)" },
341340
{ "identity": "WasmEnableSIMD", "defaultValueInRuntimePack": "$(WasmEnableSIMD)" },

src/mono/browser/build/BrowserWasmApp.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
WasmIcuDataFileName="$(WasmIcuDataFileName)"
182182
RuntimeAssetsLocation="$(WasmRuntimeAssetsLocation)"
183183
CacheBootResources="$(BlazorCacheBootResources)"
184-
RuntimeConfigJsonPath="$(_WasmRuntimeConfigFilePath)"
184+
RuntimeConfigJsonPath="$(ProjectRuntimeConfigFilePath)"
185185
IsAot="$(RunAOTCompilation)"
186186
IsMultiThreaded="$(WasmEnableThreads)"
187187
>

src/mono/browser/build/WasmApp.InTree.targets

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<!-- This depends on the root Directory.Build.targets imported this file -->
33
<UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" TaskFactory="TaskHostFactory" />
44
<UsingTask TaskName="ILStrip" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" TaskFactory="TaskHostFactory" />
5-
<UsingTask TaskName="RuntimeConfigParserTask" AssemblyFile="$(MonoTargetsTasksAssemblyPath)" TaskFactory="TaskHostFactory" />
65

76
<!-- TODO: this breaks runtime tests on Helix due to the file not being there for some reason. Once this is fixed we can remove the UpdateRuntimePack target here -->
87
<Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" Condition="'$(TargetingpacksTargetsImported)' != 'true' and '$(ImportTargetingPacksTargetsInWasmAppTargets)' == 'true'"/>

src/mono/browser/runtime/cwraps.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const fn_signatures: SigLine[] = [
4646
[true, "mono_wasm_load_icu_data", "number", ["number"]],
4747
[false, "mono_wasm_add_assembly", "number", ["string", "number", "number"]],
4848
[true, "mono_wasm_add_satellite_assembly", "void", ["string", "string", "number", "number"]],
49-
[false, "mono_wasm_load_runtime", null, ["number"]],
49+
[false, "mono_wasm_load_runtime", null, ["number", "number", "number", "number"]],
5050
[true, "mono_wasm_change_debugger_log_level", "void", ["number"]],
5151

5252
[true, "mono_wasm_assembly_load", "number", ["string"]],
@@ -173,7 +173,7 @@ export interface t_Cwraps {
173173
mono_wasm_load_icu_data(offset: VoidPtr): number;
174174
mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number;
175175
mono_wasm_add_satellite_assembly(name: string, culture: string, data: VoidPtr, size: number): void;
176-
mono_wasm_load_runtime(debugLevel: number): void;
176+
mono_wasm_load_runtime(debugLevel: number, propertyCount:number, propertyKeys:CharPtrPtr, propertyValues:CharPtrPtr): void;
177177
mono_wasm_change_debugger_log_level(value: number): void;
178178

179179
mono_wasm_assembly_load(name: string): MonoAssembly;

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ type MonoConfig = {
192192
environmentVariables?: {
193193
[i: string]: string;
194194
};
195+
/**
196+
* Subset of runtimeconfig.json
197+
*/
198+
runtimeConfig?: {
199+
runtimeOptions?: {
200+
configProperties?: {
201+
[i: string]: string | number | boolean;
202+
};
203+
};
204+
};
195205
/**
196206
* initial number of workers to add to the emscripten pthread pool
197207
*/

src/mono/browser/runtime/driver.c

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ int mono_regression_test_step (int verbose_level, char *image, char *method_name
6363

6464
static MonoDomain *root_domain;
6565

66-
#define RUNTIMECONFIG_BIN_FILE "runtimeconfig.bin"
67-
6866
extern void mono_wasm_trace_logger (const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data);
6967

7068
static void
@@ -184,7 +182,7 @@ cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
184182
static int runtime_initialized = 0;
185183

186184
EMSCRIPTEN_KEEPALIVE void
187-
mono_wasm_load_runtime (int debug_level)
185+
mono_wasm_load_runtime (int debug_level, int propertyCount, const char **propertyKeys, const char **propertyValues)
188186
{
189187
runtime_initialized = 1;
190188
const char *interp_opts = "";
@@ -193,34 +191,7 @@ mono_wasm_load_runtime (int debug_level)
193191
mono_wasm_link_icu_shim ();
194192
#endif
195193

196-
// When the list of app context properties changes, please update RuntimeConfigReservedProperties for
197-
// target _WasmGenerateRuntimeConfig in BrowserWasmApp.targets file
198-
const char *appctx_keys[2];
199-
appctx_keys [0] = "APP_CONTEXT_BASE_DIRECTORY";
200-
appctx_keys [1] = "RUNTIME_IDENTIFIER";
201-
202-
const char *appctx_values[2];
203-
appctx_values [0] = "/";
204-
appctx_values [1] = "browser-wasm";
205-
206-
char *file_name = RUNTIMECONFIG_BIN_FILE;
207-
int str_len = strlen (file_name) + 1; // +1 is for the "/"
208-
char *file_path = (char *)malloc (sizeof (char) * (str_len +1)); // +1 is for the terminating null character
209-
int num_char = snprintf (file_path, (str_len + 1), "/%s", file_name);
210-
struct stat buffer;
211-
212-
assert (num_char > 0 && num_char == str_len);
213-
214-
if (stat (file_path, &buffer) == 0) {
215-
MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments));
216-
arg->kind = 0;
217-
arg->runtimeconfig.name.path = file_path;
218-
monovm_runtimeconfig_initialize (arg, cleanup_runtime_config, file_path);
219-
} else {
220-
free (file_path);
221-
}
222-
223-
monovm_initialize (2, appctx_keys, appctx_values);
194+
monovm_initialize (propertyCount, propertyKeys, propertyValues);
224195

225196
#ifndef INVARIANT_TIMEZONE
226197
char* invariant_timezone = monoeg_g_getenv ("DOTNET_SYSTEM_TIMEZONE_INVARIANT");
@@ -237,7 +208,17 @@ int initialize_runtime()
237208
{
238209
if (runtime_initialized == 1)
239210
return 0;
240-
mono_wasm_load_runtime (0);
211+
212+
const char *appctx_keys[2];
213+
appctx_keys [0] = "APP_CONTEXT_BASE_DIRECTORY";
214+
appctx_keys [1] = "RUNTIME_IDENTIFIER";
215+
216+
const char *appctx_values[2];
217+
appctx_values [0] = "/";
218+
appctx_values [1] = "browser-wasm";
219+
220+
// this does not support loading runtimeConfig.json part of boot.config.json
221+
mono_wasm_load_runtime (0, 2, appctx_keys, appctx_values);
241222

242223
return 0;
243224
}

src/mono/browser/runtime/startup.ts

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import { mono_wasm_init_aot_profiler, mono_wasm_init_devtools_profiler, mono_was
1313
import { initialize_marshalers_to_cs } from "./marshal-to-cs";
1414
import { initialize_marshalers_to_js } from "./marshal-to-js";
1515
import { init_polyfills_async } from "./polyfills";
16-
import { strings_init, utf8ToString } from "./strings";
16+
import { strings_init, stringToUTF8Ptr, utf8ToString } from "./strings";
1717
import { init_managed_exports } from "./managed-exports";
1818
import { cwraps_internal } from "./exports-internal";
19-
import { CharPtr, EmscriptenModule, InstantiateWasmCallBack, InstantiateWasmSuccessCallback } from "./types/emscripten";
19+
import { CharPtr, CharPtrPtr, EmscriptenModule, InstantiateWasmCallBack, InstantiateWasmSuccessCallback, VoidPtr } from "./types/emscripten";
2020
import { wait_for_all_assets } from "./assets";
2121
import { replace_linker_placeholders } from "./exports-binding";
2222
import { endMeasure, MeasuredBlock, startMeasure } from "./profiler";
@@ -28,7 +28,7 @@ import { populateEmscriptenPool, mono_wasm_init_threads } from "./pthreads";
2828
import { currentWorkerThreadEvents, dotnetPthreadCreated, initWorkerThreadEvents, monoThreadInfo } from "./pthreads";
2929
import { mono_wasm_pthread_ptr, update_thread_info } from "./pthreads";
3030
import { jiterpreter_allocate_tables } from "./jiterpreter-support";
31-
import { localHeapViewU8, malloc } from "./memory";
31+
import { localHeapViewU8, malloc, setU32 } from "./memory";
3232
import { assertNoProxies } from "./gc-handles";
3333
import { runtimeList } from "./exports";
3434
import { nativeAbort, nativeExit } from "./run";
@@ -617,7 +617,41 @@ export function mono_wasm_load_runtime (): void {
617617
if (!loaderHelpers.isDebuggingSupported() || !runtimeHelpers.config.resources!.pdb) {
618618
debugLevel = 0;
619619
}
620-
cwraps.mono_wasm_load_runtime(debugLevel);
620+
621+
const runtimeConfigProperties = new Map<string, string>();
622+
if (runtimeHelpers.config.runtimeConfig?.runtimeOptions?.configProperties) {
623+
for (const [key, value] of Object.entries(runtimeHelpers.config.runtimeConfig?.runtimeOptions?.configProperties)) {
624+
runtimeConfigProperties.set(key, "" + value);
625+
}
626+
}
627+
runtimeConfigProperties.set("APP_CONTEXT_BASE_DIRECTORY", "/");
628+
runtimeConfigProperties.set("RUNTIME_IDENTIFIER", "browser-wasm");
629+
const propertyCount = runtimeConfigProperties.size;
630+
631+
const buffers:VoidPtr[] = [];
632+
const appctx_keys = malloc(4 * runtimeConfigProperties.size) as any as CharPtrPtr;
633+
const appctx_values = malloc(4 * runtimeConfigProperties.size) as any as CharPtrPtr;
634+
buffers.push(appctx_keys as any);
635+
buffers.push(appctx_values as any);
636+
637+
let position = 0;
638+
for (const [key, value] of runtimeConfigProperties.entries()) {
639+
const keyPtr = stringToUTF8Ptr(key);
640+
const valuePtr = stringToUTF8Ptr(value);
641+
setU32((appctx_keys as any) + (position * 4), keyPtr);
642+
setU32((appctx_values as any) + (position * 4), valuePtr);
643+
position++;
644+
buffers.push(keyPtr as any);
645+
buffers.push(valuePtr as any);
646+
}
647+
648+
cwraps.mono_wasm_load_runtime(debugLevel, propertyCount, appctx_keys, appctx_values);
649+
650+
// free the buffers
651+
for (const buffer of buffers) {
652+
Module._free(buffer);
653+
}
654+
621655
endMeasure(mark, MeasuredBlock.loadRuntime);
622656

623657
} catch (err: any) {

src/mono/browser/runtime/types/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ export type MonoConfig = {
144144
environmentVariables?: {
145145
[i: string]: string;
146146
},
147+
/**
148+
* Subset of runtimeconfig.json
149+
*/
150+
runtimeConfig?: {
151+
runtimeOptions?: {
152+
configProperties?: {
153+
[i: string]: string | number | boolean;
154+
}
155+
}
156+
},
147157
/**
148158
* initial number of workers to add to the emscripten pthread pool
149159
*/

src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Copyright (c) .NET Foundation. All rights reserved.
130130
</AddWasmStaticWebAssetsDependsOn>
131131
<GenerateBuildWasmBootJsonDependsOn>
132132
$(GenerateBuildWasmBootJsonDependsOn);
133+
GenerateBuildRuntimeConfigurationFiles;
133134
ResolveWasmOutputs;
134135
</GenerateBuildWasmBootJsonDependsOn>
135136
</PropertyGroup>
@@ -403,6 +404,7 @@ Copyright (c) .NET Foundation. All rights reserved.
403404
Extensions="@(WasmBootConfigExtension)"
404405
EnvVariables="@(WasmEnvironmentVariable)"
405406
Profilers="$(_WasmProfilers)"
407+
RuntimeConfigJsonPath="$(ProjectRuntimeConfigFilePath)"
406408
TargetFrameworkVersion="$(TargetFrameworkVersion)"
407409
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"
408410
ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)"
@@ -810,6 +812,7 @@ Copyright (c) .NET Foundation. All rights reserved.
810812
RuntimeOptions="$(_BlazorWebAssemblyRuntimeOptions)"
811813
EnvVariables="@(WasmEnvironmentVariable)"
812814
Profilers="$(_WasmProfilers)"
815+
RuntimeConfigJsonPath="$(ProjectRuntimeConfigFilePath)"
813816
Extensions="@(WasmBootConfigExtension)"
814817
TargetFrameworkVersion="$(TargetFrameworkVersion)"
815818
ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)"

0 commit comments

Comments
 (0)