Add runtimeconfig.json support for WebAssembly (#56486)
authorFan Yang <52458914+fanyang-mono@users.noreply.github.com>
Fri, 6 Aug 2021 13:04:16 +0000 (09:04 -0400)
committerGitHub <noreply@github.com>
Fri, 6 Aug 2021 13:04:16 +0000 (09:04 -0400)
commit13f80656cde1f8db4edba63dad09cd28831fee9f
treec095f093a03e1e6ea798b73f9533bae753bbc137
parenta8baca13ea08916e32b57413488a6cd0a20c6d13
Add runtimeconfig.json support for WebAssembly (#56486)

* Initial change for adding runtimeconfig to wasm

* Add runtimeconfig support to wasm

* Move test folder and update runtimeconifg task name

* Fix test

* Fix test csproj file

* Use the right var for main dll name

* Resolve review feedback part 1

* Resolve review feedbacks part 2

* Add doc for updating dependencies when adding new tasks

* Remove redundant condition and redundant copy

* There is no runtimeconfig.json file to parse, when OutputType is library. So skip it.

* Skip for Android tests as well.

* Remove the wrong locatioin of WasmFilesToIncludeInFileSystem

* Update runtimeconfig file path

* Add RuntimeConfigParserTasksAssemblyPath to linker test project template

* Fix test failures on WASM EAT and AOT lanes

* [wasm] Add a test for reading runtimeconfig.json

* improve error reporting slightly

* Enable tests

* One more thing to enable tests

* Run target _WasmGenerateRuntimeConfig when runtimeconfig.json file exists

* Add a test for configure runtime using msbuild properties

* Fix runtime test failures

* Update tests base on feedback

* Add missing ")"

* Add one more condition

* More format changes

* Better error handling

* [wasm] Fix build for a test support project

This fixes the build for ApplyUpdateReferencedAssembly.csproj, which is
a support project for HotReload wasm functional test.

```
D:\workspace\_work\1\s\src\mono\wasm\build\WasmApp.targets(131,5): error : Could not find
    D:\workspace\_work\1\s\artifacts\bin\ApplyUpdateReferencedAssembly\net6.0-Release\browser-wasm\publish\ApplyUpdateReferencedAssembly.runtimeconfig.json
    for D:\workspace\_work\1\s\artifacts\bin\ApplyUpdateReferencedAssembly\net6.0-Release\browser-wasm\publish\ApplyUpdateReferencedAssembly.dll.

    [D:\workspace\_work\1\s\src\tests\FunctionalTests\WebAssembly\Browser\HotReload\ApplyUpdateReferencedAssembly\ApplyUpdateReferencedAssembly.csproj]
```

The wasm targets should be run at all for this project. But they are run
because they get imported by tests.wasm.targets, which gets imported because
`$(IsTestProject)=true`.

The csproj has `$(IsTestProject)=false`, and `$(IsTestSupportProject)=true`,
which should mean that the test.props/targets don't get imported. But the
import is conditioned on `$(EnableTestSupport)`, which gets set in
`src/libraries/Directory.Build.props`. And that means setting
`$(IsTestProject)=true` in the csproj is too late.

So, instead, set that in a `Directory.Build.props`. And also, ensure that the
`Directory.Build.props` for functional tests doesn't override the value!

Co-authored-by: Ankit Jain <radical@gmail.com>
29 files changed:
eng/testing/linker/project.csproj.template
eng/testing/linker/trimmingTests.targets
eng/testing/tests.mobile.targets
eng/testing/tests.wasm.targets
src/libraries/System.Diagnostics.DiagnosticSource/tests/TestWithConfigSwitches/System.Diagnostics.DiagnosticSource.Switches.Tests.csproj
src/libraries/System.Text.Encoding/tests/Encoding/Encoding.cs
src/libraries/System.Text.Encoding/tests/Encoding/EncodingGetEncodingTests.cs
src/libraries/System.Text.Encoding/tests/UTF7Encoding/UTF7EncodingEncode.cs
src/libraries/System.Text.Encoding/tests/UTF7Encoding/UTF7EncodingTests.cs
src/libraries/sendtohelixhelp.proj
src/libraries/tests.proj
src/mono/wasm/build/README.md
src/mono/wasm/build/WasmApp.InTree.targets
src/mono/wasm/build/WasmApp.LocalBuild.props
src/mono/wasm/build/WasmApp.LocalBuild.targets
src/mono/wasm/build/WasmApp.targets
src/mono/wasm/runtime/driver.c
src/tasks/AndroidAppBuilder/Templates/monodroid.c
src/tests/BuildWasmApps/Wasm.Build.Tests/WasmBuildAppTest.cs
src/tests/Common/wasm-test-runner/WasmTestRunner.proj
src/tests/Directory.Build.targets
src/tests/FunctionalTests/Directory.Build.props
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/ApplyUpdateReferencedAssembly.csproj
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/Directory.Build.props [new file with mode: 0644]
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/Program.cs [new file with mode: 0644]
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/WebAssembly.Browser.RuntimeConfig.Test.csproj [new file with mode: 0644]
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/index.html [new file with mode: 0644]
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/runtime.js [new file with mode: 0644]
src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/runtimeconfig.template.json [new file with mode: 0644]