-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/6.0-preview6] [wasm] Build static components; include hot_re…
…load in runtime (#54622) Backport of #54568 to release/6.0-preview6 Workaround until #54565 is fixed Build the runtime always with support for hot_reload, and without diagnostics_tracing Co-authored-by: Aleksey Kliger <[email protected]> Co-authored-by: Thays Grazia <[email protected]>
- Loading branch information
1 parent
b1e9def
commit 12c92e8
Showing
14 changed files
with
306 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...mbly/Browser/HotReload/ApplyUpdateReferencedAssembly/ApplyUpdateReferencedAssembly.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="EnableAggressiveTrimming;PublishTrimmed"> | ||
<PropertyGroup> | ||
<TestRuntime>true</TestRuntime> | ||
<DeltaScript>deltascript.json</DeltaScript> | ||
<OutputType>library</OutputType> | ||
<IsTestProject>false</IsTestProject> | ||
<IsTestSupportProject>true</IsTestSupportProject> | ||
<!-- to call AsssemblyExtensions.ApplyUpdate we need Optimize=false, EmitDebugInformation=true in all configurations --> | ||
<Optimize>false</Optimize> | ||
<EmitDebugInformation>true</EmitDebugInformation> | ||
<!-- hot reload is not compatible with trimming --> | ||
<EnableAggressiveTrimming>false</EnableAggressiveTrimming> | ||
<PublishTrimmed>false</PublishTrimmed> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="MethodBody1.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<!-- This package from https://github.com/dotnet/hotreload-utils provides | ||
targets that read the json delta script and generates deltas based on the baseline assembly and the modified sources. | ||
Projects must define the DeltaScript property that specifies the (relative) path to the json script. | ||
Deltas will be emitted next to the output assembly. Deltas will be copied when the current | ||
project is referenced from other other projects. | ||
--> | ||
<PackageReference Include="Microsoft.DotNet.HotReload.Utils.Generator.BuildTool" Version="$(MicrosoftDotNetHotReloadUtilsGeneratorBuildToolVersion)" /> | ||
</ItemGroup> | ||
</Project> |
11 changes: 11 additions & 0 deletions
11
...unctionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/MethodBody1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace ApplyUpdateReferencedAssembly | ||
{ | ||
public class MethodBody1 { | ||
public static string StaticMethod1 () { | ||
return "OLD STRING"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...tionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/MethodBody1_v1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace ApplyUpdateReferencedAssembly | ||
{ | ||
public class MethodBody1 { | ||
public static string StaticMethod1 () { | ||
return "NEW STRING"; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...tionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/MethodBody1_v2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace ApplyUpdateReferencedAssembly | ||
{ | ||
public class MethodBody1 { | ||
public static string StaticMethod1 () { | ||
return "NEWEST STRING"; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ctionalTests/WebAssembly/Browser/HotReload/ApplyUpdateReferencedAssembly/deltascript.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"changes": [ | ||
{"document": "MethodBody1.cs", "update": "MethodBody1_v1.cs"}, | ||
{"document": "MethodBody1.cs", "update": "MethodBody1_v2.cs"}, | ||
] | ||
} | ||
|
81 changes: 81 additions & 0 deletions
81
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Sample | ||
{ | ||
public class Test | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Console.WriteLine ("Hello, World!"); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
public static int TestMeaning() | ||
{ | ||
const int success = 42; | ||
const int failure = 1; | ||
|
||
var ty = typeof(System.Reflection.Metadata.AssemblyExtensions); | ||
var mi = ty.GetMethod("GetApplyUpdateCapabilities", BindingFlags.NonPublic | BindingFlags.Static, Array.Empty<Type>()); | ||
|
||
if (mi == null) | ||
return failure; | ||
|
||
var caps = mi.Invoke(null, null) as string; | ||
|
||
if (String.IsNullOrEmpty(caps)) | ||
return failure; | ||
|
||
var assm = typeof (ApplyUpdateReferencedAssembly.MethodBody1).Assembly; | ||
|
||
var r = ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1(); | ||
if ("OLD STRING" != r) | ||
return failure; | ||
|
||
ApplyUpdate(assm); | ||
|
||
r = ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1(); | ||
if ("NEW STRING" != r) | ||
return failure; | ||
|
||
ApplyUpdate(assm); | ||
|
||
r = ApplyUpdateReferencedAssembly.MethodBody1.StaticMethod1(); | ||
if ("NEWEST STRING" != r) | ||
return failure; | ||
|
||
return success; | ||
} | ||
|
||
private static System.Collections.Generic.Dictionary<Assembly, int> assembly_count = new(); | ||
|
||
internal static void ApplyUpdate (System.Reflection.Assembly assm) | ||
{ | ||
int count; | ||
if (!assembly_count.TryGetValue(assm, out count)) | ||
count = 1; | ||
else | ||
count++; | ||
assembly_count [assm] = count; | ||
|
||
/* FIXME WASM: Location is empty on wasm. Make up a name based on Name */ | ||
string basename = assm.Location; | ||
if (basename == "") | ||
basename = assm.GetName().Name + ".dll"; | ||
Console.Error.WriteLine($"Apply Delta Update for {basename}, revision {count}"); | ||
|
||
string dmeta_name = $"{basename}.{count}.dmeta"; | ||
string dil_name = $"{basename}.{count}.dil"; | ||
byte[] dmeta_data = System.IO.File.ReadAllBytes(dmeta_name); | ||
byte[] dil_data = System.IO.File.ReadAllBytes(dil_name); | ||
byte[] dpdb_data = null; // TODO also use the dpdb data | ||
|
||
System.Reflection.Metadata.AssemblyExtensions.ApplyUpdate(assm, dmeta_data, dil_data, dpdb_data); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/FunctionalTests/WebAssembly/Browser/HotReload/WebAssembly.Browser.HotReload.Test.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<MonoForceInterpreter>true</MonoForceInterpreter> | ||
<RunAOTCompilation>false</RunAOTCompilation> | ||
<PublishTrimmed>false</PublishTrimmed> | ||
<TestRuntime>true</TestRuntime> | ||
<Scenario>WasmTestOnBrowser</Scenario> | ||
<ExpectedExitCode>42</ExpectedExitCode> | ||
<WasmMainJSPath>runtime.js</WasmMainJSPath> | ||
<EnableDefaultItems>false</EnableDefaultItems> | ||
<!-- setting WasmXHarnessMonoArgs doesn't work here, but see runtime.js --> | ||
<!-- <WasmXHarnessMonoArgs>- -setenv=DOTNET_MODIFIABLE_ASSEMBLIES=debug</WasmXHarnessMonoArgs> --> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Content Include="index.html"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<ProjectReference Include="ApplyUpdateReferencedAssembly\ApplyUpdateReferencedAssembly.csproj" /> | ||
</ItemGroup> | ||
|
||
<Target Name="AfterWasmBuildApp" AfterTargets="WasmBuildApp"> | ||
<Copy SourceFiles="$(OutDir)\index.html" DestinationFolder="$(WasmAppDir)" /> | ||
</Target> | ||
|
||
<Target Name="PreserveEnCAssembliesFromLinking" | ||
Condition="'$(TargetOS)' == 'Browser' and '$(EnableAggressiveTrimming)' == 'true'" | ||
BeforeTargets="ConfigureTrimming"> | ||
<ItemGroup> | ||
<!-- Don't modify EnC test assemblies --> | ||
<TrimmerRootAssembly | ||
Condition="$([System.String]::Copy('%(ResolvedFileToPublish.FileName)%(ResolvedFileToPublish.Extension)').EndsWith('ApplyUpdateReferencedAssembly.dll'))" | ||
Include="%(ResolvedFileToPublish.FullPath)" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
<Target Name="IncludeDeltasInWasmBundle" | ||
BeforeTargets="PrepareForWasmBuildApp" | ||
Condition="'$(TargetOS)' == 'Browser'"> | ||
<ItemGroup> | ||
<!-- FIXME: this belongs in eng/testing/tests.wasm.targets --> | ||
<!-- FIXME: Can we do something on the Content items in the referenced projects themselves to get this for free? --> | ||
<WasmFilesToIncludeInFileSystem Include="@(PublishItemsOutputGroupOutputs)" | ||
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dmeta'))" /> | ||
<WasmFilesToIncludeInFileSystem Include="@(PublishItemsOutputGroupOutputs)" | ||
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dil'))" /> | ||
<WasmFilesToIncludeInFileSystem Include="@(PublishItemsOutputGroupOutputs)" | ||
Condition="$([System.String]::new('%(PublishItemsOutputGroupOutputs.Identity)').EndsWith('.dpdb'))" /> | ||
</ItemGroup> | ||
</Target> | ||
|
||
</Project> |
56 changes: 56 additions & 0 deletions
56
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<!DOCTYPE html> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. --> | ||
<!-- The .NET Foundation licenses this file to you under the MIT license. --> | ||
<html> | ||
<head> | ||
<title>TESTS</title> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body onload="onLoad()"> | ||
<h3 id="header">Wasm Browser Sample</h3> | ||
Result from Sample.Test.TestMeaning: <span id="out"></span> | ||
<script type='text/javascript'> | ||
var is_testing = false; | ||
var onLoad = function() { | ||
var url = new URL(decodeURI(window.location)); | ||
let args = url.searchParams.getAll('arg'); | ||
is_testing = args !== undefined && (args.find(arg => arg == '--testing') !== undefined); | ||
}; | ||
|
||
var test_exit = function(exit_code) | ||
{ | ||
if (!is_testing) { | ||
console.log(`test_exit: ${exit_code}`); | ||
return; | ||
} | ||
|
||
/* Set result in a tests_done element, to be read by xharness */ | ||
var tests_done_elem = document.createElement("label"); | ||
tests_done_elem.id = "tests_done"; | ||
tests_done_elem.innerHTML = exit_code.toString(); | ||
document.body.appendChild(tests_done_elem); | ||
|
||
console.log(`WASM EXIT ${exit_code}`); | ||
}; | ||
|
||
var App = { | ||
init: function () { | ||
var exit_code = BINDING.call_static_method("[WebAssembly.Browser.HotReload.Test] Sample.Test:TestMeaning", []); | ||
document.getElementById("out").innerHTML = exit_code; | ||
|
||
if (is_testing) | ||
{ | ||
console.debug(`exit_code: ${exit_code}`); | ||
test_exit(exit_code); | ||
} | ||
}, | ||
}; | ||
</script> | ||
<script type="text/javascript" src="mono-config.js"></script> | ||
<script type="text/javascript" src="runtime.js"></script> | ||
|
||
<script defer src="dotnet.js"></script> | ||
|
||
</body> | ||
</html> |
34 changes: 34 additions & 0 deletions
34
src/tests/FunctionalTests/WebAssembly/Browser/HotReload/runtime.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
var Module = { | ||
onRuntimeInitialized: function () { | ||
config.loaded_cb = function () { | ||
try { | ||
App.init (); | ||
} catch (error) { | ||
test_exit(1); | ||
throw (error); | ||
} | ||
}; | ||
config.fetch_file_cb = function (asset) { | ||
return fetch (asset, { credentials: 'same-origin' }); | ||
} | ||
|
||
if (config.environment_variables !== undefined) { | ||
console.log ("expected environment variables to be undefined, but they're: ", config.environment_variables); | ||
test_exit(1); | ||
} | ||
config.environment_variables = { | ||
"DOTNET_MODIFIABLE_ASSEMBLIES": "debug" | ||
}; | ||
|
||
try | ||
{ | ||
MONO.mono_load_runtime_and_bcl_args (config); | ||
} catch (error) { | ||
test_exit(1); | ||
throw(error); | ||
} | ||
}, | ||
}; |