Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add runtimeconfig.json support for WebAssembly #56486

Merged
merged 29 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6bb8c65
Initial change for adding runtimeconfig to wasm
fanyang-mono Jul 20, 2021
6336f0a
Add runtimeconfig support to wasm
fanyang-mono Jul 22, 2021
593ca12
Move test folder and update runtimeconifg task name
fanyang-mono Jul 22, 2021
2a00cd7
Fix test
fanyang-mono Jul 22, 2021
f1d71a2
Fix test csproj file
fanyang-mono Jul 28, 2021
b17864f
Use the right var for main dll name
fanyang-mono Jul 28, 2021
905ae91
Resolve review feedback part 1
fanyang-mono Jul 29, 2021
ad3e285
Resolve review feedbacks part 2
fanyang-mono Jul 29, 2021
2965386
Add doc for updating dependencies when adding new tasks
fanyang-mono Jul 29, 2021
b65538c
Remove redundant condition and redundant copy
fanyang-mono Jul 30, 2021
ad37573
There is no runtimeconfig.json file to parse, when OutputType is libr…
fanyang-mono Jul 30, 2021
eb65cc2
Skip for Android tests as well.
fanyang-mono Jul 30, 2021
093c0a4
Remove the wrong locatioin of WasmFilesToIncludeInFileSystem
fanyang-mono Jul 30, 2021
e147641
Update runtimeconfig file path
fanyang-mono Jul 31, 2021
9d2f53c
Add RuntimeConfigParserTasksAssemblyPath to linker test project template
fanyang-mono Jul 31, 2021
b7bc84c
Fix test failures on WASM EAT and AOT lanes
fanyang-mono Aug 2, 2021
e8bfc59
[wasm] Add a test for reading runtimeconfig.json
radical Aug 3, 2021
2cfc3de
improve error reporting slightly
radical Aug 3, 2021
034887c
Enable tests
fanyang-mono Aug 3, 2021
de4284a
One more thing to enable tests
fanyang-mono Aug 3, 2021
f0b1fde
Run target _WasmGenerateRuntimeConfig when runtimeconfig.json file ex…
fanyang-mono Aug 4, 2021
e284581
Add a test for configure runtime using msbuild properties
fanyang-mono Aug 4, 2021
bef52de
Fix runtime test failures
fanyang-mono Aug 5, 2021
9bcb10a
Update tests base on feedback
fanyang-mono Aug 5, 2021
ee244ba
Add missing ")"
fanyang-mono Aug 5, 2021
c909ef2
Add one more condition
fanyang-mono Aug 6, 2021
c0a7981
More format changes
fanyang-mono Aug 6, 2021
29818f5
Better error handling
fanyang-mono Aug 6, 2021
2fddcba
[wasm] Fix build for a test support project
radical Aug 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/testing/linker/project.csproj.template
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<MonoAOTCompilerTasksAssemblyPath>{MonoAOTCompilerTasksAssemblyPath}</MonoAOTCompilerTasksAssemblyPath>
<WasmAppBuilderTasksAssemblyPath>{WasmAppBuilderTasksAssemblyPath}</WasmAppBuilderTasksAssemblyPath>
<JsonToItemsTaskFactoryTasksAssemblyPath>{JsonToItemsTaskFactoryTasksAssemblyPath}</JsonToItemsTaskFactoryTasksAssemblyPath>
<RuntimeConfigParserTasksAssemblyPath>{RuntimeConfigParserTasksAssemblyPath}</RuntimeConfigParserTasksAssemblyPath>
<MicrosoftNetCoreAppRuntimePackRidDir>{MicrosoftNetCoreAppRuntimePackRidDir}</MicrosoftNetCoreAppRuntimePackRidDir>
<RepositoryEngineeringDir>{RepositoryEngineeringDir}</RepositoryEngineeringDir>
<TargetFramework>{TestTargetFramework}</TargetFramework>
Expand Down
1 change: 1 addition & 0 deletions eng/testing/linker/trimmingTests.targets
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
.Replace('{MonoProjectRoot}', '$(MonoProjectRoot)')
.Replace('{MonoAOTCompilerTasksAssemblyPath}', '$(MonoAOTCompilerTasksAssemblyPath)')
.Replace('{JsonToItemsTaskFactoryTasksAssemblyPath}', '$(JsonToItemsTaskFactoryTasksAssemblyPath)')
.Replace('{RuntimeConfigParserTasksAssemblyPath}', '$(RuntimeConfigParserTasksAssemblyPath)')
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
.Replace('{WasmAppBuilderTasksAssemblyPath}', '$(WasmAppBuilderTasksAssemblyPath)')
.Replace('{MicrosoftNetCoreAppRuntimePackRidDir}', '$(MicrosoftNetCoreAppRuntimePackRidDir)'))"
Overwrite="true" />
Expand Down
4 changes: 2 additions & 2 deletions eng/testing/tests.mobile.targets
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
AssemblyFile="$(RuntimeConfigParserTasksAssemblyPath)"
Condition="'$(RuntimeConfigParserTasksAssemblyPath)' != ''" />

