dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.97k stars 4.65k forks source link

[browser] Support AppContext switches on runtime #97449

Open maraf opened 7 months ago

maraf commented 7 months ago

AppContext switches defined in csproj are not available on runtime

<ItemGroup>
    ...
    <RuntimeHostConfigurationOption Include="System.Runtime.OptionalFeatureBehavior"
                                    Condition="'$(UnoptimizedUserFacingBehavior)' != ''"
                                    Value="$(UnoptimizedUserFacingBehavior)"
                                    Link="false" />
    ...
</ItemGroup>

On other platforms, they end up in runtime.config.json. We should put them into blazor.boot.json as that's the only config required (for both wasmbrowser and blazor experience)

ghost commented 7 months ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
AppContext switches defined in csproj are not available on runtime ``` ... ... ``` On other platforms, they end up in `runtime.config.json`. We should put them into `blazor.boot.json` as that's the only config required (for both wasmbrowser and blazor experience)
Author: maraf
Assignees: -
Labels: `arch-wasm`, `area-Build-mono`, `os-browser`
Milestone: 9.0.0
lewing commented 7 months ago

AppContext switches defined in csproj are not available on runtime

<ItemGroup>
    ...
    <RuntimeHostConfigurationOption Include="System.Runtime.OptionalFeatureBehavior"
                                    Condition="'$(UnoptimizedUserFacingBehavior)' != ''"
                                    Value="$(UnoptimizedUserFacingBehavior)"
                                    Link="false" />
    ...
</ItemGroup>

On other platforms, they end up in runtime.config.json. We should put them into blazor.boot.json as that's the only config required (for both wasmbrowser and blazor experience)

That works for browser but we will have the same issue in wasi where there is no json parser.

maraf commented 7 months ago

That works for browser but we will have the same issue in wasi where there is no json parser.

That's true. We can use the binary format for WASI and we bundle it into wasm file even for browser, but I would like to avoid distributing it as a separate file for browser scenario

lambdageek commented 7 months ago

Mono has a task that converts rutnimeconfig.json files into a binary blob at build time so you don't need to do JSON parsing at execution time https://github.com/dotnet/runtime/blob/main/src/tasks/MonoTargetsTasks/RuntimeConfigParser/RuntimeConfigParser.cs

the binary blob can be passed by the driver to monovm_runtimeconfig_initialize:

https://github.com/dotnet/runtime/blob/77fd98c8fb245b30b24b8eeaf577b0a457a4449c/src/native/public/mono/jit/details/mono-private-unstable-functions.h#L21

https://github.com/dotnet/runtime/blob/77fd98c8fb245b30b24b8eeaf577b0a457a4449c/src/native/public/mono/jit/details/mono-private-unstable-types.h#L21-L34

This is used by xamarin-android, for example:

https://github.com/xamarin/xamarin-android/blob/e67afc7d7ae848da6b33026b80973d30713b98ad/src/monodroid/jni/monodroid-glue.cc#L846-L848