diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs index e1620d2dd77101..15f33923a1b8a4 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/ReferenceNewAssemblyRebuildTest.cs @@ -25,7 +25,13 @@ public ReferenceNewAssemblyRebuildTest(ITestOutputHelper output, SharedBuildPerT [MemberData(nameof(NativeBuildData))] public async Task ReferenceNewAssembly(Configuration config, bool aot, bool nativeRelink, bool invariant) { - ProjectInfo info = CopyTestAsset(config, aot, TestAsset.WasmBasicTestApp, "rebuild_tasks"); + // Reference a dedicated first-party library that the default app does not use, so it is + // trimmed away on the first build and only enters the AOT module set once the swapped + // entry point references it. Relying on a specific BCL assembly being absent from the + // closure is fragile (it has silently regressed as the base app's dependencies grew). + string extraItems = @""; + ProjectInfo info = CopyTestAsset(config, aot, TestAsset.WasmBasicTestApp, "rebuild_tasks", extraItems: extraItems); + ReplaceFile(Path.Combine("..", "Library", "Library.cs"), Path.Combine(BuildEnvironment.TestAssetsPath, "EntryPoints", "NativeRebuildReferencedLibrary.cs")); BuildPaths paths = await FirstNativeBuildAndRun(info, config, aot, nativeRelink, invariant); var pathsDict = GetFilesTable(info.ProjectName, aot, paths, unchanged: false); diff --git a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs index bff7ffb3827a40..f870ba88b7f828 100644 --- a/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs +++ b/src/mono/wasm/testassets/EntryPoints/NativeRebuildNewAssembly.cs @@ -1,17 +1,10 @@ -using System; -using System.Security.Cryptography; -using System.Text; +// Reference a dedicated first-party library ("Library") that is not part of +// the WasmBasicTestApp's default assembly closure. This guarantees the rebuild +// pulls in a genuinely new AOT module, regardless of which BCL assemblies the +// base app happens to root. +using NativeRebuildReferencedLibrary; + public class Test { - public static int Main() - { - string input = "Hello, world!"; - using (SHA256 sha256 = SHA256.Create()) - { - byte[] inputBytes = Encoding.UTF8.GetBytes(input); - byte[] hashBytes = sha256.ComputeHash(inputBytes); - Console.WriteLine($"Hash of {input}: {Convert.ToBase64String(hashBytes)}"); - } - return 42; - } + public static int Main() => NewlyReferencedType.GetValue(); } diff --git a/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs b/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs new file mode 100644 index 00000000000000..9d2c0ed0d0ba6c --- /dev/null +++ b/src/mono/wasm/testassets/EntryPoints/NativeRebuildReferencedLibrary.cs @@ -0,0 +1,6 @@ +namespace NativeRebuildReferencedLibrary; + +public static class NewlyReferencedType +{ + public static int GetValue() => 42; +}