<Target Name="GenerateRuntimeConfig">
<Target Name="GenerateRuntimeConfig" Condition="'$(OutputType)' != 'library' and '$(TargetOS)' != 'Browser'">
<PropertyGroup>
<RuntimeConfigFilePath>$(PublishDir)$(AssemblyName).runtimeconfig.json</RuntimeConfigFilePath>
<ParsedRuntimeConfigFilePath>$(PublishDir)runtimeconfig.bin</ParsedRuntimeConfigFilePath>
</PropertyGroup>

<ItemGroup Condition="'$(RunAOTCompilation)' == 'true'">
<ItemGroup>
<RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER"/>
<RuntimeConfigReservedProperties Include="APP_CONTEXT_BASE_DIRECTORY"/>
</ItemGroup>
Expand Down
7 changes: 7 additions & 0 deletions eng/testing/tests.wasm.targets
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@
AssemblyFile="$(WasmBuildTasksAssemblyPath)" />

<Target Name="_BundleAOTTestWasmAppForHelix" DependsOnTargets="PrepareForWasmBuildApp">
<PropertyGroup>
<_MainAssemblyPath Condition="'%(WasmAssembliesToBundle.FileName)' == $(AssemblyName) and '%(WasmAssembliesToBundle.Extension)' == '.dll'">%(WasmAssembliesToBundle.Identity)</_MainAssemblyPath>
<RuntimeConfigFilePath>$([System.IO.Path]::ChangeExtension($(_MainAssemblyPath), '.runtimeconfig.json'))</RuntimeConfigFilePath>
</PropertyGroup>

<ItemGroup>
<BundleFiles Include="$(WasmMainJSPath)" TargetDir="publish" />
<BundleFiles Include="@(WasmAssembliesToBundle)" TargetDir="publish\%(WasmAssembliesToBundle.RecursiveDir)" />
<BundleFiles Include="$(RuntimeConfigFilePath)" TargetDir="publish" />

<BundleFiles Include="$(MonoProjectRoot)\wasm\data\aot-tests\*" TargetDir="publish" />
</ItemGroup>
Expand All @@ -99,6 +105,7 @@
<_WasmPropertyNames Include="WasmLinkIcalls" />
<_WasmPropertyNames Include="WasmDedup" />
<_WasmPropertyNames Include="IncludeSatelliteAssembliesInVFS" />
<_WasmPropertyNames Include="AssemblyName" />

