From 5485ef04ca0fac03551ce98832c0dca8eff585b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 20 Jun 2024 12:42:37 +0200 Subject: [PATCH 01/55] Build and publish integration --- ...icrosoft.NET.Sdk.WebAssembly.Browser.props | 1 + ...rosoft.NET.Sdk.WebAssembly.Browser.targets | 65 ++++---- .../AssetsComputingHelper.cs | 23 ++- .../ComputeWasmBuildAssets.cs | 46 +----- .../ComputeWasmPublishAssets.cs | 140 +++++++++++++----- .../GenerateWasmBootJson.cs | 14 +- 6 files changed, 173 insertions(+), 116 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props index 45d892d2fc467..5adc448e11f4b 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.props @@ -35,6 +35,7 @@ Copyright (c) .NET Foundation. All rights reserved. ComputeFilesToPublish;GetCurrentProjectPublishStaticWebAssetItems $(StaticWebAssetsAdditionalPublishProperties);BuildProjectReferences=false;ResolveAssemblyReferencesFindRelatedSatellites=true $(StaticWebAssetsAdditionalPublishPropertiesToRemove);NoBuild;RuntimeIdentifier + true diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index a00c5587ad9ee..784c3f7513cdd 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -65,7 +65,6 @@ Copyright (c) .NET Foundation. All rights reserved. true true - false false @@ -194,6 +193,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache) <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) + <_WasmFingerprintAssets>$(WasmFingerprintAssets) + <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">true $(OutputPath)$(PublishDirName)\ @@ -238,10 +239,8 @@ Copyright (c) .NET Foundation. All rights reserved. InvariantGlobalization="$(_WasmInvariantGlobalization)" HybridGlobalization="$(_IsHybridGlobalization)" LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)" - DotNetJsVersion="$(_WasmRuntimePackVersion)" CopySymbols="$(_WasmCopyOutputSymbolsToOutputDirectory)" OutputPath="$(OutputPath)" - FingerprintDotNetJs="$(WasmFingerprintDotnetJs)" EnableThreads="$(_WasmEnableThreads)" EmitSourceMap="$(_WasmEmitSourceMapBuild)" > @@ -259,6 +258,12 @@ Copyright (c) .NET Foundation. All rights reserved. + + <_WasmFingerprintPatterns Include="WasmFiles" Pattern="*.wasm" Expression="#[.{fingerprint}]!" /> + <_WasmFingerprintPatterns Include="DatFiles" Pattern="*.dat" Expression="#[.{fingerprint}]!" /> + <_WasmFingerprintPatterns Include="Pdb" Pattern="*.pdb" Expression="#[.{fingerprint}]!" /> + + @@ -321,10 +328,6 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'%(StaticWebAsset.AssetTraitName)' == 'JSModule' and '%(StaticWebAsset.AssetTraitValue)' == 'JSLibraryModule' and '%(AssetKind)' != 'Publish'" /> - - - - - - - + + + + + + + - - - - @@ -465,13 +473,13 @@ Copyright (c) .NET Foundation. All rights reserved. LoadFullICUData="$(_BlazorWebAssemblyLoadAllGlobalizationData)" CopySymbols="$(CopyOutputSymbolsToPublishDirectory)" ExistingAssets="@(_WasmPublishPrefilteredAssets)" - DotNetJsVersion="$(_WasmRuntimePackVersion)" - FingerprintDotNetJs="$(WasmFingerprintDotnetJs)" EnableThreads="$(_WasmEnableThreads)" EmitSourceMap="$(_WasmEmitSourceMapPublish)" IsWebCilEnabled="$(_WasmEnableWebcil)" + IsFingerprintingEnabled="$(_WasmFingerprintAssets)" > + @@ -494,7 +502,7 @@ Copyright (c) .NET Foundation. All rights reserved. RemoveMetadata="Integrity;Fingerprint" /> - + @@ -627,13 +635,18 @@ Copyright (c) .NET Foundation. All rights reserved. - - - + + + string.Concat(fileName, optionalFingerprint, extension), + ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.worker", ".js") => string.Concat(fileName, requiredFingerprint, extension), + _ => string.Concat(fileName, extension) + }; + return $"_framework/{subPath}{relativePath}"; } public static ITaskItem GetCustomIcuAsset(ITaskItem candidate) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs index e5c10d67a4a30..6250737443387 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs @@ -31,9 +31,6 @@ public class ComputeWasmBuildAssets : Task [Required] public ITaskItem[] ProjectSatelliteAssemblies { get; set; } - [Required] - public string DotNetJsVersion { get; set; } - [Required] public string OutputPath { get; set; } @@ -52,8 +49,6 @@ public class ComputeWasmBuildAssets : Task [Required] public bool CopySymbols { get; set; } - public bool FingerprintDotNetJs { get; set; } - public bool EnableThreads { get; set; } public bool EmitSourceMap { get; set; } @@ -117,44 +112,8 @@ public override bool Execute() continue; } - string candidateFileName = candidate.GetMetadata("FileName"); - if (candidateFileName.StartsWith("dotnet") && candidate.GetMetadata("Extension") == ".js") - { - string newDotnetJSFileName = null; - string newDotNetJSFullPath = null; - if (candidateFileName != "dotnet" || FingerprintDotNetJs) - { - var itemHash = FileHasher.GetFileHash(candidate.ItemSpec); - newDotnetJSFileName = $"{candidateFileName}.{DotNetJsVersion}.{itemHash}.js"; - - var originalFileFullPath = Path.GetFullPath(candidate.ItemSpec); - var originalFileDirectory = Path.GetDirectoryName(originalFileFullPath); - - newDotNetJSFullPath = Path.Combine(originalFileDirectory, newDotnetJSFileName); - } - else - { - newDotNetJSFullPath = candidate.ItemSpec; - newDotnetJSFileName = Path.GetFileName(newDotNetJSFullPath); - } - - var newDotNetJs = new TaskItem(newDotNetJSFullPath, candidate.CloneCustomMetadata()); - newDotNetJs.SetMetadata("OriginalItemSpec", candidate.ItemSpec); - - var newRelativePath = $"_framework/{newDotnetJSFileName}"; - newDotNetJs.SetMetadata("RelativePath", newRelativePath); - - newDotNetJs.SetMetadata("AssetTraitName", "WasmResource"); - newDotNetJs.SetMetadata("AssetTraitValue", "native"); - - assetCandidates.Add(newDotNetJs); - continue; - } - else - { - string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate); - candidate.SetMetadata("RelativePath", relativePath); - } + string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate); + candidate.SetMetadata("RelativePath", relativePath); // Workaround for https://github.com/dotnet/aspnetcore/issues/37574. // For items added as "Reference" in project references, the OriginalItemSpec is incorrect. @@ -264,6 +223,7 @@ private static void ApplyUniqueMetadataProperties(ITaskItem candidate) break; case ".wasm": case ".blat": + case ".js" when filename.StartsWith("dotnet"): case ".dat" when filename.StartsWith("icudt"): case ".json" when filename.StartsWith("segmentation-rules"): candidate.SetMetadata("AssetTraitName", "WasmResource"); diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index 64b7b99c930ae..87e0f30d900d2 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -55,20 +55,20 @@ public class ComputeWasmPublishAssets : Task [Required] public string PublishPath { get; set; } - [Required] - public string DotNetJsVersion { get; set; } - - public bool FingerprintDotNetJs { get; set; } - public bool EnableThreads { get; set; } public bool EmitSourceMap { get; set; } public bool IsWebCilEnabled { get; set; } + public bool IsFingerprintingEnabled { get; set; } + [Output] public ITaskItem[] NewCandidates { get; set; } + [Output] + public ITaskItem[] PromotedAssets { get; set; } + [Output] public ITaskItem[] FilesToRemove { get; set; } @@ -76,6 +76,7 @@ public override bool Execute() { var filesToRemove = new List(); var newAssets = new List(); + var promotedAssets = new List(); try { @@ -109,33 +110,32 @@ public override bool Execute() symbolAssets, compressedRepresentations); - var newStaticWebAssets = ComputeUpdatedAssemblies( + ComputeUpdatedAssemblies( satelliteAssemblyToPublish, filesToRemove, resolvedAssembliesToPublish, assemblyAssets, satelliteAssemblyAssets, - compressedRepresentations); - - newAssets.AddRange(newStaticWebAssets); + compressedRepresentations, + newAssets, + promotedAssets); - var nativeStaticWebAssets = ProcessNativeAssets( + ProcessNativeAssets( nativeAssets, resolvedFilesToPublishToRemove, resolvedNativeAssetToPublish, compressedRepresentations, - filesToRemove); - - newAssets.AddRange(nativeStaticWebAssets); + filesToRemove, + newAssets, + promotedAssets); - var symbolStaticWebAssets = ProcessSymbolAssets( + ProcessSymbolAssets( symbolAssets, compressedRepresentations, resolvedFilesToPublishToRemove, resolvedSymbolsToPublish, - filesToRemove); - - newAssets.AddRange(symbolStaticWebAssets); + filesToRemove, + promotedAssets); foreach (var kvp in resolvedFilesToPublishToRemove) { @@ -151,22 +151,28 @@ public override bool Execute() FilesToRemove = filesToRemove.ToArray(); NewCandidates = newAssets.ToArray(); + PromotedAssets = promotedAssets.ToArray(); return !Log.HasLoggedErrors; } - private List ProcessNativeAssets( + private void ProcessNativeAssets( Dictionary nativeAssets, IDictionary resolvedPublishFilesToRemove, Dictionary resolvedNativeAssetToPublish, Dictionary compressedRepresentations, - List filesToRemove) + List filesToRemove, + List newAssets, + List promotedAssets) { var nativeStaticWebAssets = new List(); // Keep track of the updated assets to determine what compressed assets we can reuse var updateMap = new Dictionary(); + // Keep track of not-fingerprinted asset mapped to fingerprinted. + var mappedFingerprintedAssets = new Dictionary(); + foreach (var kvp in nativeAssets) { var key = kvp.Key; @@ -182,11 +188,14 @@ private List ProcessNativeAssets( { // This is a native asset like timezones.blat or similar that was not filtered and that needs to be updated // to a publish asset. - var newAsset = new TaskItem(asset); - ApplyPublishProperties(newAsset); + ITaskItem newAsset = CreatePromotedAsset(asset); + if (newAsset.ItemSpec != asset.ItemSpec) + mappedFingerprintedAssets[asset.ItemSpec] = newAsset.ItemSpec; + nativeStaticWebAssets.Add(newAsset); filesToRemove.Add(existing); updateMap.Add(asset.ItemSpec, newAsset); + promotedAssets.Add(newAsset); Log.LogMessage(MessageImportance.Low, "Promoting asset '{0}' to Publish asset.", asset.ItemSpec); } else @@ -222,22 +231,26 @@ private List ProcessNativeAssets( newDotNetJs = new TaskItem(Path.GetFullPath(aotDotNetJs.ItemSpec), asset.CloneCustomMetadata()); newDotNetJs.SetMetadata("OriginalItemSpec", aotDotNetJs.ItemSpec); - string relativePath = baseName != "dotnet" || FingerprintDotNetJs - ? $"_framework/{$"{baseName}.{DotNetJsVersion}.{FileHasher.GetFileHash(aotDotNetJs.ItemSpec)}.js"}" - : $"_framework/{baseName}.js"; + ApplyPublishProperties(newDotNetJs); + + string relativePath = $"_framework/{baseName}.js"; newDotNetJs.SetMetadata("RelativePath", relativePath); updateMap.Add(asset.ItemSpec, newDotNetJs); + newAssets.Add(newDotNetJs); Log.LogMessage(MessageImportance.Low, "Replacing asset '{0}' with AoT version '{1}'", asset.ItemSpec, newDotNetJs.ItemSpec); } else { - newDotNetJs = new TaskItem(asset); + newDotNetJs = CreatePromotedAsset(asset); + if (newDotNetJs.ItemSpec != asset.ItemSpec) + mappedFingerprintedAssets[asset.ItemSpec] = newDotNetJs.ItemSpec; + + promotedAssets.Add(newDotNetJs); Log.LogMessage(MessageImportance.Low, "Promoting asset '{0}' to Publish asset.", asset.ItemSpec); } - ApplyPublishProperties(newDotNetJs); nativeStaticWebAssets.Add(newDotNetJs); if (resolvedNativeAssetToPublish.TryGetValue($"{baseName}.js", out var resolved)) { @@ -258,16 +271,22 @@ private List ProcessNativeAssets( { newDotNetWasm = new TaskItem(Path.GetFullPath(aotDotNetWasm.ItemSpec), asset.CloneCustomMetadata()); newDotNetWasm.SetMetadata("OriginalItemSpec", aotDotNetWasm.ItemSpec); + ApplyPublishProperties(newDotNetWasm); + updateMap.Add(asset.ItemSpec, newDotNetWasm); + newAssets.Add(newDotNetWasm); Log.LogMessage(MessageImportance.Low, "Replacing asset '{0}' with AoT version '{1}'", asset.ItemSpec, newDotNetWasm.ItemSpec); } else { - newDotNetWasm = new TaskItem(asset); + newDotNetWasm = CreatePromotedAsset(asset); + if (newDotNetWasm.ItemSpec != asset.ItemSpec) + mappedFingerprintedAssets[asset.ItemSpec] = newDotNetWasm.ItemSpec; + + promotedAssets.Add(newDotNetWasm); Log.LogMessage(MessageImportance.Low, "Promoting asset '{0}' to Publish asset.", asset.ItemSpec); } - ApplyPublishProperties(newDotNetWasm); nativeStaticWebAssets.Add(newDotNetWasm); if (resolvedNativeAssetToPublish.TryGetValue("dotnet.native.wasm", out var resolved)) @@ -285,10 +304,18 @@ private List ProcessNativeAssets( var compressedUpdatedFiles = ProcessCompressedAssets(compressedRepresentations, nativeAssets, updateMap); foreach (var f in compressedUpdatedFiles) { - nativeStaticWebAssets.Add(f); - } + var compressed = f; + if (mappedFingerprintedAssets.TryGetValue(compressed.GetMetadata("RelatedAsset"), out var fingerprintedAsset)) + { + Log.LogMessage(MessageImportance.Low, "Changing related asset for compressed asset '{0}' to '{1}'.", compressed.ItemSpec, fingerprintedAsset); - return nativeStaticWebAssets; + compressed = new TaskItem(compressed); + compressed.SetMetadata("RelatedAsset", fingerprintedAsset); + } + + promotedAssets.Add(compressed); + nativeStaticWebAssets.Add(compressed); + } static bool IsAnyDotNetJs(string key) { @@ -304,12 +331,38 @@ static bool IsDotNetWasm(string key) } } - private List ProcessSymbolAssets( + private ITaskItem CreatePromotedAsset(ITaskItem asset) + { + string newAssetItemSpec = asset.ItemSpec; + string newAssetRelativePath = asset.GetMetadata("RelativePath"); + + if (IsFingerprintingEnabled) + { + string assetDirectory = Path.GetDirectoryName(asset.ItemSpec); + string assetFileNameToFingerprint = Path.GetFileName(newAssetRelativePath); + string fingerprint = asset.GetMetadata("Fingerprint"); + string newAssetFingerprintedFileName = assetFileNameToFingerprint.Replace("#[.{fingerprint}]!", $".{fingerprint}"); + if (newAssetFingerprintedFileName != assetFileNameToFingerprint) + { + newAssetItemSpec = $"{assetDirectory}/{newAssetFingerprintedFileName}"; + newAssetRelativePath = newAssetRelativePath.Replace(assetFileNameToFingerprint, newAssetFingerprintedFileName); + } + } + + var newAsset = new TaskItem(newAssetItemSpec, asset.CloneCustomMetadata()); + newAsset.SetMetadata("RelativePath", newAssetRelativePath); + + ApplyPublishProperties(newAsset); + return newAsset; + } + + private void ProcessSymbolAssets( Dictionary symbolAssets, Dictionary compressedRepresentations, Dictionary resolvedPublishFilesToRemove, Dictionary resolvedSymbolAssetToPublish, - List filesToRemove) + List filesToRemove, + List promotedAssets) { var symbolStaticWebAssets = new List(); var updateMap = new Dictionary(); @@ -329,6 +382,7 @@ private List ProcessSymbolAssets( symbolStaticWebAssets.Add(newAsset); updateMap.Add(newAsset.ItemSpec, newAsset); filesToRemove.Add(existing); + promotedAssets.Add(newAsset); Log.LogMessage(MessageImportance.Low, "Promoting asset '{0}' to Publish asset.", asset.ItemSpec); } else @@ -351,19 +405,20 @@ private List ProcessSymbolAssets( foreach (var file in compressedFiles) { + promotedAssets.Add(file); symbolStaticWebAssets.Add(file); } - - return symbolStaticWebAssets; } - private List ComputeUpdatedAssemblies( + private void ComputeUpdatedAssemblies( IDictionary<(string, string assemblyName), ITaskItem> satelliteAssemblies, List filesToRemove, Dictionary resolvedAssembliesToPublish, Dictionary assemblyAssets, Dictionary satelliteAssemblyAssets, - Dictionary compressedRepresentations) + Dictionary compressedRepresentations, + List newAssets, + List promotedAssets) { // All assemblies, satellite assemblies and gzip files are initially defined as build assets. // We need to update them to publish assets when they haven't changed or when they have been linked. @@ -375,7 +430,7 @@ private List ComputeUpdatedAssemblies( foreach (var kvp in assemblyAssets) { var asset = kvp.Value; - var fileName = Path.GetFileName(asset.GetMetadata("RelativePath")); + var fileName = Path.GetFileName(asset.ItemSpec); if (IsWebCilEnabled) fileName = Path.ChangeExtension(fileName, ".dll"); @@ -389,6 +444,11 @@ private List ComputeUpdatedAssemblies( linkedAssets.Add(asset.ItemSpec, existing); } } + else + { + Log.LogMessage(MessageImportance.Low, "Asset '{0}' is not present in resolved files to publish and will be omitted from publish", + asset.ItemSpec); + } } foreach (var kvp in satelliteAssemblyAssets) @@ -446,6 +506,7 @@ private List ComputeUpdatedAssemblies( } ApplyPublishProperties(newAsemblyAsset); + newAssets.Add(newAsemblyAsset); updatedAssetsMap.Add(asset.ItemSpec, newAsemblyAsset); break; default: @@ -455,12 +516,11 @@ private List ComputeUpdatedAssemblies( UpdateRelatedAssetProperty(asset, dependentAsset, updatedAssetsMap); Log.LogMessage(MessageImportance.Low, "Promoting asset '{0}' to Publish asset.", asset.ItemSpec); + promotedAssets.Add(dependentAsset); updatedAssetsMap.Add(asset.ItemSpec, dependentAsset); break; } } - - return updatedAssetsMap.Values.ToList(); } private List ProcessCompressedAssets( diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 33f3debdd4ef8..6cd143ed305d9 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -34,6 +34,9 @@ public class GenerateWasmBootJson : Task [Required] public ITaskItem[] Resources { get; set; } + [Required] + public ITaskItem[] Endpoints { get; set; } + [Required] public bool DebugBuild { get; set; } @@ -169,6 +172,8 @@ public void WriteBootJson(Stream output, string entryAssemblyName) // - ContentHash (e.g., "3448f339acf512448") if (Resources != null) { + var endpointByAsset = Endpoints.ToDictionary(e => e.GetMetadata("AssetFile")); + var remainingLazyLoadAssemblies = new List(LazyLoadedAssemblies ?? Array.Empty()); var resourceData = result.resources; foreach (var resource in Resources) @@ -181,6 +186,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var assetTraitName = resource.GetMetadata("AssetTraitName"); var assetTraitValue = resource.GetMetadata("AssetTraitValue"); var resourceName = Path.GetFileName(resource.GetMetadata("RelativePath")); + var resourceRoute = Path.GetFileName(endpointByAsset[resource.ItemSpec].ItemSpec); if (TryGetLazyLoadedAssembly(resourceName, out var lazyLoad)) { @@ -195,7 +201,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) resourceData.satelliteResources ??= new Dictionary(StringComparer.OrdinalIgnoreCase); if (!IsTargeting80OrLater()) - resourceName = assetTraitValue + "/" + resourceName; + resourceRoute = assetTraitValue + "/" + resourceRoute; if (!resourceData.satelliteResources.TryGetValue(assetTraitValue, out resourceList)) { @@ -324,13 +330,13 @@ public void WriteBootJson(Stream output, string entryAssemblyName) if (resourceList != null) { - AddResourceToList(resource, resourceList, resourceName); + AddResourceToList(resource, resourceList, resourceRoute); } if (!string.IsNullOrEmpty(behavior)) { resourceData.runtimeAssets ??= new Dictionary(); - AddToAdditionalResources(resource, resourceData.runtimeAssets, resourceName, behavior); + AddToAdditionalResources(resource, resourceData.runtimeAssets, resourceRoute, behavior); } } @@ -406,7 +412,7 @@ void AddResourceToList(ITaskItem resource, ResourceHashesByNameDictionary resour if (!resourceList.ContainsKey(resourceKey)) { Log.LogMessage(MessageImportance.Low, "Added resource '{0}' to the manifest.", resource.ItemSpec); - resourceList.Add(resourceKey, $"sha256-{resource.GetMetadata("FileHash")}"); + resourceList.Add(resourceKey, $"sha256-{resource.GetMetadata("Integrity")}"); } } } From 2c0d21f5c8203bf9fbb227a0cd59792ec06152b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 20 Jun 2024 14:41:24 +0200 Subject: [PATCH 02/55] Make fingerpring work at runtime for assemblies --- src/mono/browser/runtime/loader/assets.ts | 5 +++++ src/mono/browser/runtime/types/index.ts | 1 + .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 6 ++++-- .../BootJsonData.cs | 2 ++ .../GenerateWasmBootJson.cs | 5 ++++- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index 6d4232675d11d..8526228cc61e4 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -318,6 +318,11 @@ export function prepareAssets () { } const addAsset = (asset: AssetEntryInternal, isCore: boolean) => { + if (resources.fingerprinting && asset.behavior == "assembly") { + const indexOfExtension = asset.name.lastIndexOf("."); + const indexOfFingerprint = asset.name.lastIndexOf(".", indexOfExtension - 1); + asset.virtualPath = asset.name.substring(0, indexOfFingerprint) + asset.name.substring(indexOfExtension); + } if (isCore) { asset.isCore = true; coreAssetsToLoad.push(asset); diff --git a/src/mono/browser/runtime/types/index.ts b/src/mono/browser/runtime/types/index.ts index 5e8e8c9d18bb7..730bf353db7fd 100644 --- a/src/mono/browser/runtime/types/index.ts +++ b/src/mono/browser/runtime/types/index.ts @@ -203,6 +203,7 @@ export type ResourceExtensions = { [extensionName: string]: ResourceList }; export interface ResourceGroups { hash?: string; + fingerprinting?: boolean, coreAssembly?: ResourceList; // nullable only temporarily assembly?: ResourceList; // nullable only temporarily lazyAssembly?: ResourceList; // nullable only temporarily diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 784c3f7513cdd..5994919a80a1a 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -376,7 +376,8 @@ Copyright (c) .NET Foundation. All rights reserved. ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" IsPublish="false" IsAot="$(RunAOTCompilation)" - IsMultiThreaded="$(WasmEnableThreads)" /> + IsMultiThreaded="$(WasmEnableThreads)" + IsFingerprintingEnabled="$(_WasmFingerprintAssets)" /> @@ -667,7 +668,8 @@ Copyright (c) .NET Foundation. All rights reserved. ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" IsPublish="true" IsAot="$(RunAOTCompilation)" - IsMultiThreaded="$(WasmEnableThreads)" /> + IsMultiThreaded="$(WasmEnableThreads)" + IsFingerprintingEnabled="$(_WasmFingerprintAssets)" /> diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs index 19c0d1f02e764..376e75dab0855 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -125,6 +125,8 @@ public class ResourcesData /// public string hash { get; set; } + public bool fingerprinting { get; set; } + /// /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. /// diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 6cd143ed305d9..4e7391f4f5d81 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -84,6 +84,8 @@ public class GenerateWasmBootJson : Task public bool IsMultiThreaded { get; set; } + public bool IsFingerprintingEnabled { get; set; } + public override bool Execute() { using var fileStream = File.Create(OutputPath); @@ -176,6 +178,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var remainingLazyLoadAssemblies = new List(LazyLoadedAssemblies ?? Array.Empty()); var resourceData = result.resources; + resourceData.fingerprinting = IsFingerprintingEnabled; foreach (var resource in Resources) { ResourceHashesByNameDictionary resourceList = null; @@ -185,7 +188,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var fileExtension = resource.GetMetadata("Extension"); var assetTraitName = resource.GetMetadata("AssetTraitName"); var assetTraitValue = resource.GetMetadata("AssetTraitValue"); - var resourceName = Path.GetFileName(resource.GetMetadata("RelativePath")); + var resourceName = Path.GetFileName(resource.ItemSpec); var resourceRoute = Path.GetFileName(endpointByAsset[resource.ItemSpec].ItemSpec); if (TryGetLazyLoadedAssembly(resourceName, out var lazyLoad)) From da8f2ece644603f12ab0ab266fcd825dbc73761b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 20 Jun 2024 15:57:42 +0200 Subject: [PATCH 03/55] Make fingerpring work at runtime for icu --- src/mono/browser/runtime/loader/assets.ts | 14 +++++++++++--- src/mono/browser/runtime/loader/icu.ts | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index 8526228cc61e4..7e1ea9215f4c4 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -319,9 +319,7 @@ export function prepareAssets () { const addAsset = (asset: AssetEntryInternal, isCore: boolean) => { if (resources.fingerprinting && asset.behavior == "assembly") { - const indexOfExtension = asset.name.lastIndexOf("."); - const indexOfFingerprint = asset.name.lastIndexOf(".", indexOfExtension - 1); - asset.virtualPath = asset.name.substring(0, indexOfFingerprint) + asset.name.substring(indexOfExtension); + asset.virtualPath = getNonFingerprintedAssetName(asset.name); } if (isCore) { asset.isCore = true; @@ -465,6 +463,16 @@ export function prepareAssets () { config.assets = [...coreAssetsToLoad, ...assetsToLoad, ...modulesAssets]; } +export function getNonFingerprintedAssetName(assetName: string) { + if (loaderHelpers.config.resources?.fingerprinting) { + const indexOfExtension = assetName.lastIndexOf("."); + const indexOfFingerprint = assetName.lastIndexOf(".", indexOfExtension - 1); + return assetName.substring(0, indexOfFingerprint) + assetName.substring(indexOfExtension); + } + + return assetName; +} + export function prepareAssetsWorker () { const config = loaderHelpers.config; mono_assert(config.assets, "config.assets must be defined"); diff --git a/src/mono/browser/runtime/loader/icu.ts b/src/mono/browser/runtime/loader/icu.ts index b9bf54eb31f10..18fa7342da697 100644 --- a/src/mono/browser/runtime/loader/icu.ts +++ b/src/mono/browser/runtime/loader/icu.ts @@ -5,6 +5,7 @@ import { mono_log_error } from "./logging"; import { GlobalizationMode, MonoConfig } from "../types"; import { ENVIRONMENT_IS_WEB, loaderHelpers } from "./globals"; import { mono_log_info, mono_log_debug } from "./logging"; +import { getNonFingerprintedAssetName } from "./assets"; export function init_globalization () { loaderHelpers.preferredIcuAsset = getIcuResourceName(loaderHelpers.config); @@ -50,7 +51,18 @@ export function getIcuResourceName (config: MonoConfig): string | null { // TODO: when starting on sidecar, we should pass default culture from UI thread const culture = config.applicationCulture || (ENVIRONMENT_IS_WEB ? (globalThis.navigator && globalThis.navigator.languages && globalThis.navigator.languages[0]) : Intl.DateTimeFormat().resolvedOptions().locale); - const icuFiles = Object.keys(config.resources.icu); + let icuFiles = Object.keys(config.resources.icu); + const fileMapping: { + [k: string]: string + } = {}; + for (let index = 0; index < icuFiles.length; index++) { + const icuFile = icuFiles[index]; + if (config.resources.fingerprinting) { + fileMapping[getNonFingerprintedAssetName(icuFile)] = icuFile; + } else { + fileMapping[icuFile] = icuFile; + } + } let icuFile = null; if (config.globalizationMode === GlobalizationMode.Custom) { @@ -65,8 +77,8 @@ export function getIcuResourceName (config: MonoConfig): string | null { icuFile = getShardedIcuResourceName(culture); } - if (icuFile && icuFiles.includes(icuFile)) { - return icuFile; + if (icuFile && fileMapping[icuFile]) { + return fileMapping[icuFile]; } } From a92358340d92257b1b06b443b67a460805577660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 20 Jun 2024 22:00:55 +0200 Subject: [PATCH 04/55] Remove version fingerprint check --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 6be096cb67ea5..223773d456b0f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -22,7 +22,7 @@ namespace Wasm.Build.Tests; public abstract class ProjectProviderBase(ITestOutputHelper _testOutput, string? _projectDir) { public static string WasmAssemblyExtension = BuildTestBase.s_buildEnv.UseWebcil ? ".wasm" : ".dll"; - protected const string s_dotnetVersionHashRegex = @"\.(?[0-9]+\.[0-9]+\.[a-zA-Z0-9\.-]+)\.(?[a-zA-Z0-9]+)\."; + protected const string s_dotnetVersionHashRegex = @"\.(?[a-zA-Z0-9]+)\."; private const string s_runtimePackPathPattern = "\\*\\* MicrosoftNetCoreAppRuntimePackDir : '([^ ']*)'"; private static Regex s_runtimePackPathRegex = new Regex(s_runtimePackPathPattern); From 00695e7cee45b9ea2e971f297988df3e75067549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 20 Jun 2024 22:01:12 +0200 Subject: [PATCH 05/55] Check core assembly extension --- src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index 3c8e36199d25e..2d86cf99d37df 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -98,7 +98,7 @@ switch (testCase) { const { setModuleImports, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create(); const config = getConfig(); const exports = await getAssemblyExports(config.mainAssemblyName); -const assemblyExtension = config.resources.coreAssembly['System.Private.CoreLib.wasm'] !== undefined ? ".wasm" : ".dll"; +const assemblyExtension = Object.keys(config.resources.coreAssembly)[0].endsWith('.wasm') ? ".wasm" : ".dll"; // Run the test case try { From de7ab0966492a6f61711b5ba9e21d0cf17e62140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 21 Jun 2024 14:00:26 +0200 Subject: [PATCH 06/55] Typescript nits --- src/mono/browser/runtime/loader/assets.ts | 2 +- src/mono/browser/runtime/loader/icu.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index 7e1ea9215f4c4..82c329463a954 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -463,7 +463,7 @@ export function prepareAssets () { config.assets = [...coreAssetsToLoad, ...assetsToLoad, ...modulesAssets]; } -export function getNonFingerprintedAssetName(assetName: string) { +export function getNonFingerprintedAssetName (assetName: string) { if (loaderHelpers.config.resources?.fingerprinting) { const indexOfExtension = assetName.lastIndexOf("."); const indexOfFingerprint = assetName.lastIndexOf(".", indexOfExtension - 1); diff --git a/src/mono/browser/runtime/loader/icu.ts b/src/mono/browser/runtime/loader/icu.ts index 18fa7342da697..d5ad0dd3b8bbd 100644 --- a/src/mono/browser/runtime/loader/icu.ts +++ b/src/mono/browser/runtime/loader/icu.ts @@ -51,7 +51,7 @@ export function getIcuResourceName (config: MonoConfig): string | null { // TODO: when starting on sidecar, we should pass default culture from UI thread const culture = config.applicationCulture || (ENVIRONMENT_IS_WEB ? (globalThis.navigator && globalThis.navigator.languages && globalThis.navigator.languages[0]) : Intl.DateTimeFormat().resolvedOptions().locale); - let icuFiles = Object.keys(config.resources.icu); + const icuFiles = Object.keys(config.resources.icu); const fileMapping: { [k: string]: string } = {}; From 99d9b6a07a2f36b46c99c304d122286d6bf1d5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 21 Jun 2024 15:27:19 +0200 Subject: [PATCH 07/55] JSModules and SatelliteAssemblies --- ...rosoft.NET.Sdk.WebAssembly.Browser.targets | 37 +++++++++---------- .../ComputeWasmPublishAssets.cs | 13 +++---- .../GenerateWasmBootJson.cs | 2 +- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 680206cb03d5f..23942ce449bed 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -329,13 +329,13 @@ Copyright (c) .NET Foundation. All rights reserved. Condition="'%(StaticWebAsset.AssetTraitName)' == 'JSModule' and '%(StaticWebAsset.AssetTraitValue)' == 'JSLibraryModule' and '%(AssetKind)' != 'Publish'" /> - - - + + @@ -355,7 +355,7 @@ Copyright (c) .NET Foundation. All rights reserved. - - - <_WasmPublishAsset Remove="@(_BlazorExtensionsCandidatesForPublish)" /> - - - + + @@ -649,7 +646,7 @@ Copyright (c) .NET Foundation. All rights reserved. Date: Fri, 21 Jun 2024 15:27:43 +0200 Subject: [PATCH 08/55] DEBUG require newer SDK for testing --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 048346dc91024..7262535085788 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -81,7 +81,7 @@ 0.2.0 - 9.0.100-preview.6.24311.23 + 9.0.100-preview.6.24318.4 9.0.0-beta.24311.10 9.0.0-beta.24311.10 From bfbb51854bb32b7ee041c96bcfa49e8958d81eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 21 Jun 2024 15:32:06 +0200 Subject: [PATCH 09/55] Fix fingerprint for new publish assets --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 23942ce449bed..f5007fbbf15b7 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -506,7 +506,7 @@ Copyright (c) .NET Foundation. All rights reserved. RemoveMetadata="Integrity;Fingerprint" /> - + From 574d8996ab13beab2af8de0b1782f88faee74a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 21 Jun 2024 16:14:34 +0200 Subject: [PATCH 10/55] Lazy loading and FP mapping boot json --- src/mono/browser/runtime/lazyLoading.ts | 10 ++++++++++ src/mono/browser/runtime/loader/assets.ts | 7 +++---- src/mono/browser/runtime/types/index.ts | 2 +- .../BootJsonData.cs | 3 ++- .../GenerateWasmBootJson.cs | 18 +++++++++++++++++- 5 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/mono/browser/runtime/lazyLoading.ts b/src/mono/browser/runtime/lazyLoading.ts index f4da4521010a9..026905730b624 100644 --- a/src/mono/browser/runtime/lazyLoading.ts +++ b/src/mono/browser/runtime/lazyLoading.ts @@ -12,6 +12,16 @@ export async function loadLazyAssembly (assemblyNameToLoad: string): Promise public string hash { get; set; } - public bool fingerprinting { get; set; } + [DataMember(EmitDefaultValue = false)] + public Dictionary fingerprinting { get; set; } /// /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 24dce4df7f1b3..45f862ac43f22 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -178,7 +178,10 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var remainingLazyLoadAssemblies = new List(LazyLoadedAssemblies ?? Array.Empty()); var resourceData = result.resources; - resourceData.fingerprinting = IsFingerprintingEnabled; + + if (IsFingerprintingEnabled) + resourceData.fingerprinting = new(); + foreach (var resource in Resources) { ResourceHashesByNameDictionary resourceList = null; @@ -193,6 +196,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) if (TryGetLazyLoadedAssembly(resourceName, out var lazyLoad)) { + MapFingerprintedAsset(resourceData, resourceRoute, resourceName); Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded assembly.", resource.ItemSpec); remainingLazyLoadAssemblies.Remove(lazyLoad); resourceData.lazyAssembly ??= new ResourceHashesByNameDictionary(); @@ -200,6 +204,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) } else if (string.Equals("Culture", assetTraitName, StringComparison.OrdinalIgnoreCase)) { + MapFingerprintedAsset(resourceData, resourceRoute, resourceName); Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as satellite assembly with culture '{1}'.", resource.ItemSpec, assetTraitValue); resourceData.satelliteResources ??= new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -214,6 +219,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) } else if (string.Equals("symbol", assetTraitValue, StringComparison.OrdinalIgnoreCase)) { + MapFingerprintedAsset(resourceData, resourceRoute, resourceName); if (TryGetLazyLoadedAssembly($"{fileName}.dll", out _) || TryGetLazyLoadedAssembly($"{fileName}{Utils.WebcilInWasmExtension}", out _)) { Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a lazy loaded symbols file.", resource.ItemSpec); @@ -238,6 +244,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) } else if (string.Equals("runtime", assetTraitValue, StringComparison.OrdinalIgnoreCase)) { + MapFingerprintedAsset(resourceData, resourceRoute, resourceName); if (IsTargeting90OrLater() && (IsAot || helper.IsCoreAssembly(resourceName))) { Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as core assembly.", resource.ItemSpec); @@ -252,6 +259,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) else if (string.Equals(assetTraitName, "WasmResource", StringComparison.OrdinalIgnoreCase) && string.Equals(assetTraitValue, "native", StringComparison.OrdinalIgnoreCase)) { + MapFingerprintedAsset(resourceData, resourceRoute, resourceName); Log.LogMessage(MessageImportance.Low, "Candidate '{0}' is defined as a native application resource.", resource.ItemSpec); if (IsTargeting80OrLater()) @@ -420,6 +428,14 @@ void AddResourceToList(ITaskItem resource, ResourceHashesByNameDictionary resour } } + private void MapFingerprintedAsset(ResourcesData resources, string resourceRoute, string resourceName) + { + if (!IsTargeting90OrLater()) + return; + + resources.fingerprinting[resourceRoute] = resourceName; + } + private GlobalizationMode GetGlobalizationMode() { if (string.Equals(InvariantGlobalization, "true", StringComparison.OrdinalIgnoreCase)) From 8848871ad58455cea9069bbc14df642be2375651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 9 Jul 2024 18:27:32 +0200 Subject: [PATCH 11/55] WBT file on disk checks --- src/mono/wasm/Wasm.Build.Tests/Common/DotNetFileName.cs | 1 - src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 8 +------- .../wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/DotNetFileName.cs b/src/mono/wasm/Wasm.Build.Tests/Common/DotNetFileName.cs index 42fd8873e78f5..0c1739d55833d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/DotNetFileName.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/DotNetFileName.cs @@ -8,7 +8,6 @@ namespace Wasm.Build.Tests; public sealed record DotNetFileName ( string ExpectedFilename, - string? Version, string? Hash, string ActualPath ); diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 223773d456b0f..72a931f464027 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -124,8 +124,7 @@ public IReadOnlyDictionary FindAndAssertDotnetFiles( return true; actual[expectedFilename] = new(ExpectedFilename: expectedFilename, - Version: match.Groups[1].Value, - Hash: match.Groups[2].Value, + Hash: match.Groups[1].Value, ActualPath: actualFile); } else @@ -134,7 +133,6 @@ public IReadOnlyDictionary FindAndAssertDotnetFiles( return true; actual[expectedFilename] = new(ExpectedFilename: expectedFilename, - Version: null, Hash: null, ActualPath: actualFile); } @@ -180,15 +178,11 @@ private void AssertDotNetFilesSet( expectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs, expectFingerprintForThisFile: expectFingerprint)) { - if (string.IsNullOrEmpty(actual[expectedFilename].Version)) - throw new XunitException($"Expected version in filename: {actual[expectedFilename].ActualPath}"); if (string.IsNullOrEmpty(actual[expectedFilename].Hash)) throw new XunitException($"Expected hash in filename: {actual[expectedFilename].ActualPath}"); } else { - if (!string.IsNullOrEmpty(actual[expectedFilename].Version)) - throw new XunitException($"Expected no version in filename: {actual[expectedFilename].ActualPath}"); if (!string.IsNullOrEmpty(actual[expectedFilename].Hash)) throw new XunitException($"Expected no hash in filename: {actual[expectedFilename].ActualPath}"); } diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs index 5807120bf8879..19f2d51090662 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs @@ -27,7 +27,7 @@ protected override IReadOnlyDictionary GetAllKnownDotnetFilesToFin { "dotnet.native.js", true }, { "dotnet.native.js.symbols", false }, { "dotnet.globalization.js", true }, - { "dotnet.native.wasm", false }, + { "dotnet.native.wasm", true }, { "dotnet.native.worker.js", true }, { "dotnet.runtime.js", true }, { "dotnet.runtime.js.map", false }, From e40c14ecbf99c007f8df3dc2d70dd710070cc3ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 9 Jul 2024 19:29:22 +0200 Subject: [PATCH 12/55] WBT file on disk checks --- .../Wasm.Build.Tests/ProjectProviderBase.cs | 37 +++++++++++++------ .../GenerateWasmBootJson.cs | 2 +- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 72a931f464027..d14d399f4fba1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Runtime.Serialization.Json; using System.Text; +using System.Text.Json; using System.Text.RegularExpressions; using Microsoft.NET.Sdk.WebAssembly; using Xunit; @@ -45,17 +46,17 @@ public IReadOnlyDictionary AssertBasicBundle(AssertBundl TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.dll" }, - expectToExist: !BuildTestBase.UseWebcil); + expectToExist: false); TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.wasm" }, - expectToExist: BuildTestBase.UseWebcil); + expectToExist: false); - AssertBootJson(assertOptions); + var bootJson = AssertBootJson(assertOptions); // icu if (assertOptions.AssertIcuAssets) { - AssertIcuAssets(assertOptions); + AssertIcuAssets(assertOptions, bootJson); } else { @@ -345,7 +346,7 @@ public static void AssertDotNetJsSymbols(AssertBundleOptionsBase assertOptions) } } - public void AssertIcuAssets(AssertBundleOptionsBase assertOptions) + public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData bootJson) { List expected = new(); switch (assertOptions.GlobalizationMode) @@ -379,6 +380,17 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions) IEnumerable actual = Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "icudt*dat"); if (assertOptions.GlobalizationMode == GlobalizationMode.Hybrid) actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules.json")); + + var expectedFingerprinted = new List(expected.Count); + foreach (var expectedItem in expected) + { + var expectedFingerprintedItem = bootJson.resources.fingerprinting.Where(kv => kv.Value == expectedItem).SingleOrDefault().Key; + if (string.IsNullOrEmpty(expectedFingerprintedItem)) + throw new XunitException($"Could not find ICU asset {expectedItem} in fingerprinting in boot config"); + + expectedFingerprinted.Add(expectedFingerprintedItem); + } + AssertFileNames(expected, actual); if (assertOptions.GlobalizationMode is GlobalizationMode.PredefinedIcu) { @@ -390,7 +402,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions) } } - public void AssertBootJson(AssertBundleOptionsBase options) + public BootJsonData AssertBootJson(AssertBundleOptionsBase options) { EnsureProjectDirIsSet(); // string binFrameworkDir = FindBinFrameworkDir(options.Config, options.IsPublish, options.TargetFramework); @@ -400,13 +412,16 @@ public void AssertBootJson(AssertBundleOptionsBase options) BootJsonData bootJson = ParseBootData(bootJsonPath); string spcExpectedFilename = $"System.Private.CoreLib{WasmAssemblyExtension}"; + + spcExpectedFilename = bootJson.resources.fingerprinting.Where(kv => kv.Value == spcExpectedFilename).SingleOrDefault().Key; + if (string.IsNullOrEmpty(spcExpectedFilename)) + throw new XunitException($"Could not find an assembly System.Private.CoreLib in fingerprinting in {bootJsonPath}"); + string? spcActualFilename = bootJson.resources.coreAssembly.Keys - .Where(a => Path.GetFileNameWithoutExtension(a) == "System.Private.CoreLib") + .Where(a => a == spcExpectedFilename) .SingleOrDefault(); if (spcActualFilename is null) throw new XunitException($"Could not find an assembly named System.Private.CoreLib.* in {bootJsonPath}"); - if (spcExpectedFilename != spcActualFilename) - throw new XunitException($"Expected to find {spcExpectedFilename} but found {spcActualFilename} in {bootJsonPath}"); var bootJsonEntries = bootJson.resources.jsModuleNative.Keys .Union(bootJson.resources.jsModuleRuntime.Keys) @@ -454,10 +469,10 @@ public void AssertBootJson(AssertBundleOptionsBase options) throw new XunitException($"In {bootJsonPath}{Environment.NewLine}" + $" Expected: {string.Join(", ", expectedEntries.Keys.ToArray())}{Environment.NewLine}" + $" Actual : {string.Join(", ", bootJsonEntries)}"); - - } Assert.Collection(bootJsonEntries.Order(), expectedEntries.Values.ToArray()); + + return bootJson; } public static BootJsonData ParseBootData(string bootJsonPath) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 45f862ac43f22..40534bb1c03aa 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -191,7 +191,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var fileExtension = resource.GetMetadata("Extension"); var assetTraitName = resource.GetMetadata("AssetTraitName"); var assetTraitValue = resource.GetMetadata("AssetTraitValue"); - var resourceName = Path.GetFileName(resource.ItemSpec); + var resourceName = Path.GetFileName(resource.GetMetadata("OriginalItemSpec")); var resourceRoute = Path.GetFileName(endpointByAsset[resource.ItemSpec].ItemSpec); if (TryGetLazyLoadedAssembly(resourceName, out var lazyLoad)) From fd8b240c914305e71f845be4542ac47f0818d32d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 9 Jul 2024 19:40:25 +0200 Subject: [PATCH 13/55] WBT file on disk checks --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index d14d399f4fba1..37e8cee33a539 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -391,7 +391,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData expectedFingerprinted.Add(expectedFingerprintedItem); } - AssertFileNames(expected, actual); + AssertFileNames(expectedFingerprinted, actual); if (assertOptions.GlobalizationMode is GlobalizationMode.PredefinedIcu) { string srcPath = assertOptions.PredefinedIcudt!; From d642b3c06656efc4855965ccac74898e72532cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 10 Jul 2024 14:56:01 +0200 Subject: [PATCH 14/55] WBT testmain no fingerprint --- .../Wasm.Build.Tests/ProjectProviderBase.cs | 36 ++++++++++++------- .../WasmSdkBasedProjectProvider.cs | 4 ++- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 37e8cee33a539..e26bf9dec7aed 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -38,18 +38,22 @@ public abstract class ProjectProviderBase(ITestOutputHelper _testOutput, string? protected BuildEnvironment _buildEnv = BuildTestBase.s_buildEnv; public string BundleDirName { get; set; } = "wwwroot"; + public bool IsFingerprintingSupported { get; protected set; } + // Returns the actual files on disk public IReadOnlyDictionary AssertBasicBundle(AssertBundleOptionsBase assertOptions) { EnsureProjectDirIsSet(); var dotnetFiles = FindAndAssertDotnetFiles(assertOptions); + Console.WriteLine($"MF: IsFingerprintingSupported: {IsFingerprintingSupported}, UseWebcil: {BuildTestBase.UseWebcil}"); + TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.dll" }, - expectToExist: false); + expectToExist: IsFingerprintingSupported ? false : !BuildTestBase.UseWebcil); TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.wasm" }, - expectToExist: false); + expectToExist: IsFingerprintingSupported ? false : BuildTestBase.UseWebcil); var bootJson = AssertBootJson(assertOptions); @@ -381,17 +385,22 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData if (assertOptions.GlobalizationMode == GlobalizationMode.Hybrid) actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules.json")); - var expectedFingerprinted = new List(expected.Count); - foreach (var expectedItem in expected) + if (IsFingerprintingSupported) { - var expectedFingerprintedItem = bootJson.resources.fingerprinting.Where(kv => kv.Value == expectedItem).SingleOrDefault().Key; - if (string.IsNullOrEmpty(expectedFingerprintedItem)) - throw new XunitException($"Could not find ICU asset {expectedItem} in fingerprinting in boot config"); + var expectedFingerprinted = new List(expected.Count); + foreach (var expectedItem in expected) + { + var expectedFingerprintedItem = bootJson.resources.fingerprinting.Where(kv => kv.Value == expectedItem).SingleOrDefault().Key; + if (string.IsNullOrEmpty(expectedFingerprintedItem)) + throw new XunitException($"Could not find ICU asset {expectedItem} in fingerprinting in boot config"); - expectedFingerprinted.Add(expectedFingerprintedItem); + expectedFingerprinted.Add(expectedFingerprintedItem); + } + + expected = expectedFingerprinted; } - AssertFileNames(expectedFingerprinted, actual); + AssertFileNames(expected, actual); if (assertOptions.GlobalizationMode is GlobalizationMode.PredefinedIcu) { string srcPath = assertOptions.PredefinedIcudt!; @@ -413,9 +422,12 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) BootJsonData bootJson = ParseBootData(bootJsonPath); string spcExpectedFilename = $"System.Private.CoreLib{WasmAssemblyExtension}"; - spcExpectedFilename = bootJson.resources.fingerprinting.Where(kv => kv.Value == spcExpectedFilename).SingleOrDefault().Key; - if (string.IsNullOrEmpty(spcExpectedFilename)) - throw new XunitException($"Could not find an assembly System.Private.CoreLib in fingerprinting in {bootJsonPath}"); + if (IsFingerprintingSupported) + { + spcExpectedFilename = bootJson.resources.fingerprinting.Where(kv => kv.Value == spcExpectedFilename).SingleOrDefault().Key; + if (string.IsNullOrEmpty(spcExpectedFilename)) + throw new XunitException($"Could not find an assembly System.Private.CoreLib in fingerprinting in {bootJsonPath}"); + } string? spcActualFilename = bootJson.resources.coreAssembly.Keys .Where(a => a == spcExpectedFilename) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs index 19f2d51090662..90dbd03faba51 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmSdkBasedProjectProvider.cs @@ -17,7 +17,9 @@ public class WasmSdkBasedProjectProvider : ProjectProviderBase { public WasmSdkBasedProjectProvider(ITestOutputHelper _testOutput, string? _projectDir = null) : base(_testOutput, _projectDir) - {} + { + IsFingerprintingSupported = true; + } protected override IReadOnlyDictionary GetAllKnownDotnetFilesToFingerprintMap(AssertBundleOptionsBase assertOptions) => new SortedDictionary() From 4d3c657b1ab23f6025563e917eaf2813d3f15dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 10:10:19 +0200 Subject: [PATCH 15/55] WBT revert debug message --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index e26bf9dec7aed..052543ab16f6e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -46,8 +46,6 @@ public IReadOnlyDictionary AssertBasicBundle(AssertBundl EnsureProjectDirIsSet(); var dotnetFiles = FindAndAssertDotnetFiles(assertOptions); - Console.WriteLine($"MF: IsFingerprintingSupported: {IsFingerprintingSupported}, UseWebcil: {BuildTestBase.UseWebcil}"); - TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.dll" }, expectToExist: IsFingerprintingSupported ? false : !BuildTestBase.UseWebcil); From a2eac11387ce0da640aecb0f2fa46a54f7c7a994 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 12:49:27 +0200 Subject: [PATCH 16/55] AOT --- .../ComputeWasmPublishAssets.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index 87a787ccc0f2d..2dd0f154b24cb 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -233,10 +233,6 @@ private void ProcessNativeAssets( ApplyPublishProperties(newDotNetJs); - string relativePath = $"_framework/{baseName}.js"; - - newDotNetJs.SetMetadata("RelativePath", relativePath); - updateMap.Add(asset.ItemSpec, newDotNetJs); newAssets.Add(newDotNetJs); Log.LogMessage(MessageImportance.Low, "Replacing asset '{0}' with AoT version '{1}'", asset.ItemSpec, newDotNetJs.ItemSpec); From 5cbda6748bc0fa7793f1e43fad15fe73fb22a84d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 14:07:08 +0200 Subject: [PATCH 17/55] WBT fix ordering --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 052543ab16f6e..4d8193b603b70 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -433,12 +433,13 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) if (spcActualFilename is null) throw new XunitException($"Could not find an assembly named System.Private.CoreLib.* in {bootJsonPath}"); + // This needs to be in balance with how actual filename returned from GetDotNetFilesExpectedSet are ordered (alphabeticaly). var bootJsonEntries = bootJson.resources.jsModuleNative.Keys + .Union(bootJson.resources.wasmNative.Keys) .Union(bootJson.resources.jsModuleRuntime.Keys) .Union(bootJson.resources.jsModuleWorker?.Keys ?? Enumerable.Empty()) .Union(bootJson.resources.jsModuleGlobalization?.Keys ?? Enumerable.Empty()) .Union(bootJson.resources.wasmSymbols?.Keys ?? Enumerable.Empty()) - .Union(bootJson.resources.wasmNative.Keys) .ToArray(); var expectedEntries = new SortedDictionary>(); @@ -473,14 +474,15 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) }; } // FIXME: maybe use custom code so the details can show up in the log - bootJsonEntries = bootJsonEntries.Order().ToArray(); + bootJsonEntries = bootJsonEntries.ToArray(); if (bootJsonEntries.Length != expectedEntries.Count) { throw new XunitException($"In {bootJsonPath}{Environment.NewLine}" + $" Expected: {string.Join(", ", expectedEntries.Keys.ToArray())}{Environment.NewLine}" + $" Actual : {string.Join(", ", bootJsonEntries)}"); } - Assert.Collection(bootJsonEntries.Order(), expectedEntries.Values.ToArray()); + + Assert.Collection(bootJsonEntries, expectedEntries.Values.ToArray()); return bootJson; } From 71f7fa3a705be39bf3c90704bd59a1cbb62ac491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 14:33:40 +0200 Subject: [PATCH 18/55] Fingerprinting without webcil --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index f5007fbbf15b7..5076ce04ca857 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -261,6 +261,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmFingerprintPatterns Include="WasmFiles" Pattern="*.wasm" Expression="#[.{fingerprint}]!" /> + <_WasmFingerprintPatterns Include="DllFiles" Pattern="*.dll" Expression="#[.{fingerprint}]!" /> <_WasmFingerprintPatterns Include="DatFiles" Pattern="*.dat" Expression="#[.{fingerprint}]!" /> <_WasmFingerprintPatterns Include="Pdb" Pattern="*.pdb" Expression="#[.{fingerprint}]!" /> From f25f7de55e4cc7abc5a355504145e4da9186db7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 15:30:27 +0200 Subject: [PATCH 19/55] Fix GenerateWasmBootJson when FP is off --- .../GenerateWasmBootJson.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 40534bb1c03aa..cb7e97e372867 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -430,7 +430,7 @@ void AddResourceToList(ITaskItem resource, ResourceHashesByNameDictionary resour private void MapFingerprintedAsset(ResourcesData resources, string resourceRoute, string resourceName) { - if (!IsTargeting90OrLater()) + if (IsFingerprintingEnabled && !IsTargeting90OrLater()) return; resources.fingerprinting[resourceRoute] = resourceName; From b2e1ffa96cf1c8500a3c80730ba6223351835a84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 11 Jul 2024 18:23:19 +0200 Subject: [PATCH 20/55] NoFingerprint WBT variant --- src/libraries/sendtohelix-wasm.targets | 1 + src/libraries/sendtohelix.proj | 8 +++-- src/libraries/sendtohelixhelp.proj | 3 +- ...rosoft.NET.Sdk.WebAssembly.Browser.targets | 1 + .../Common/BuildEnvironment.cs | 6 ++++ .../Common/EnvironmentVariables.cs | 1 + .../Wasm.Build.Tests/ProjectProviderBase.cs | 14 +++++---- .../Wasm.Build.Tests/Wasm.Build.Tests.csproj | 3 ++ .../data/RunScriptTemplate.cmd | 5 ++++ .../data/RunScriptTemplate.sh | 6 ++++ .../AssetsComputingHelper.cs | 30 ++++++++++++------- .../ComputeWasmBuildAssets.cs | 4 ++- .../ComputeWasmPublishAssets.cs | 2 +- .../GenerateWasmBootJson.cs | 6 +++- 14 files changed, 68 insertions(+), 22 deletions(-) diff --git a/src/libraries/sendtohelix-wasm.targets b/src/libraries/sendtohelix-wasm.targets index 3fce57cf9c4e1..adb5531ceb954 100644 --- a/src/libraries/sendtohelix-wasm.targets +++ b/src/libraries/sendtohelix-wasm.targets @@ -13,6 +13,7 @@ Workloads- NoWorkload- $(WorkItemPrefix)NoWebcil- + $(WorkItemPrefix)NoFingerprint- $(WorkItemPrefix)ST- $(WorkItemPrefix)MT- diff --git a/src/libraries/sendtohelix.proj b/src/libraries/sendtohelix.proj index 17aa91b1597bb..a6e48f3716b5d 100644 --- a/src/libraries/sendtohelix.proj +++ b/src/libraries/sendtohelix.proj @@ -87,17 +87,21 @@ <_TestUsingWorkloadsValues Include="true;false" /> <_TestUsingWebcilValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> + <_TestUsingFingerprintingValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> <_TestUsingCrossProductValuesTemp Include="@(_TestUsingWorkloadsValues)"> %(_TestUsingWorkloadsValues.Identity) - <_TestUsingCrossProductValues Include="@(_TestUsingCrossProductValuesTemp)"> + <_TestUsingCrossProductValuesTemp2 Include="@(_TestUsingCrossProductValuesTemp)"> %(_TestUsingWebcilValues.Identity) + + <_TestUsingCrossProductValues Include="@(_TestUsingCrossProductValuesTemp2)"> + %(_TestUsingFingerprintingValues.Identity) <_BuildWasmAppsProjectsToBuild Include="$(PerScenarioProjectFile)"> - $(_PropertiesToPass);Scenario=BuildWasmApps;TestArchiveRuntimeFile=$(TestArchiveRuntimeFile);TestUsingWorkloads=%(_TestUsingCrossProductValues.Workloads);TestUsingWebcil=%(_TestUsingCrossProductValues.Webcil) + $(_PropertiesToPass);Scenario=BuildWasmApps;TestArchiveRuntimeFile=$(TestArchiveRuntimeFile);TestUsingWorkloads=%(_TestUsingCrossProductValues.Workloads);TestUsingWebcil=%(_TestUsingCrossProductValues.Webcil);TestUsingFingerprinting=%(_TestUsingCrossProductValues.Fingerprinting) %(_BuildWasmAppsProjectsToBuild.AdditionalProperties);NeedsToBuildWasmAppsOnHelix=$(NeedsToBuildWasmAppsOnHelix) diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 3608f1cae63d0..deb61b4e156a2 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -156,6 +156,7 @@ + @@ -345,7 +346,7 @@ + Text="Scenario: $(Scenario), TestUsingWorkloads: $(TestUsingWorkloads), TestUsingWebcil: $(TestUsingWebcil), TestUsingFingerprinting: $(TestUsingFingerprinting)" /> diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 5076ce04ca857..88df5e9785cd8 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -243,6 +243,7 @@ Copyright (c) .NET Foundation. All rights reserved. OutputPath="$(OutputPath)" EnableThreads="$(_WasmEnableThreads)" EmitSourceMap="$(_WasmEmitSourceMapBuild)" + IsFingerprintingEnabled="$(_WasmFingerprintAssets)" > diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs b/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs index 0ffd223d8e03f..bdda42dd4531e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs @@ -134,6 +134,12 @@ public BuildEnvironment() EnvVars["WasmEnableWebCil"] = "false"; } + if (!EnvironmentVariables.UseFingerprinting) + { + // Default is 'true' + EnvVars["WasmFingerprintAssets"] = "false"; + } + DotNet = Path.Combine(sdkForWorkloadPath!, "dotnet"); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) DotNet += ".exe"; diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs b/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs index e2cf9b3dbf8b4..d928fc1e1b406 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/EnvironmentVariables.cs @@ -22,6 +22,7 @@ internal static class EnvironmentVariables internal static readonly bool IsRunningOnCI = Environment.GetEnvironmentVariable("IS_RUNNING_ON_CI") is "true"; internal static readonly bool ShowBuildOutput = IsRunningOnCI || Environment.GetEnvironmentVariable("SHOW_BUILD_OUTPUT") is not null; internal static readonly bool UseWebcil = Environment.GetEnvironmentVariable("USE_WEBCIL_FOR_TESTS") is "true"; + internal static readonly bool UseFingerprinting = Environment.GetEnvironmentVariable("USE_FINGERPRINTING_FOR_TESTS") is "true"; internal static readonly string? SdkDirName = Environment.GetEnvironmentVariable("SDK_DIR_NAME"); internal static readonly string? WasiSdkPath = Environment.GetEnvironmentVariable("WASI_SDK_PATH"); internal static readonly bool WorkloadsTestPreviousVersions = Environment.GetEnvironmentVariable("WORKLOADS_TEST_PREVIOUS_VERSIONS") is "true"; diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 4d8193b603b70..c80c979fef713 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -40,6 +40,8 @@ public abstract class ProjectProviderBase(ITestOutputHelper _testOutput, string? public bool IsFingerprintingSupported { get; protected set; } + public bool IsFinterprintingEnabled => IsFingerprintingSupported && EnvironmentVariables.UseFingerprinting; + // Returns the actual files on disk public IReadOnlyDictionary AssertBasicBundle(AssertBundleOptionsBase assertOptions) { @@ -48,10 +50,10 @@ public IReadOnlyDictionary AssertBasicBundle(AssertBundl TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.dll" }, - expectToExist: IsFingerprintingSupported ? false : !BuildTestBase.UseWebcil); + expectToExist: IsFinterprintingEnabled ? false : !BuildTestBase.UseWebcil); TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.wasm" }, - expectToExist: IsFingerprintingSupported ? false : BuildTestBase.UseWebcil); + expectToExist: IsFinterprintingEnabled ? false : BuildTestBase.UseWebcil); var bootJson = AssertBootJson(assertOptions); @@ -319,8 +321,8 @@ public static string FindSubDirIgnoringCase(string parentDir, string dirName) return dict; } - public static bool ShouldCheckFingerprint(string expectedFilename, bool expectFingerprintOnDotnetJs, bool expectFingerprintForThisFile) => - (expectedFilename == "dotnet.js" && expectFingerprintOnDotnetJs) || expectFingerprintForThisFile; + public bool ShouldCheckFingerprint(string expectedFilename, bool expectFingerprintOnDotnetJs, bool expectFingerprintForThisFile) + => IsFinterprintingEnabled && ((expectedFilename == "dotnet.js" && expectFingerprintOnDotnetJs) || expectFingerprintForThisFile); public static void AssertRuntimePackPath(string buildOutput, string targetFramework, RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded) @@ -383,7 +385,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData if (assertOptions.GlobalizationMode == GlobalizationMode.Hybrid) actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules.json")); - if (IsFingerprintingSupported) + if (IsFinterprintingEnabled) { var expectedFingerprinted = new List(expected.Count); foreach (var expectedItem in expected) @@ -420,7 +422,7 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) BootJsonData bootJson = ParseBootData(bootJsonPath); string spcExpectedFilename = $"System.Private.CoreLib{WasmAssemblyExtension}"; - if (IsFingerprintingSupported) + if (IsFinterprintingEnabled) { spcExpectedFilename = bootJson.resources.fingerprinting.Where(kv => kv.Value == spcExpectedFilename).SingleOrDefault().Key; if (string.IsNullOrEmpty(spcExpectedFilename)) diff --git a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj index 62601dd54d85b..33aae4ef2b700 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj +++ b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj @@ -112,6 +112,9 @@ + + + diff --git a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd index e088aa4861df4..fc66d9e745a06 100644 --- a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd +++ b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd @@ -56,6 +56,11 @@ if [%TEST_USING_WEBCIL%] == [false] ( ) else ( set USE_WEBCIL_FOR_TESTS=true ) +if [%TEST_USING_FINGERPRINTING%] == [false] ( + set USE_FINGERPRINTING_FOR_TESTS=false +) else ( + set USE_FINGERPRINTING_FOR_TESTS=true +) if [%HELIX_CORRELATION_PAYLOAD%] NEQ [] ( robocopy /mt /np /nfl /NDL /nc /e %BASE_DIR%\%SDK_DIR_NAME% %EXECUTION_DIR%\%SDK_DIR_NAME% diff --git a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh index 2c23e8a4185f6..bab35b29d534a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh +++ b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh @@ -39,6 +39,12 @@ function set_env_vars() export USE_WEBCIL_FOR_TESTS=true fi + if [ "x$TEST_USING_FINGERPRINTING" = "xfalse" ]; then + export USE_FINGERPRINTING_FOR_TESTS=false + else + export USE_FINGERPRINTING_FOR_TESTS=true + fi + local _SDK_DIR= if [[ -n "$HELIX_WORKITEM_UPLOAD_ROOT" ]]; then cp -r $BASE_DIR/$SDK_DIR_NAME $EXECUTION_DIR diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs index 485c9b78c3f57..6abac08e5b560 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs @@ -92,7 +92,7 @@ private static bool IsFromMonoPackage(ITaskItem candidate) return monoPackageIds.Contains(packageId, StringComparer.Ordinal); } - public static string GetCandidateRelativePath(ITaskItem candidate) + public static string GetCandidateRelativePath(ITaskItem candidate, bool isFingerprintingEnabled) { const string optionalFingerprint = "#[.{fingerprint}]?"; const string requiredFingerprint = "#[.{fingerprint}]!"; @@ -109,20 +109,30 @@ public static string GetCandidateRelativePath(ITaskItem candidate) subPath = destinationSubPath.Substring(fileName.Length + extension.Length); } - string relativePath = (fileName, extension) switch { - ("dotnet", ".js") => string.Concat(fileName, optionalFingerprint, extension), - ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), - ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), - ("dotnet.worker", ".js") => string.Concat(fileName, requiredFingerprint, extension), - _ => string.Concat(fileName, extension) - }; + string relativePath; + if (isFingerprintingEnabled) + { + relativePath = (fileName, extension) switch + { + ("dotnet", ".js") => string.Concat(fileName, optionalFingerprint, extension), + ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.worker", ".js") => string.Concat(fileName, requiredFingerprint, extension), + _ => string.Concat(fileName, extension) + }; + } + else + { + relativePath = string.Concat(fileName, extension); + } + return $"_framework/{subPath}{relativePath}"; } - public static ITaskItem GetCustomIcuAsset(ITaskItem candidate) + public static ITaskItem GetCustomIcuAsset(ITaskItem candidate, bool isFingerprintingEnabled) { var customIcuCandidate = new TaskItem(candidate); - var relativePath = GetCandidateRelativePath(customIcuCandidate); + var relativePath = GetCandidateRelativePath(customIcuCandidate, isFingerprintingEnabled); customIcuCandidate.SetMetadata("RelativePath", relativePath); customIcuCandidate.SetMetadata("AssetTraitName", "BlazorWebAssemblyResource"); customIcuCandidate.SetMetadata("AssetTraitValue", "native"); diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs index 6250737443387..3788cc44cd8d3 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs @@ -53,6 +53,8 @@ public class ComputeWasmBuildAssets : Task public bool EmitSourceMap { get; set; } + public bool IsFingerprintingEnabled { get; set; } + [Output] public ITaskItem[] AssetCandidates { get; set; } @@ -112,7 +114,7 @@ public override bool Execute() continue; } - string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate); + string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate, IsFingerprintingEnabled); candidate.SetMetadata("RelativePath", relativePath); // Workaround for https://github.com/dotnet/aspnetcore/issues/37574. diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index 2dd0f154b24cb..521868713886a 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -642,7 +642,7 @@ private void GroupResolvedFilesToPublish( var resolvedFilesToPublish = ResolvedFilesToPublish.ToList(); if (AssetsComputingHelper.TryGetAssetFilename(CustomIcuCandidate, out string customIcuCandidateFilename)) { - var customIcuCandidate = AssetsComputingHelper.GetCustomIcuAsset(CustomIcuCandidate); + var customIcuCandidate = AssetsComputingHelper.GetCustomIcuAsset(CustomIcuCandidate, IsFingerprintingEnabled); resolvedFilesToPublish.Add(customIcuCandidate); } diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index cb7e97e372867..a427cc7f1350e 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -430,9 +430,13 @@ void AddResourceToList(ITaskItem resource, ResourceHashesByNameDictionary resour private void MapFingerprintedAsset(ResourcesData resources, string resourceRoute, string resourceName) { - if (IsFingerprintingEnabled && !IsTargeting90OrLater()) + if (!IsFingerprintingEnabled || !IsTargeting90OrLater()) return; + Console.WriteLine($"MF Should not be reached!"); + if (!IsFingerprintingEnabled) + throw new NotSupportedException("MF Should not be reached!"); + resources.fingerprinting[resourceRoute] = resourceName; } From a411302feb3c436b97db3402ee31204f1275d5e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 12 Jul 2024 10:20:12 +0200 Subject: [PATCH 21/55] DEBUG try to run WBT without fingerprinting --- src/libraries/sendtohelix.proj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/sendtohelix.proj b/src/libraries/sendtohelix.proj index a6e48f3716b5d..66ba7666998ac 100644 --- a/src/libraries/sendtohelix.proj +++ b/src/libraries/sendtohelix.proj @@ -87,7 +87,8 @@ <_TestUsingWorkloadsValues Include="true;false" /> <_TestUsingWebcilValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> - <_TestUsingFingerprintingValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> + + <_TestUsingFingerprintingValues Include="false" Condition="'$(TargetOS)' == 'browser'" /> <_TestUsingCrossProductValuesTemp Include="@(_TestUsingWorkloadsValues)"> From fd55a183086ef2cecf8a4056c97c5c360c5c2d6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 12 Jul 2024 12:04:52 +0200 Subject: [PATCH 22/55] WBT make entry comparison order agnostic --- .../Wasm.Build.Tests/ProjectProviderBase.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index c80c979fef713..31771b580efba 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -435,7 +435,6 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) if (spcActualFilename is null) throw new XunitException($"Could not find an assembly named System.Private.CoreLib.* in {bootJsonPath}"); - // This needs to be in balance with how actual filename returned from GetDotNetFilesExpectedSet are ordered (alphabeticaly). var bootJsonEntries = bootJson.resources.jsModuleNative.Keys .Union(bootJson.resources.wasmNative.Keys) .Union(bootJson.resources.jsModuleRuntime.Keys) @@ -444,7 +443,7 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) .Union(bootJson.resources.wasmSymbols?.Keys ?? Enumerable.Empty()) .ToArray(); - var expectedEntries = new SortedDictionary>(); + var expectedEntries = new SortedDictionary>(); IReadOnlySet expected = GetDotNetFilesExpectedSet(options); var knownSet = GetAllKnownDotnetFilesToFingerprintMap(options); @@ -464,15 +463,12 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs, expectFingerprintForThisFile: expectFingerprint)) { - Assert.Matches($"{prefix}{s_dotnetVersionHashRegex}{extension}", item); + return Regex.Match($"{prefix}{s_dotnetVersionHashRegex}{extension}", item).Success; } else { - Assert.Equal(expectedFilename, item); + return expectedFilename == item; } - - string absolutePath = Path.Combine(binFrameworkDir, item); - Assert.True(File.Exists(absolutePath), $"Expected to find '{absolutePath}'"); }; } // FIXME: maybe use custom code so the details can show up in the log @@ -484,7 +480,15 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) $" Actual : {string.Join(", ", bootJsonEntries)}"); } - Assert.Collection(bootJsonEntries, expectedEntries.Values.ToArray()); + var expectedEntriesToCheck = expectedEntries.Values.ToList(); + foreach (var bootJsonEntry in bootJsonEntries) + { + var matcher = expectedEntriesToCheck.FirstOrDefault(c => c(bootJsonEntry)); + if (matcher == null) + throw new XunitException($"Unexpected entry in boot json '{bootJsonEntry}'. Expected files {String.Join(", ", expectedEntries.Keys)}"); + + expectedEntriesToCheck.Remove(matcher); + } return bootJson; } From 1e88e55cba31e45d2692956e7be3161acea2eb90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 12 Jul 2024 12:43:09 +0200 Subject: [PATCH 23/55] WBT smoke tests for no-fingerprinting --- src/libraries/sendtohelix-browser.targets | 1 + src/libraries/sendtohelix-wasm.targets | 4 ++-- src/libraries/sendtohelix.proj | 3 +-- src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs | 4 ++-- src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs | 2 +- src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs | 2 +- .../Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs | 2 +- .../TestAppScenarios/SatelliteLoadingTests.cs | 2 +- src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj | 1 + 9 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libraries/sendtohelix-browser.targets b/src/libraries/sendtohelix-browser.targets index e1d0d2a5c9324..73498e9e0b2e8 100644 --- a/src/libraries/sendtohelix-browser.targets +++ b/src/libraries/sendtohelix-browser.targets @@ -139,6 +139,7 @@ $(RepositoryEngineeringDir)testing\scenarios\BuildWasmAppsJobsList.txt <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' == 'true'">-notrait category=no-workload <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' != 'true'">-trait category=no-workload + <_XUnitTraitArg Condition="'$(TestUsingFingerprinting)' == 'false'">-trait category=no-fingerprinting diff --git a/src/libraries/sendtohelix-wasm.targets b/src/libraries/sendtohelix-wasm.targets index adb5531ceb954..23fb50e216f09 100644 --- a/src/libraries/sendtohelix-wasm.targets +++ b/src/libraries/sendtohelix-wasm.targets @@ -50,7 +50,7 @@ - + $(_BuildWasmAppsPayloadArchive) set "HELIX_XUNIT_ARGS=-class %(Identity)" export "HELIX_XUNIT_ARGS=-class %(Identity)" @@ -58,7 +58,7 @@ $(_workItemTimeout) - + $(_BuildWasmAppsPayloadArchive) $(HelixCommand) $(_workItemTimeout) diff --git a/src/libraries/sendtohelix.proj b/src/libraries/sendtohelix.proj index 66ba7666998ac..a6e48f3716b5d 100644 --- a/src/libraries/sendtohelix.proj +++ b/src/libraries/sendtohelix.proj @@ -87,8 +87,7 @@ <_TestUsingWorkloadsValues Include="true;false" /> <_TestUsingWebcilValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> - - <_TestUsingFingerprintingValues Include="false" Condition="'$(TargetOS)' == 'browser'" /> + <_TestUsingFingerprintingValues Include="true;false" Condition="'$(TargetOS)' == 'browser'" /> <_TestUsingCrossProductValuesTemp Include="@(_TestUsingWorkloadsValues)"> diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs index 31807b6d54bb7..08c8467a90bcb 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs @@ -43,7 +43,7 @@ public void Wasm_CannotAOT_InDebug(BuildArgs buildArgs, RunHost _, string id) Assert.Contains("AOT is not supported in debug configuration", buildOutput); } - [Theory] + [Theory, TestCategory("no-fingerprinting")] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Release")] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Debug")] public void BuildThenPublishNoAOT(BuildArgs buildArgs, RunHost host, string id) @@ -91,7 +91,7 @@ void Run() => RunAndTestWasmApp( host: host, id: id); } - [Theory] + [Theory, TestCategory("no-fingerprinting")] [BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release")] public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id) { diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index f7c7483a949d3..a6b1fc1a3f138 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -19,7 +19,7 @@ public NativeBuildTests(ITestOutputHelper output, SharedBuildPerTestClassFixture { } - [Theory] + [Theory, TestCategory("no-fingerprinting")] [BuildAndRun] public void SimpleNativeBuild(BuildArgs buildArgs, RunHost host, string id) { diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index 3142bed49a35f..6edaddddbbdfd 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -107,7 +107,7 @@ private void UpdateMainJsEnvironmentVariables(params (string key, string value)[ File.WriteAllText(mainJsPath, mainJsContent); } - [Theory] + [Theory, TestCategory("no-fingerprinting")] [InlineData("Debug")] [InlineData("Release")] public void BrowserBuildThenPublish(string config) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs index 038951e1822e6..020243aa341cb 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -20,7 +20,7 @@ public LazyLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture { } - [Fact] + [Fact, TestCategory("no-fingerprinting")] public async Task LoadLazyAssemblyBeforeItIsNeeded() { CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests", "App"); diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs index 517f34255f996..5e15cc53841ad 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs @@ -23,7 +23,7 @@ public SatelliteLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFi { } - [Fact] + [Fact, TestCategory("no-fingerprinting")] public async Task LoadSatelliteAssembly() { CopyTestAsset("WasmBasicTestApp", "SatelliteLoadingTests", "App"); diff --git a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj index 33aae4ef2b700..cd39a7102485d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj +++ b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj @@ -94,6 +94,7 @@ <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' == 'true'">-notrait category=no-workload <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' != 'true'">-trait category=no-workload + <_XUnitTraitArg Condition="'$(TestUsingFingerprinting)' == 'false'">-trait category=no-fingerprinting From a3fd46a33ba40b7cdcf04e294addd918d35a5afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 12 Jul 2024 17:31:15 +0200 Subject: [PATCH 24/55] Update sendtohelix-browser.targets --- src/libraries/sendtohelix-browser.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/sendtohelix-browser.targets b/src/libraries/sendtohelix-browser.targets index 73498e9e0b2e8..c4b8bcb3217eb 100644 --- a/src/libraries/sendtohelix-browser.targets +++ b/src/libraries/sendtohelix-browser.targets @@ -139,7 +139,7 @@ $(RepositoryEngineeringDir)testing\scenarios\BuildWasmAppsJobsList.txt <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' == 'true'">-notrait category=no-workload <_XUnitTraitArg Condition="'$(TestUsingWorkloads)' != 'true'">-trait category=no-workload - <_XUnitTraitArg Condition="'$(TestUsingFingerprinting)' == 'false'">-trait category=no-fingerprinting + <_XUnitTraitArg Condition="'$(TestUsingFingerprinting)' == 'false'">$(_XUnitTraitArg) -trait category=no-fingerprinting From 5f662b22ee691ba421a9b13a02f2d04e64e91fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 12 Jul 2024 13:58:28 +0200 Subject: [PATCH 25/55] Remove debug log --- .../GenerateWasmBootJson.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index a427cc7f1350e..5945b63f217e4 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -433,10 +433,6 @@ private void MapFingerprintedAsset(ResourcesData resources, string resourceRoute if (!IsFingerprintingEnabled || !IsTargeting90OrLater()) return; - Console.WriteLine($"MF Should not be reached!"); - if (!IsFingerprintingEnabled) - throw new NotSupportedException("MF Should not be reached!"); - resources.fingerprinting[resourceRoute] = resourceName; } From 1cd4de45b82b57ca8a63e49e72d43fa7b4a60865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 11:48:46 +0200 Subject: [PATCH 26/55] Fix typo --- .../wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 31771b580efba..fdb21684678aa 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -40,7 +40,7 @@ public abstract class ProjectProviderBase(ITestOutputHelper _testOutput, string? public bool IsFingerprintingSupported { get; protected set; } - public bool IsFinterprintingEnabled => IsFingerprintingSupported && EnvironmentVariables.UseFingerprinting; + public bool IsFingerprintingEnabled => IsFingerprintingSupported && EnvironmentVariables.UseFingerprinting; // Returns the actual files on disk public IReadOnlyDictionary AssertBasicBundle(AssertBundleOptionsBase assertOptions) @@ -50,10 +50,10 @@ public IReadOnlyDictionary AssertBasicBundle(AssertBundl TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.dll" }, - expectToExist: IsFinterprintingEnabled ? false : !BuildTestBase.UseWebcil); + expectToExist: IsFingerprintingEnabled ? false : !BuildTestBase.UseWebcil); TestUtils.AssertFilesExist(assertOptions.BinFrameworkDir, new[] { "System.Private.CoreLib.wasm" }, - expectToExist: IsFinterprintingEnabled ? false : BuildTestBase.UseWebcil); + expectToExist: IsFingerprintingEnabled ? false : BuildTestBase.UseWebcil); var bootJson = AssertBootJson(assertOptions); @@ -322,7 +322,7 @@ public static string FindSubDirIgnoringCase(string parentDir, string dirName) } public bool ShouldCheckFingerprint(string expectedFilename, bool expectFingerprintOnDotnetJs, bool expectFingerprintForThisFile) - => IsFinterprintingEnabled && ((expectedFilename == "dotnet.js" && expectFingerprintOnDotnetJs) || expectFingerprintForThisFile); + => IsFingerprintingEnabled && ((expectedFilename == "dotnet.js" && expectFingerprintOnDotnetJs) || expectFingerprintForThisFile); public static void AssertRuntimePackPath(string buildOutput, string targetFramework, RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded) @@ -385,7 +385,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData if (assertOptions.GlobalizationMode == GlobalizationMode.Hybrid) actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules.json")); - if (IsFinterprintingEnabled) + if (IsFingerprintingEnabled) { var expectedFingerprinted = new List(expected.Count); foreach (var expectedItem in expected) @@ -422,7 +422,7 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) BootJsonData bootJson = ParseBootData(bootJsonPath); string spcExpectedFilename = $"System.Private.CoreLib{WasmAssemblyExtension}"; - if (IsFinterprintingEnabled) + if (IsFingerprintingEnabled) { spcExpectedFilename = bootJson.resources.fingerprinting.Where(kv => kv.Value == spcExpectedFilename).SingleOrDefault().Key; if (string.IsNullOrEmpty(spcExpectedFilename)) From 754b5f28c54d6692dcf1bdaa072ea3dfc65ee9c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 11:49:29 +0200 Subject: [PATCH 27/55] Fix regex matching --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index fdb21684678aa..3b3a575609e8e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -463,7 +463,7 @@ public BootJsonData AssertBootJson(AssertBundleOptionsBase options) expectFingerprintOnDotnetJs: options.ExpectFingerprintOnDotnetJs, expectFingerprintForThisFile: expectFingerprint)) { - return Regex.Match($"{prefix}{s_dotnetVersionHashRegex}{extension}", item).Success; + return Regex.Match(item, $"{prefix}{s_dotnetVersionHashRegex}{extension}").Success; } else { From 1c1100704451ad8e4704ecd95fa9cb158868056a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 11:53:54 +0200 Subject: [PATCH 28/55] Remove test for dotnet.js FP since we don't support that anymore --- .../Blazor/BuildPublishTests.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 9fe78d3df5072..59a72116d8c72 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -95,24 +95,6 @@ public void DefaultTemplate_AOT_WithWorkload(string config, bool testUnicode) BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.AOT), "-p:RunAOTCompilation=true"); } - [Theory] - [InlineData("Debug", false)] - [InlineData("Release", false)] - [InlineData("Debug", true)] - [InlineData("Release", true)] - public void DefaultTemplate_CheckFingerprinting(string config, bool expectFingerprintOnDotnetJs) - { - string id = $"blz_checkfingerprinting_{config}_{GetRandomId()}"; - - CreateBlazorWasmTemplateProject(id); - - var options = new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true, ExpectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs); - var finterprintingArg = expectFingerprintOnDotnetJs ? "/p:WasmFingerprintDotnetJs=true" : string.Empty; - - BlazorBuild(options, "/p:WasmBuildNative=true", finterprintingArg); - BlazorPublish(options, "/p:WasmBuildNative=true", finterprintingArg); - } - // Disabling for now - publish folder can have more than one dotnet*hash*js, and not sure // how to pick which one to check, for the test //[Theory] From d3a8ba1f7ba589c33c159a1289161ee316ffe24b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 12:48:33 +0200 Subject: [PATCH 29/55] Fix check for System.Private.CoreLib --- .../wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index 6edaddddbbdfd..9c25cb33248f3 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; using Xunit; @@ -598,11 +599,12 @@ internal static void TestWasmStripILAfterAOTOutput(string objBuildDir, string fr Assert.False(Directory.Exists(strippedAssemblyDir), $"Expected {strippedAssemblyDir} to not exist"); string assemblyToExamine = "System.Private.CoreLib.dll"; + string assemblyToExamineWithoutExtension = Path.GetFileNameWithoutExtension(assemblyToExamine); string originalAssembly = Path.Combine(objBuildDir, origAssemblyDir, assemblyToExamine); string strippedAssembly = Path.Combine(objBuildDir, strippedAssemblyDir, assemblyToExamine); - string bundledAssembly = Path.Combine(frameworkDir, Path.ChangeExtension(assemblyToExamine, ProjectProviderBase.WasmAssemblyExtension)); + string? bundledAssembly = Directory.EnumerateFiles(frameworkDir, $"*{ProjectProviderBase.WasmAssemblyExtension}").FirstOrDefault(f => Path.GetFileNameWithoutExtension(f).StartsWith(assemblyToExamineWithoutExtension)); Assert.True(File.Exists(originalAssembly), $"Expected {nameof(originalAssembly)} {originalAssembly} to exist"); - Assert.True(File.Exists(bundledAssembly), $"Expected {nameof(bundledAssembly)} {bundledAssembly} to exist"); + Assert.True(bundledAssembly != null && File.Exists(bundledAssembly), $"Expected {nameof(bundledAssembly)} {bundledAssembly} to exist"); if (expectILStripping) Assert.True(File.Exists(strippedAssembly), $"Expected {nameof(strippedAssembly)} {strippedAssembly} to exist"); else From 653643acb499480f143b10f304e154e8b9823411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 13:03:35 +0200 Subject: [PATCH 30/55] FP for dotnet.globalization.js --- .../AssetsComputingHelper.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs index 6abac08e5b560..38f2c33251d9d 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs @@ -118,6 +118,7 @@ public static string GetCandidateRelativePath(ITaskItem candidate, bool isFinger ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.worker", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.globalization", ".js") => string.Concat(fileName, requiredFingerprint, extension), _ => string.Concat(fileName, extension) }; } From 90de8b7b7e3cac934b95c0992d0d9d8affe56b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 13:32:17 +0200 Subject: [PATCH 31/55] Fingerprinting pdbs --- .../ComputeWasmPublishAssets.cs | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index 521868713886a..f863042a1717d 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -364,6 +364,8 @@ private void ProcessSymbolAssets( var updateMap = new Dictionary(); var existingToRemove = new Dictionary(); + var mappedFingerprintedAssets = new Dictionary(); + foreach (var kvp in symbolAssets) { var asset = kvp.Value; @@ -373,8 +375,10 @@ private void ProcessSymbolAssets( { // This is a symbol asset like classlibrary.pdb or similar that was not filtered and that needs to be updated // to a publish asset. - var newAsset = new TaskItem(asset); - ApplyPublishProperties(newAsset); + var newAsset = CreatePromotedAsset(asset); + if (newAsset.ItemSpec != asset.ItemSpec) + mappedFingerprintedAssets[asset.ItemSpec] = newAsset.ItemSpec; + symbolStaticWebAssets.Add(newAsset); updateMap.Add(newAsset.ItemSpec, newAsset); filesToRemove.Add(existing); @@ -398,11 +402,19 @@ private void ProcessSymbolAssets( } var compressedFiles = ProcessCompressedAssets(compressedRepresentations, symbolAssets, updateMap, existingToRemove); - - foreach (var file in compressedFiles) + foreach (var f in compressedFiles) { - promotedAssets.Add(file); - symbolStaticWebAssets.Add(file); + var compressed = f; + if (mappedFingerprintedAssets.TryGetValue(compressed.GetMetadata("RelatedAsset"), out var fingerprintedAsset)) + { + Log.LogMessage(MessageImportance.Low, "Changing related asset for compressed asset '{0}' to '{1}'.", compressed.ItemSpec, fingerprintedAsset); + + compressed = new TaskItem(compressed); + compressed.SetMetadata("RelatedAsset", fingerprintedAsset); + } + + promotedAssets.Add(compressed); + symbolStaticWebAssets.Add(compressed); } } From 57f1c0f252012e6d12a2ed9503355c678c874e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 Jul 2024 17:28:37 +0200 Subject: [PATCH 32/55] WBT fix file check --- src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 4 ++-- src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs | 6 +++--- .../wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 59a72116d8c72..93d8df8b4315f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -153,8 +153,8 @@ void AssertResourcesDlls(string basePath) { foreach (string culture in cultures) { - string resourceAssemblyPath = Path.Combine(basePath, culture, $"{id}.resources{ProjectProviderBase.WasmAssemblyExtension}"); - Assert.True(File.Exists(resourceAssemblyPath), $"Expects to have a resource assembly at {resourceAssemblyPath}"); + string? resourceAssemblyPath = Directory.EnumerateFiles(Path.Combine(basePath, culture), $"*{ProjectProviderBase.WasmAssemblyExtension}").SingleOrDefault(f => Path.GetFileNameWithoutExtension(f).StartsWith($"{id}.resources")); + Assert.True(resourceAssemblyPath != null && File.Exists(resourceAssemblyPath), $"Expects to have a resource assembly at {resourceAssemblyPath}"); } } } diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs index eeaf368640e92..9cb166c2a11d0 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests3.cs @@ -115,10 +115,10 @@ public void BugRegression_60479_WithRazorClassLib() .ExecuteWithCapturedOutput("new razorclasslib") .EnsureSuccessful(); - string razorClassLibraryFileName = $"RazorClassLibrary{ProjectProviderBase.WasmAssemblyExtension}"; + string razorClassLibraryFileNameWithoutExtension = "RazorClassLibrary"; AddItemsPropertiesToProject(wasmProjectFile, extraItems: @$" - + "); _projectDir = wasmProjectDir; @@ -141,7 +141,7 @@ public void BugRegression_60479_WithRazorClassLib() throw new XunitException($"Could not find resources.lazyAssembly object in {bootJson}"); } - Assert.Contains(razorClassLibraryFileName, lazyVal.EnumerateObject().Select(jp => jp.Name)); + Assert.True(lazyVal.EnumerateObject().Select(jp => jp.Name).FirstOrDefault(f => f.StartsWith(razorClassLibraryFileNameWithoutExtension)) != null); } private void BlazorAddRazorButton(string buttonText, string customCode, string methodName = "test", string razorPage = "Pages/Counter.razor") diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index 9c25cb33248f3..6968b06d2794d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -660,8 +660,8 @@ public void PublishPdb(bool copyOutputSymbolsToPublishDirectory) void AssertFile(string suffix) { - var fileName = $"{id}{suffix}"; - Assert.True(copyOutputSymbolsToPublishDirectory == File.Exists(Path.Combine(publishFrameworkPath, fileName)), $"The {fileName} file {(copyOutputSymbolsToPublishDirectory ? "should" : "shouldn't")} exist in publish folder"); + var fileName = Directory.EnumerateFiles(publishFrameworkPath, $"*{suffix}").FirstOrDefault(f => Path.GetFileNameWithoutExtension(f).StartsWith(id)); + Assert.True(copyOutputSymbolsToPublishDirectory == (fileName != null && File.Exists(fileName)), $"The {fileName} file {(copyOutputSymbolsToPublishDirectory ? "should" : "shouldn't")} exist in publish folder"); } } } From 1f880a480a813213f7a0845ae5a203883d05671c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 17 Jul 2024 13:35:29 +0200 Subject: [PATCH 33/55] Fingerprint segmentation-rules.json --- src/mono/browser/runtime/loader/assets.ts | 2 +- .../AssetsComputingHelper.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index 4565ad0ca5bda..d82723460f3e4 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -421,7 +421,7 @@ export function prepareAssets () { behavior: "icu", loadRemote: true }); - } else if (name === "segmentation-rules.json") { + } else if (name.startsWith("segmentation-rules") && name.endsWith(".json")) { assetsToLoad.push({ name, hash: resources.icu[name], diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs index fcdc003769bc7..843ca6d61ae9b 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs @@ -120,6 +120,7 @@ public static string GetCandidateRelativePath(ITaskItem candidate, bool isFinger ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.worker", ".mjs") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.globalization", ".js") => string.Concat(fileName, requiredFingerprint, extension), + ("segmentation-rules", ".json") => string.Concat(fileName, requiredFingerprint, extension), _ => string.Concat(fileName, extension) }; } From 08e443ac8204041eeadbf8ee7c969b30e2ac8e02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 17 Jul 2024 18:57:50 +0200 Subject: [PATCH 34/55] Fix loading pdb for fingerprinted lazy assembly --- .../browser/runtime/diagnostics-mock.d.ts | 2 +- .../runtime/diagnostics-mock.d.ts.sha256 | 2 +- src/mono/browser/runtime/dotnet.d.ts | 5 ++++- src/mono/browser/runtime/lazyLoading.ts | 20 +++++++++++++++++-- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/mono/browser/runtime/diagnostics-mock.d.ts b/src/mono/browser/runtime/diagnostics-mock.d.ts index 59686e8797399..d1f24c99761d4 100644 --- a/src/mono/browser/runtime/diagnostics-mock.d.ts +++ b/src/mono/browser/runtime/diagnostics-mock.d.ts @@ -71,4 +71,4 @@ interface MockEnvironment { expectAdvertise: FilterPredicate; } -export { MockEnvironment, MockScriptConnection, PromiseAndController }; +export type { MockEnvironment, MockScriptConnection, PromiseAndController }; diff --git a/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 b/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 index 0cfcc26b86906..6821db05ad315 100644 --- a/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 +++ b/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 @@ -1 +1 @@ -6d0ff454946223f77abe8e6c1e377489c33b2914da86120f6b2952b739ebec20 \ No newline at end of file +0619de39d2c9531dee29e6f72c1202aab77e793c48b4b6ac0d42384a3817e40d \ No newline at end of file diff --git a/src/mono/browser/runtime/dotnet.d.ts b/src/mono/browser/runtime/dotnet.d.ts index 94e31ff6a3e88..1357bc4a0b613 100644 --- a/src/mono/browser/runtime/dotnet.d.ts +++ b/src/mono/browser/runtime/dotnet.d.ts @@ -247,6 +247,9 @@ type ResourceExtensions = { }; interface ResourceGroups { hash?: string; + fingerprinting?: { + [name: string]: string; + }; coreAssembly?: ResourceList; assembly?: ResourceList; lazyAssembly?: ResourceList; @@ -692,4 +695,4 @@ declare global { } declare const createDotnetRuntime: CreateDotnetRuntimeType; -export { AssetBehaviors, AssetEntry, CreateDotnetRuntimeType, DotnetHostBuilder, DotnetModuleConfig, EmscriptenModule, GlobalizationMode, IMemoryView, ModuleAPI, MonoConfig, RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; +export { type AssetBehaviors, type AssetEntry, type CreateDotnetRuntimeType, type DotnetHostBuilder, type DotnetModuleConfig, type EmscriptenModule, GlobalizationMode, type IMemoryView, type ModuleAPI, type MonoConfig, type RuntimeAPI, createDotnetRuntime as default, dotnet, exit }; diff --git a/src/mono/browser/runtime/lazyLoading.ts b/src/mono/browser/runtime/lazyLoading.ts index 026905730b624..3d075b3005a8e 100644 --- a/src/mono/browser/runtime/lazyLoading.ts +++ b/src/mono/browser/runtime/lazyLoading.ts @@ -7,6 +7,7 @@ import { AssetEntry } from "./types"; export async function loadLazyAssembly (assemblyNameToLoad: string): Promise { const resources = loaderHelpers.config.resources!; + const originalAssemblyName = assemblyNameToLoad; const lazyAssemblies = resources.lazyAssembly; if (!lazyAssemblies) { throw new Error("No assemblies have been marked as lazy-loadable. Use the 'BlazorWebAssemblyLazyLoad' item group in your project file to enable lazy loading an assembly."); @@ -18,6 +19,7 @@ export async function loadLazyAssembly (assemblyNameToLoad: string): Promise Date: Thu, 18 Jul 2024 09:43:10 +0200 Subject: [PATCH 35/55] Ensure lazy pdb is loaded --- .../Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs index 020243aa341cb..6a167ec2de10a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -24,10 +24,12 @@ public LazyLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture public async Task LoadLazyAssemblyBeforeItIsNeeded() { CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests", "App"); - PublishProject("Debug"); + BuildProject("Debug"); + + var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); - var result = await RunSdkStyleAppForPublish(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); Assert.True(result.TestOutput.Any(m => m.Contains("FirstName")), "The lazy loading test didn't emit expected message with JSON"); + Assert.True(result.ConsoleOutput.Any(m => m.Contains("Attempting to download") && m.Contains("_framework/Json.") && m.Contains(".pdb")), "The lazy loading test didn't load PDB"); } [Fact] From 2b8ccb1ba295f9336724e87c246b9472ecb6d1e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 09:50:02 +0200 Subject: [PATCH 36/55] Remove non-WasmSDK tests from non-FP category --- src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs | 4 ++-- src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs | 2 +- src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs index 08c8467a90bcb..31807b6d54bb7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs @@ -43,7 +43,7 @@ public void Wasm_CannotAOT_InDebug(BuildArgs buildArgs, RunHost _, string id) Assert.Contains("AOT is not supported in debug configuration", buildOutput); } - [Theory, TestCategory("no-fingerprinting")] + [Theory] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Release")] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Debug")] public void BuildThenPublishNoAOT(BuildArgs buildArgs, RunHost host, string id) @@ -91,7 +91,7 @@ void Run() => RunAndTestWasmApp( host: host, id: id); } - [Theory, TestCategory("no-fingerprinting")] + [Theory] [BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release")] public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id) { diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index a6b1fc1a3f138..f7c7483a949d3 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -19,7 +19,7 @@ public NativeBuildTests(ITestOutputHelper output, SharedBuildPerTestClassFixture { } - [Theory, TestCategory("no-fingerprinting")] + [Theory] [BuildAndRun] public void SimpleNativeBuild(BuildArgs buildArgs, RunHost host, string id) { diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index 6968b06d2794d..b32b95debd879 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -295,7 +295,7 @@ void AddTestData(bool forConsole, bool runOutsideProjectDirectory) return data; } - [Theory] + [Theory, TestCategory("no-fingerprinting")] [MemberData(nameof(TestDataForAppBundleDir))] public async Task RunWithDifferentAppBundleLocations(bool forConsole, bool runOutsideProjectDirectory, string extraProperties) => await (forConsole From 51cd688172af69ba84fc182f091017b79dd3d19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 11:15:42 +0200 Subject: [PATCH 37/55] Revert drop for dotnet.js finterprinting --- ...crosoft.NET.Sdk.WebAssembly.Browser.targets | 11 +++++++---- .../Blazor/BuildPublishTests.cs | 18 ++++++++++++++++++ .../AssetsComputingHelper.cs | 10 +++++----- .../ComputeWasmBuildAssets.cs | 6 ++++-- .../ComputeWasmPublishAssets.cs | 6 +++--- .../GenerateWasmBootJson.cs | 6 +++--- 6 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 88df5e9785cd8..7898d0c48923c 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -195,6 +195,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) <_WasmFingerprintAssets>$(WasmFingerprintAssets) <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">true + <_WasmFingerprintDotnetJs>$(WasmFingerprintDotnetJs) + <_WasmFingerprintDotnetJs Condition="'$(_WasmFingerprintDotnetJs)' == ''">false $(OutputPath)$(PublishDirName)\ @@ -243,7 +245,8 @@ Copyright (c) .NET Foundation. All rights reserved. OutputPath="$(OutputPath)" EnableThreads="$(_WasmEnableThreads)" EmitSourceMap="$(_WasmEmitSourceMapBuild)" - IsFingerprintingEnabled="$(_WasmFingerprintAssets)" + FingerprintAssets="$(_WasmFingerprintAssets)" + FingerprintDotnetJs="$(_WasmFingerprintDotnetJs)" > @@ -380,7 +383,7 @@ Copyright (c) .NET Foundation. All rights reserved. IsPublish="false" IsAot="$(RunAOTCompilation)" IsMultiThreaded="$(WasmEnableThreads)" - IsFingerprintingEnabled="$(_WasmFingerprintAssets)" /> + FingerprintAssets="$(_WasmFingerprintAssets)" /> @@ -482,7 +485,7 @@ Copyright (c) .NET Foundation. All rights reserved. EnableThreads="$(_WasmEnableThreads)" EmitSourceMap="$(_WasmEmitSourceMapPublish)" IsWebCilEnabled="$(_WasmEnableWebcil)" - IsFingerprintingEnabled="$(_WasmFingerprintAssets)" + FingerprintAssets="$(_WasmFingerprintAssets)" > @@ -671,7 +674,7 @@ Copyright (c) .NET Foundation. All rights reserved. IsPublish="true" IsAot="$(RunAOTCompilation)" IsMultiThreaded="$(WasmEnableThreads)" - IsFingerprintingEnabled="$(_WasmFingerprintAssets)" /> + FingerprintAssets="$(_WasmFingerprintAssets)" /> diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 93d8df8b4315f..c9612ee0d56a2 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -95,6 +95,24 @@ public void DefaultTemplate_AOT_WithWorkload(string config, bool testUnicode) BlazorPublish(new BlazorBuildOptions(id, config, NativeFilesType.AOT), "-p:RunAOTCompilation=true"); } + [Theory] + [InlineData("Debug", false)] + [InlineData("Release", false)] + [InlineData("Debug", true)] + [InlineData("Release", true)] + public void DefaultTemplate_CheckFingerprinting(string config, bool expectFingerprintOnDotnetJs) + { + string id = $"blz_checkfingerprinting_{config}_{GetRandomId()}"; + + CreateBlazorWasmTemplateProject(id); + + var options = new BlazorBuildOptions(id, config, NativeFilesType.Relinked, ExpectRelinkDirWhenPublishing: true, ExpectFingerprintOnDotnetJs: expectFingerprintOnDotnetJs); + var finterprintingArg = expectFingerprintOnDotnetJs ? "/p:WasmFingerprintDotnetJs=true" : string.Empty; + + BlazorBuild(options, "/p:WasmBuildNative=true", finterprintingArg); + BlazorPublish(options, "/p:WasmBuildNative=true", finterprintingArg); + } + // Disabling for now - publish folder can have more than one dotnet*hash*js, and not sure // how to pick which one to check, for the test //[Theory] diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs index 843ca6d61ae9b..1fb142ac9b2cf 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs @@ -93,7 +93,7 @@ private static bool IsFromMonoPackage(ITaskItem candidate) return monoPackageIds.Contains(packageId, StringComparer.Ordinal); } - public static string GetCandidateRelativePath(ITaskItem candidate, bool isFingerprintingEnabled) + public static string GetCandidateRelativePath(ITaskItem candidate, bool fingerprintAssets, bool fingerprintDotNetJs) { const string optionalFingerprint = "#[.{fingerprint}]?"; const string requiredFingerprint = "#[.{fingerprint}]!"; @@ -111,11 +111,11 @@ public static string GetCandidateRelativePath(ITaskItem candidate, bool isFinger } string relativePath; - if (isFingerprintingEnabled) + if (fingerprintAssets) { relativePath = (fileName, extension) switch { - ("dotnet", ".js") => string.Concat(fileName, optionalFingerprint, extension), + ("dotnet", ".js") => string.Concat(fileName, fingerprintDotNetJs ? requiredFingerprint : optionalFingerprint, extension), ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.worker", ".mjs") => string.Concat(fileName, requiredFingerprint, extension), @@ -132,10 +132,10 @@ public static string GetCandidateRelativePath(ITaskItem candidate, bool isFinger return $"_framework/{subPath}{relativePath}"; } - public static ITaskItem GetCustomIcuAsset(ITaskItem candidate, bool isFingerprintingEnabled) + public static ITaskItem GetCustomIcuAsset(ITaskItem candidate, bool fingerprintAssets) { var customIcuCandidate = new TaskItem(candidate); - var relativePath = GetCandidateRelativePath(customIcuCandidate, isFingerprintingEnabled); + var relativePath = GetCandidateRelativePath(customIcuCandidate, fingerprintAssets, false); customIcuCandidate.SetMetadata("RelativePath", relativePath); customIcuCandidate.SetMetadata("AssetTraitName", "BlazorWebAssemblyResource"); customIcuCandidate.SetMetadata("AssetTraitValue", "native"); diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs index 3788cc44cd8d3..813c862726765 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs @@ -53,7 +53,9 @@ public class ComputeWasmBuildAssets : Task public bool EmitSourceMap { get; set; } - public bool IsFingerprintingEnabled { get; set; } + public bool FingerprintAssets { get; set; } + + public bool FingerprintDotNetJs { get; set; } [Output] public ITaskItem[] AssetCandidates { get; set; } @@ -114,7 +116,7 @@ public override bool Execute() continue; } - string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate, IsFingerprintingEnabled); + string relativePath = AssetsComputingHelper.GetCandidateRelativePath(candidate, FingerprintAssets, FingerprintDotNetJs); candidate.SetMetadata("RelativePath", relativePath); // Workaround for https://github.com/dotnet/aspnetcore/issues/37574. diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs index d7610cac3fecb..3ea146e92e6ed 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmPublishAssets.cs @@ -61,7 +61,7 @@ public class ComputeWasmPublishAssets : Task public bool IsWebCilEnabled { get; set; } - public bool IsFingerprintingEnabled { get; set; } + public bool FingerprintAssets { get; set; } [Output] public ITaskItem[] NewCandidates { get; set; } @@ -334,7 +334,7 @@ private TaskItem CreatePromotedAsset(ITaskItem asset) string newAssetItemSpec = asset.ItemSpec; string newAssetRelativePath = asset.GetMetadata("RelativePath"); - if (IsFingerprintingEnabled) + if (FingerprintAssets) { string assetDirectory = Path.GetDirectoryName(asset.ItemSpec); string assetFileNameToFingerprint = Path.GetFileName(newAssetRelativePath); @@ -656,7 +656,7 @@ private void GroupResolvedFilesToPublish( var resolvedFilesToPublish = ResolvedFilesToPublish.ToList(); if (AssetsComputingHelper.TryGetAssetFilename(CustomIcuCandidate, out string customIcuCandidateFilename)) { - var customIcuCandidate = AssetsComputingHelper.GetCustomIcuAsset(CustomIcuCandidate, IsFingerprintingEnabled); + var customIcuCandidate = AssetsComputingHelper.GetCustomIcuAsset(CustomIcuCandidate, FingerprintAssets); resolvedFilesToPublish.Add(customIcuCandidate); } diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 5945b63f217e4..63cee84d412a8 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -84,7 +84,7 @@ public class GenerateWasmBootJson : Task public bool IsMultiThreaded { get; set; } - public bool IsFingerprintingEnabled { get; set; } + public bool FingerprintAssets { get; set; } public override bool Execute() { @@ -179,7 +179,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) var remainingLazyLoadAssemblies = new List(LazyLoadedAssemblies ?? Array.Empty()); var resourceData = result.resources; - if (IsFingerprintingEnabled) + if (FingerprintAssets) resourceData.fingerprinting = new(); foreach (var resource in Resources) @@ -430,7 +430,7 @@ void AddResourceToList(ITaskItem resource, ResourceHashesByNameDictionary resour private void MapFingerprintedAsset(ResourcesData resources, string resourceRoute, string resourceName) { - if (!IsFingerprintingEnabled || !IsTargeting90OrLater()) + if (!FingerprintAssets || !IsTargeting90OrLater()) return; resources.fingerprinting[resourceRoute] = resourceName; From a531dc82bb7d19dc84c837dbbae397e1d922d52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 12:39:45 +0200 Subject: [PATCH 38/55] Compute non-Fingerprinted virtualPath for pdb and resource as well --- src/mono/browser/runtime/loader/assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/browser/runtime/loader/assets.ts b/src/mono/browser/runtime/loader/assets.ts index d82723460f3e4..27b37da25b8d5 100644 --- a/src/mono/browser/runtime/loader/assets.ts +++ b/src/mono/browser/runtime/loader/assets.ts @@ -318,7 +318,7 @@ export function prepareAssets () { } const addAsset = (asset: AssetEntryInternal, isCore: boolean) => { - if (resources.fingerprinting && asset.behavior == "assembly") { + if (resources.fingerprinting && (asset.behavior == "assembly" || asset.behavior == "pdb" || asset.behavior == "resource")) { asset.virtualPath = getNonFingerprintedAssetName(asset.name); } if (isCore) { From 31d1a73d08b68374b97cbae5abe3b90bda371520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 18:08:21 +0200 Subject: [PATCH 39/55] Make debugger working with fingerprinted assemblies and pdbs --- .../debugger/BrowserDebugProxy/DebugStore.cs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs index dfd0f368561bd..6978a8cfaf8cf 100644 --- a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs @@ -109,6 +109,7 @@ public bool IsMatch(SourceFile sourceFile) return regex.IsMatch(sourceFile.Url.ToString()) || regex.IsMatch(sourceFile.FilePath); } + url = Uri.UnescapeDataString(url); return sourceFile.Url.ToString() == url || sourceFile.DotNetUrlEscaped == url; } @@ -1683,6 +1684,9 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil var asm_files = new List(); List steps = new List(); + // Use System.Private.CoreLib to determine if we have a fingerprinted assemblies or not. + bool isFingerprinted = Path.GetFileNameWithoutExtension(loaded_files.FirstOrDefault(f => f.Contains("System.Private.CoreLib"))) != "System.Private.CoreLib"; + if (!useDebuggerProtocol) { var pdb_files = new List(); @@ -1698,8 +1702,17 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil { try { - string candidate_pdb = Path.ChangeExtension(url, "pdb"); - string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); + string pdb; + if (isFingerprinted) + { + string noFingerprintPdbFileName = string.Concat(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(url)), ".pdb"); + pdb = pdb_files.FirstOrDefault(n => string.Concat(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(n)), Path.GetExtension(n)) == noFingerprintPdbFileName); + } + else + { + string candidate_pdb = Path.ChangeExtension(url, "pdb"); + pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); + } steps.Add( new DebugItem @@ -1722,12 +1735,14 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil continue; try { - string unescapedFileName = Uri.UnescapeDataString(file_name); + string unescapedFileName = Path.GetFileName(Uri.UnescapeDataString(file_name)); + if (isFingerprinted) + unescapedFileName = string.Concat(Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(unescapedFileName)), Path.GetExtension(unescapedFileName)); steps.Add( new DebugItem { Url = file_name, - DataTask = context.SdbAgent.GetDataFromAssemblyAndPdbAsync(Path.GetFileName(unescapedFileName), false, token) + DataTask = context.SdbAgent.GetDataFromAssemblyAndPdbAsync(unescapedFileName, false, token) }); } catch (Exception e) From dc91e2014a571ff995831212031844214b02d7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 18:12:13 +0200 Subject: [PATCH 40/55] DEBUG latest SDK for WBT --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 526206c9b3c20..1ab9fa15292d1 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -81,7 +81,7 @@ 0.2.0 - 9.0.100-preview.7.24358.3 + 9.0.100-preview.7.24368.3 9.0.0-beta.24360.4 9.0.0-beta.24360.4 From c0d3d625c1a2246bb335f6d70dc2154ae0dcce71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 20:33:20 +0200 Subject: [PATCH 41/55] DEBUG fix wbt installation --- src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs index 4b4486cdf4696..4a5aeef403286 100644 --- a/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs +++ b/src/tasks/WorkloadBuildTasks/InstallWorkloadFromArtifacts.cs @@ -287,6 +287,10 @@ private bool InstallWorkloadManifest(ITaskItem workloadId, string name, string v } string outputDir = FindSubDirIgnoringCase(manifestVersionBandDir, name); + string[] outputSubEntries = Directory.GetFileSystemEntries(outputDir); + if (outputSubEntries.Length == 1) + outputDir = outputSubEntries[0]; + var bandVersion = VersionBandForManifestPackages; // regex matching the version band, e.g. 6.0.100-preview.3.21202.5 => 6.0.100-preview.3 string packagePreleaseVersion = bandVersionRegex().Match(version).Groups[1].Value; From 907ce2c3187853f81725685fefe90757846d1742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 18 Jul 2024 20:33:36 +0200 Subject: [PATCH 42/55] Add WorkloadBuildTasks to WasmBuild.sln --- src/mono/wasm/sln/WasmBuild.sln | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/mono/wasm/sln/WasmBuild.sln b/src/mono/wasm/sln/WasmBuild.sln index b84f2d7ba8c84..48bbfe555ab42 100755 --- a/src/mono/wasm/sln/WasmBuild.sln +++ b/src/mono/wasm/sln/WasmBuild.sln @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wasi.Build.Tests", "..\..\w EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WasmTestRunner", "..\..\..\libraries\Common\tests\WasmTestRunner\WasmTestRunner.csproj", "{2BBE4AA8-5424-44AB-933C-66554B688872}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkloadBuildTasks", "..\..\..\tasks\WorkloadBuildTasks\WorkloadBuildTasks.csproj", "{680C730D-C257-4F65-9CD9-6B9A161844B0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -87,6 +89,10 @@ Global {2BBE4AA8-5424-44AB-933C-66554B688872}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BBE4AA8-5424-44AB-933C-66554B688872}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BBE4AA8-5424-44AB-933C-66554B688872}.Release|Any CPU.Build.0 = Release|Any CPU + {680C730D-C257-4F65-9CD9-6B9A161844B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {680C730D-C257-4F65-9CD9-6B9A161844B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {680C730D-C257-4F65-9CD9-6B9A161844B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {680C730D-C257-4F65-9CD9-6B9A161844B0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From e367713f35c361c9d2e9d74882a4badb949504ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jul 2024 07:30:00 +0200 Subject: [PATCH 43/55] Fix WBT --- src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs | 4 ++-- .../Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs index 3b3a575609e8e..69b6d07ff2d6c 100644 --- a/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/ProjectProviderBase.cs @@ -369,7 +369,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData throw new ArgumentException("WasmBuildTest is invalid, value for predefinedIcudt is required when GlobalizationMode=PredefinedIcu."); // predefined ICU name can be identical with the icu files from runtime pack - expected.Add(assertOptions.PredefinedIcudt); + expected.Add(Path.GetFileName(assertOptions.PredefinedIcudt)); break; case GlobalizationMode.Sharded: // icu shard chosen based on the locale @@ -383,7 +383,7 @@ public void AssertIcuAssets(AssertBundleOptionsBase assertOptions, BootJsonData IEnumerable actual = Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "icudt*dat"); if (assertOptions.GlobalizationMode == GlobalizationMode.Hybrid) - actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules.json")); + actual = actual.Union(Directory.EnumerateFiles(assertOptions.BinFrameworkDir, "segmentation-rules*json")); if (IsFingerprintingEnabled) { diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs index 6a167ec2de10a..d06b8499bf106 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -24,7 +24,7 @@ public LazyLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture public async Task LoadLazyAssemblyBeforeItIsNeeded() { CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests", "App"); - BuildProject("Debug"); + BuildProject("Debug", extraArgs: $"-p:WasmDebugLevel=1"); var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); From b78497f19e9970020902963d39f50983b0903ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jul 2024 08:42:34 +0200 Subject: [PATCH 44/55] Revert escaping URL in debugger --- src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs index 6978a8cfaf8cf..c535f47fc7d61 100644 --- a/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/browser/debugger/BrowserDebugProxy/DebugStore.cs @@ -109,7 +109,6 @@ public bool IsMatch(SourceFile sourceFile) return regex.IsMatch(sourceFile.Url.ToString()) || regex.IsMatch(sourceFile.FilePath); } - url = Uri.UnescapeDataString(url); return sourceFile.Url.ToString() == url || sourceFile.DotNetUrlEscaped == url; } From 768af4373e4646332759d7f98fd7f5efc4a2ba4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jul 2024 17:43:53 +0200 Subject: [PATCH 45/55] Fix lazy loading test and message emit in release config --- .../wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs | 2 +- src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs index d06b8499bf106..6a167ec2de10a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -24,7 +24,7 @@ public LazyLoadingTests(ITestOutputHelper output, SharedBuildPerTestClassFixture public async Task LoadLazyAssemblyBeforeItIsNeeded() { CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests", "App"); - BuildProject("Debug", extraArgs: $"-p:WasmDebugLevel=1"); + BuildProject("Debug"); var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index f9c38e2f6dcbc..85fd83270b273 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -31,6 +31,9 @@ switch (testCase) { case "AppSettingsTest": dotnet.withApplicationEnvironment(params.get("applicationEnvironment")); break; + case "LazyLoadingTest": + dotnet.withDiagnosticTracing(true); + break; case "DownloadResourceProgressTest": if (params.get("failAssemblyDownload") === "true") { let assemblyCounter = 0; From 0e705fa7fdd7b27e63d796472169fdf0efa5fa34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jul 2024 18:52:14 +0200 Subject: [PATCH 46/55] Fixes for MT after merge --- .../AssetsComputingHelper.cs | 2 +- .../ComputeWasmBuildAssets.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs index 1fb142ac9b2cf..6885bf62343c7 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/AssetsComputingHelper.cs @@ -118,7 +118,7 @@ public static string GetCandidateRelativePath(ITaskItem candidate, bool fingerpr ("dotnet", ".js") => string.Concat(fileName, fingerprintDotNetJs ? requiredFingerprint : optionalFingerprint, extension), ("dotnet.runtime", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.native", ".js") => string.Concat(fileName, requiredFingerprint, extension), - ("dotnet.worker", ".mjs") => string.Concat(fileName, requiredFingerprint, extension), + ("dotnet.native.worker", ".mjs") => string.Concat(fileName, requiredFingerprint, extension), ("dotnet.globalization", ".js") => string.Concat(fileName, requiredFingerprint, extension), ("segmentation-rules", ".json") => string.Concat(fileName, requiredFingerprint, extension), _ => string.Concat(fileName, extension) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs index 813c862726765..e8daa16e60813 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/ComputeWasmBuildAssets.cs @@ -228,6 +228,7 @@ private static void ApplyUniqueMetadataProperties(ITaskItem candidate) case ".wasm": case ".blat": case ".js" when filename.StartsWith("dotnet"): + case ".mjs" when filename.StartsWith("dotnet"): case ".dat" when filename.StartsWith("icudt"): case ".json" when filename.StartsWith("segmentation-rules"): candidate.SetMetadata("AssetTraitName", "WasmResource"); From 5db6c0e11de4f9347e9f4b91bc9ed83c0b7cb6af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jul 2024 22:32:20 +0200 Subject: [PATCH 47/55] Skip WBT without workloads and without fingerprinting --- src/libraries/sendtohelix.proj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libraries/sendtohelix.proj b/src/libraries/sendtohelix.proj index a6e48f3716b5d..999d8ed9d61c7 100644 --- a/src/libraries/sendtohelix.proj +++ b/src/libraries/sendtohelix.proj @@ -100,6 +100,9 @@ %(_TestUsingFingerprintingValues.Identity) + + <_TestUsingCrossProductValues Remove="@(_TestUsingCrossProductValues)" Condition="'%(_TestUsingCrossProductValues.Workloads)' == 'false' and '%(_TestUsingCrossProductValues.Fingerprinting)' == 'false'" /> + <_BuildWasmAppsProjectsToBuild Include="$(PerScenarioProjectFile)"> $(_PropertiesToPass);Scenario=BuildWasmApps;TestArchiveRuntimeFile=$(TestArchiveRuntimeFile);TestUsingWorkloads=%(_TestUsingCrossProductValues.Workloads);TestUsingWebcil=%(_TestUsingCrossProductValues.Webcil);TestUsingFingerprinting=%(_TestUsingCrossProductValues.Fingerprinting) %(_BuildWasmAppsProjectsToBuild.AdditionalProperties);NeedsToBuildWasmAppsOnHelix=$(NeedsToBuildWasmAppsOnHelix) From 46cb7b3e259512b3834ed388527882d71022b3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 22 Jul 2024 13:49:11 +0200 Subject: [PATCH 48/55] Turn off fingerprinting when targeting downlevel versions --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 7898d0c48923c..85a498e0c2a93 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -177,6 +177,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_TargetingNET80OrLater>false <_TargetingNET80OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '8.0'))">true + <_TargetingNET90OrLater Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals('$(TargetFrameworkVersion)', '9.0'))">true <_BlazorEnableTimeZoneSupport>$(BlazorEnableTimeZoneSupport) <_BlazorEnableTimeZoneSupport Condition="'$(_BlazorEnableTimeZoneSupport)' == ''">true @@ -194,7 +195,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) <_WasmFingerprintAssets>$(WasmFingerprintAssets) - <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">true + <_WasmFingerprintAssets Condition="'$(_TargetingNET90OrLater)' == 'true'">true + <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">false <_WasmFingerprintDotnetJs>$(WasmFingerprintDotnetJs) <_WasmFingerprintDotnetJs Condition="'$(_WasmFingerprintDotnetJs)' == ''">false From c8a645c13c95f02f171cc79422458b53587fbf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 22 Jul 2024 13:52:19 +0200 Subject: [PATCH 49/55] Git ignore *.d.ts.sha256 --- src/mono/browser/.gitignore | 2 +- src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 diff --git a/src/mono/browser/.gitignore b/src/mono/browser/.gitignore index 6177029d9f9e1..a7c533cfd01b3 100644 --- a/src/mono/browser/.gitignore +++ b/src/mono/browser/.gitignore @@ -2,4 +2,4 @@ .stamp-wasm-install-and-select* emsdk -runtime/dotnet.d.ts.sha256 +runtime/*.d.ts.sha256 diff --git a/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 b/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 deleted file mode 100644 index 6821db05ad315..0000000000000 --- a/src/mono/browser/runtime/diagnostics-mock.d.ts.sha256 +++ /dev/null @@ -1 +0,0 @@ -0619de39d2c9531dee29e6f72c1202aab77e793c48b4b6ac0d42384a3817e40d \ No newline at end of file From d0762905d56231e2922c8225df271cf9e51c709a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 22 Jul 2024 19:35:43 +0200 Subject: [PATCH 50/55] Fix --- .../build/Microsoft.NET.Sdk.WebAssembly.Browser.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 85a498e0c2a93..22ebca926a5ce 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -195,7 +195,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) <_WasmFingerprintAssets>$(WasmFingerprintAssets) - <_WasmFingerprintAssets Condition="'$(_TargetingNET90OrLater)' == 'true'">true + <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == '' and '$(_TargetingNET90OrLater)' == 'true'">true <_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">false <_WasmFingerprintDotnetJs>$(WasmFingerprintDotnetJs) <_WasmFingerprintDotnetJs Condition="'$(_WasmFingerprintDotnetJs)' == ''">false From bef50ee7016c84c26bf6bd5c26671282509ca6f3 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 22 Jul 2024 17:32:38 -0500 Subject: [PATCH 51/55] Update source-build-reference-packages to latest --- eng/Version.Details.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index e188a4fe12a6a..eabfc303ce2b4 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -79,9 +79,9 @@ - + https://github.com/dotnet/source-build-reference-packages - 9ae78a4e6412926d19ba97cfed159bf9de70b538 + 97ffbaec397634584a11218e5a29e82601764226 From 05a3854f4457575f88650b57640ba4f5bf6ab3a5 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 22 Jul 2024 19:38:45 -0500 Subject: [PATCH 52/55] Revert "Update source-build-reference-packages to latest" This reverts commit bef50ee7016c84c26bf6bd5c26671282509ca6f3. --- eng/Version.Details.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index eabfc303ce2b4..e188a4fe12a6a 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -79,9 +79,9 @@ - + https://github.com/dotnet/source-build-reference-packages - 97ffbaec397634584a11218e5a29e82601764226 + 9ae78a4e6412926d19ba97cfed159bf9de70b538 From f673b26a2b8e0f705aa3286eef5fd02a43e51450 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 22 Jul 2024 20:03:03 -0500 Subject: [PATCH 53/55] Fix the references --- eng/Version.Details.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index e188a4fe12a6a..fcd3110079b30 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -386,14 +386,14 @@ cada394f99c521861c39e2a5334678e6aba1ac62 - + https://github.com/dotnet/sdk - 5e03abbcf74bdef38ca67f04fbd4982e333d1f58 + 29904b25a99c8984bacb86473df7d98735fb3207 - + https://github.com/dotnet/sdk - 5e03abbcf74bdef38ca67f04fbd4982e333d1f58 + 29904b25a99c8984bacb86473df7d98735fb3207 From ac0a52d9e8e63dfb4830eb58955527ee50b7caef Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 22 Jul 2024 21:11:20 -0500 Subject: [PATCH 54/55] Update Versions.props --- eng/Versions.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 94fff6a1a017f..11e7ff4562841 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,4 +1,4 @@ - +api 9.0.0 @@ -81,7 +81,7 @@ 0.2.0 - 9.0.100-preview.7.24368.3 + 9.0.100-preview.7.24371.4 9.0.0-beta.24360.4 9.0.0-beta.24360.4 From 5d8917a557803c07a3b90877cdbf95f78b3cce02 Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Mon, 22 Jul 2024 21:20:29 -0500 Subject: [PATCH 55/55] Update Versions.props --- eng/Versions.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index 11e7ff4562841..7b0584c7400e8 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -1,4 +1,4 @@ -api + 9.0.0