<_WasmPropertiesToPass
Include="$(%(_WasmPropertyNames.Identity))"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<TestRuntime>true</TestRuntime>
<IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI> <!-- remove once https://github.com/dotnet/runtime/issues/38433 is fixed -->
</PropertyGroup>
<ItemGroup>
<Compile Include="ActivityTests.cs" />
Expand Down
2 changes: 0 additions & 2 deletions src/libraries/System.Text.Encoding/tests/Encoding/Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public static void GetEncodingsTest()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
[Theory]
[MemberData(nameof(Encoding_TestData))]
public static void VerifyCodePageAttributes(int codepage, string name, string bodyName, string headerName, bool isBrowserDisplay,
Expand All @@ -81,7 +80,6 @@ public static void VerifyCodePageAttributes(int codepage, string name, string bo
Assert.Equal(windowsCodePage, encoding.WindowsCodePage);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
[Theory]
[MemberData(nameof(Normalization_TestData))]
public static void NormalizationTest(int codepage, bool normalized, bool normalizedC, bool normalizedD, bool normalizedKC, bool normalizedKD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public CodePageMapping(string name, int codepage)
new CodePageMapping("x-unicode-2-0-utf-8", 65001)
};

[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
[Fact]
public void TestEncodingNameAndCopdepageNumber()
{
Expand All @@ -99,7 +98,6 @@ public void TestEncodingNameAndCopdepageNumber()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
[Fact]
public void GetEncoding_EncodingName()
{
Expand All @@ -119,7 +117,6 @@ public void GetEncoding_EncodingName()
}
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
[Fact]
public void GetEncoding_WebName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.Text.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
public class UTF7EncodingEncode
{
public static IEnumerable<object[]> Encode_Basic_TestData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

namespace System.Text.Tests
{
[ActiveIssue("https://github.com/dotnet/runtime/issues/38433", TestPlatforms.Browser)] // wasm doesn't honor runtimeconfig.json
public class UTF7EncodingTests
{
[Fact]
Expand Down
1 change: 1 addition & 0 deletions src/libraries/sendtohelixhelp.proj
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
<HelixCorrelationPayload Include="$(WasmBuildTargetsDir)" Destination="build/wasm" />
<HelixCorrelationPayload Include="$(MonoAotCrossDir)" Destination="build/cross" />
<HelixCorrelationPayload Include="$(JsonToItemsTaskFactoryDir)" Destination="build/JsonToItemsTaskFactory" />
<HelixCorrelationPayload Include="$(RuntimeConfigParserDir)" Destination="build/RuntimeConfigParser" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'BuildWasmApps'">
Expand Down
3 changes: 0 additions & 3 deletions src/libraries/tests.proj
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.Xml\tests\System.Security.Cryptography.Xml.Tests.csproj" />
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Security.Cryptography.X509Certificates\tests\System.Security.Cryptography.X509Certificates.Tests.csproj" />

<!-- https://github.com/dotnet/runtime/issues/38433 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Diagnostics.DiagnosticSource/tests/TestWithConfigSwitches/System.Diagnostics.DiagnosticSource.Switches.Tests.csproj" />

<!-- Issue: https://github.com/dotnet/runtime/issues/55767 -->
<ProjectExclusions Include="$(MSBuildThisFileDirectory)System.Runtime.Experimental\tests\System.Runtime.Experimental.Tests.csproj" />
</ItemGroup>
Expand Down
26 changes: 26 additions & 0 deletions src/mono/wasm/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,29 @@ The various task inputs correspond to properties as:
This should be a step towards eventually having this build as a sdk.

Refer to `WasmApp.targets` for more information about the properties/items used as inputs to the process.

## Updating dependencies needed for building wasm apps

For example, if the wasm targets are using a new task, then references to that
need to be updated in a few places. Essentially, look for existing references
to `MonoAOTCompiler`, or `WasmAppBuilder` in the relevant files, and duplicate
them for the new task assembly.

1. The task assembly dir, and its path need to be in two properties:
```xml
<JsonToItemsTaskFactoryDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'JsonToItemsTaskFactory', 'Debug', '$(NetCoreAppToolCurrent)'))</JsonToItemsTaskFactoryDir>
<JsonToItemsTaskFactoryTasksAssemblyPath>$([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll'))</JsonToItemsTaskFactoryTasksAssemblyPath>
```

And this needs to be set in:
- `Directory.Build.props`
- `src/mono/wasm/build/WasmApp.LocalBuild.props`
- `src/mono/wasm/build/WasmApp.LocalBuild.targets`
- `src/tests/Common/wasm-test-runner/WasmTestRunner.proj`

2. The new dependency (eg. task assembly) needs to be sent to helix as a payload, see `src/libraries/sendtohelixhelp.proj`. Use `MonoAOTCompiler` as an example.

3. Make changes similar to the one for existing dependent tasks in
- `eng/testing/linker/trimmingTests.targets`,
- `src/tests/Common/wasm-test-runner/WasmTestRunner.proj`
- `src/tests/Directory.Build.targets`
1 change: 1 addition & 0 deletions src/mono/wasm/build/WasmApp.InTree.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<!-- This depends on the root Directory.Build.targets imported this file -->
<UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />
<UsingTask TaskName="RuntimeConfigParserTask" AssemblyFile="$(RuntimeConfigParserTasksAssemblyPath)" />

<!-- 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 -->
<!--<Import Project="$(RepositoryEngineeringDir)targetingpacks.targets" Condition="'$(TargetingpacksTargetsImported)' != 'true'"/>-->
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/build/WasmApp.LocalBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<WasmAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmAppBuilder', 'Debug', '$(_NetCoreAppToolCurrent)', 'publish'))</WasmAppBuilderDir>
<WasmBuildTasksDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmBuildTasks', 'Debug', '$(_NetCoreAppToolCurrent)', 'publish'))</WasmBuildTasksDir>
<MonoAOTCompilerDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoAOTCompiler', 'Debug', '$(_NetCoreAppToolCurrent)'))</MonoAOTCompilerDir>
<RuntimeConfigParserDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'RuntimeConfigParser', 'Debug', '$(_NetCoreAppToolCurrent)'))</RuntimeConfigParserDir>
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
<JsonToItemsTaskFactoryDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'JsonToItemsTaskFactory', 'Debug', '$(_NetCoreAppToolCurrent)'))</JsonToItemsTaskFactoryDir>

<MonoArtifactsPath>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'mono', '$(TargetOS).$(TargetArchitecture).$(RuntimeConfig)'))</MonoArtifactsPath>
Expand All @@ -47,6 +48,7 @@

<MicrosoftNetCoreAppRuntimePackLocationToUse>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'microsoft.netcore.app.runtime.browser-wasm'))</MicrosoftNetCoreAppRuntimePackLocationToUse>
<MonoAOTCompilerDir>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'MonoAOTCompiler'))</MonoAOTCompilerDir>
<RuntimeConfigParserDir>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'RuntimeConfigParser'))</RuntimeConfigParserDir>
<JsonToItemsTaskFactoryDir>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'JsonToItemsTaskFactory'))</JsonToItemsTaskFactoryDir>
<WasmAppBuilderDir>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'WasmAppBuilder'))</WasmAppBuilderDir>
<WasmBuildTasksDir>$([MSBuild]::NormalizeDirectory($(BuildBaseDir), 'WasmBuildTasks'))</WasmBuildTasksDir>
Expand All @@ -65,6 +67,7 @@
<WasmAppBuilderTasksAssemblyPath>$([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll'))</WasmAppBuilderTasksAssemblyPath>
<WasmBuildTasksAssemblyPath>$([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll'))</WasmBuildTasksAssemblyPath>
<MonoAOTCompilerTasksAssemblyPath>$([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll'))</MonoAOTCompilerTasksAssemblyPath>
<RuntimeConfigParserTasksAssemblyPath>$([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll'))</RuntimeConfigParserTasksAssemblyPath>
<JsonToItemsTaskFactoryTasksAssemblyPath>$([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll'))</JsonToItemsTaskFactoryTasksAssemblyPath>
</PropertyGroup>

Expand Down
2 changes: 2 additions & 0 deletions src/mono/wasm/build/WasmApp.LocalBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<Project>
<Import Project="$(MSBuildThisFileDirectory)WasmApp.targets" />
<UsingTask TaskName="MonoAOTCompiler" AssemblyFile="$(MonoAOTCompilerTasksAssemblyPath)" />
<UsingTask TaskName="RuntimeConfigParserTask" AssemblyFile="$(RuntimeConfigParserTasksAssemblyPath)" />

<PropertyGroup>
<PublishTrimmed>true</PublishTrimmed>
Expand Down Expand Up @@ -64,6 +65,7 @@
<WasmAppBuilderTasksAssemblyPath>$([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll'))</WasmAppBuilderTasksAssemblyPath>
<WasmBuildTasksAssemblyPath>$([MSBuild]::NormalizePath('$(WasmBuildTasksDir)', 'WasmBuildTasks.dll'))</WasmBuildTasksAssemblyPath>
<MonoAOTCompilerTasksAssemblyPath>$([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll'))</MonoAOTCompilerTasksAssemblyPath>
<RuntimeConfigParserTasksAssemblyPath>$([MSBuild]::NormalizePath('$(RuntimeConfigParserDir)', 'RuntimeConfigParser.dll'))</RuntimeConfigParserTasksAssemblyPath>
<JsonToItemsTaskFactoryTasksAssemblyPath>$([MSBuild]::NormalizePath('$(JsonToItemsTaskFactoryDir)', 'JsonToItemsTaskFactory.dll'))</JsonToItemsTaskFactoryTasksAssemblyPath>
</PropertyGroup>

Expand Down
31 changes: 30 additions & 1 deletion src/mono/wasm/build/WasmApp.targets
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,15 @@
<WasmMainAssemblyFileName Condition="'$(WasmMainAssemblyFileName)' == ''">$(TargetFileName)</WasmMainAssemblyFileName>

<WasmAppDir>$([MSBuild]::NormalizeDirectory($(WasmAppDir)))</WasmAppDir>

<_MainAssemblyPath Condition="'%(WasmAssembliesToBundle.FileName)' == $(AssemblyName) and '%(WasmAssembliesToBundle.Extension)' == '.dll' and $(WasmGenerateAppBundle) == 'true'">%(WasmAssembliesToBundle.Identity)</_MainAssemblyPath>
<_WasmRuntimeConfigFilePath Condition="$(_MainAssemblyPath) != ''">$([System.IO.Path]::ChangeExtension($(_MainAssemblyPath), '.runtimeconfig.json'))</_WasmRuntimeConfigFilePath>
</PropertyGroup>

<Warning Condition="'$(WasmGenerateAppBundle)' == 'true' and $(_MainAssemblyPath) == ''" Text="Could not find %24(AssemblyName)=$(AssemblyName) in the assemblies to be bundled.." />
<Warning Condition="'$(WasmGenerateAppBundle)' == 'true' and $(_WasmRuntimeConfigFilePath) != '' and !Exists($(_WasmRuntimeConfigFilePath))"
Text="Could not find $(_WasmRuntimeConfigFilePath) for $(_MainAssemblyPath)." />

<ItemGroup>
<_WasmAssembliesInternal Include="@(WasmAssembliesToBundle->Distinct())" />

Expand All @@ -136,7 +143,29 @@
</ItemGroup>
</Target>

<Target Name="_WasmGenerateAppBundle" Condition="'$(WasmGenerateAppBundle)' == 'true'">
<Target Name="_WasmGenerateRuntimeConfig" Condition="Exists('$(_WasmRuntimeConfigFilePath)')">
<PropertyGroup>
<_ParsedRuntimeConfigFilePath>$([System.IO.Path]::GetDirectoryName($(_MainAssemblyPath)))\runtimeconfig.bin</_ParsedRuntimeConfigFilePath>
</PropertyGroup>

<ItemGroup>
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER"/>
<_RuntimeConfigReservedProperties Include="APP_CONTEXT_BASE_DIRECTORY"/>
</ItemGroup>

<!-- Parse *.runtimeconfig.json file -->
<RuntimeConfigParserTask
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
RuntimeConfigFile="$(_WasmRuntimeConfigFilePath)"
OutputFile="$(_ParsedRuntimeConfigFilePath)"
RuntimeConfigReservedProperties="@(_RuntimeConfigReservedProperties)">
</RuntimeConfigParserTask>

<ItemGroup>
<WasmFilesToIncludeInFileSystem Include="$(_ParsedRuntimeConfigFilePath)" />
</ItemGroup>
</Target>

<Target Name="_WasmGenerateAppBundle" Condition="'$(WasmGenerateAppBundle)' == 'true'" DependsOnTargets="_WasmGenerateRuntimeConfig">
fanyang-mono marked this conversation as resolved.
Show resolved Hide resolved
<Error Condition="'$(WasmMainJSPath)' == ''" Text="%24(WasmMainJSPath) property needs to be set" />

<PropertyGroup>
Expand Down
30 changes: 29 additions & 1 deletion src/mono/wasm/runtime/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdint.h>
#include <assert.h>
#include <dlfcn.h>
#include <sys/stat.h>

#include <mono/metadata/assembly.h>
#include <mono/metadata/tokentype.h>
Expand Down Expand Up @@ -92,6 +93,8 @@ void mono_trace_init (void);

static MonoDomain *root_domain;

#define RUNTIMECONFIG_BIN_FILE "runtimeconfig.bin"

static MonoString*
mono_wasm_invoke_js (MonoString *str, int *is_exception)
{
Expand Down Expand Up @@ -476,6 +479,13 @@ mono_wasm_register_bundled_satellite_assemblies ()

void mono_wasm_link_icu_shim (void);

void
cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data)
{
free (args);
free (user_data);
}

EMSCRIPTEN_KEEPALIVE void
mono_wasm_load_runtime (const char *unused, int debug_level)
{
Expand All @@ -493,7 +503,8 @@ mono_wasm_load_runtime (const char *unused, int debug_level)
// corlib assemblies.
monoeg_g_setenv ("COMPlus_DebugWriteToStdErr", "1", 0);
#endif

// When the list of app context properties changes, please update RuntimeConfigReservedProperties for
// target _WasmGenerateRuntimeConfig in WasmApp.targets file
const char *appctx_keys[2];
appctx_keys [0] = "APP_CONTEXT_BASE_DIRECTORY";
appctx_keys [1] = "RUNTIME_IDENTIFIER";
Expand All @@ -502,6 +513,23 @@ mono_wasm_load_runtime (const char *unused, int debug_level)
appctx_values [0] = "/";
appctx_values [1] = "browser-wasm";

char *file_name = RUNTIMECONFIG_BIN_FILE;
int str_len = strlen (file_name) + 1; // +1 is for the "/"
char *file_path = (char *)malloc (sizeof (char) * (str_len +1)); // +1 is for the terminating null character
int num_char = snprintf (file_path, (str_len + 1), "/%s", file_name);
struct stat buffer;

assert (num_char > 0 && num_char == str_len);

if (stat (file_path, &buffer) == 0) {
MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments));
arg->kind = 0;
arg->runtimeconfig.name.path = file_path;
monovm_runtimeconfig_initialize (arg, cleanup_runtime_config, file_path);
} else {
free (file_path);
}

monovm_initialize (2, appctx_keys, appctx_values);

mini_parse_debug_option ("top-runtime-invoke-unhandled");
Expand Down
8 changes: 4 additions & 4 deletions src/tasks/AndroidAppBuilder/Templates/monodroid.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ mono_droid_runtime_init (const char* executable, int managed_argc, char* managed
appctx_values[1] = bundle_path;

char *file_name = RUNTIMECONFIG_BIN_FILE;
int str_len = strlen (bundle_path) + strlen (file_name) + 2;
char *file_path = (char *)malloc (sizeof (char) * str_len);
int num_char = snprintf (file_path, str_len, "%s/%s", bundle_path, file_name);
int str_len = strlen (bundle_path) + strlen (file_name) + 1; // +1 is for the "/"
char *file_path = (char *)malloc (sizeof (char) * (str_len +1)); // +1 is for the terminating null character
int num_char = snprintf (file_path, (str_len + 1), "%s/%s", bundle_path, file_name);
struct stat buffer;

LOG_INFO ("file_path: %s\n", file_path);
assert (num_char > 0 && num_char < str_len);
assert (num_char > 0 && num_char == str_len);

if (stat (file_path, &buffer) == 0) {
MonovmRuntimeConfigArguments *arg = (MonovmRuntimeConfigArguments *)malloc (sizeof (MonovmRuntimeConfigArguments));
Expand Down
Loading