From 3ab43ea774d583691d5b13f015ece9c27bd059d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 15:01:35 +0200 Subject: [PATCH 01/77] WIP --- src/tasks/WasmAppBuilder/BootJsonData.cs | 159 ++++++++++++++++++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 181 +++++---------------- 2 files changed, 198 insertions(+), 142 deletions(-) create mode 100644 src/tasks/WasmAppBuilder/BootJsonData.cs diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs new file mode 100644 index 00000000000000..9cf04a70dc8233 --- /dev/null +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -0,0 +1,159 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; +using System.Runtime.Serialization; +using ResourceHashesByNameDictionary = System.Collections.Generic.Dictionary; + +namespace Microsoft.NET.Sdk.WebAssembly; + +/// +/// Defines the structure of a Blazor boot JSON file +/// +public class BootJsonData +{ + /// + /// Gets the name of the assembly with the application entry point + /// + public string entryAssembly { get; set; } + + /// + /// Gets the set of resources needed to boot the application. This includes the transitive + /// closure of .NET assemblies (including the entrypoint assembly), the dotnet.wasm file, + /// and any PDBs to be loaded. + /// + /// Within , dictionary keys are resource names, + /// and values are SHA-256 hashes formatted in prefixed base-64 style (e.g., 'sha256-abcdefg...') + /// as used for subresource integrity checking. + /// + public ResourcesData resources { get; set; } = new ResourcesData(); + + /// + /// Gets a value that determines whether to enable caching of the + /// inside a CacheStorage instance within the browser. + /// + public bool cacheBootResources { get; set; } + + /// + /// Gets a value that determines if this is a debug build. + /// + public bool debugBuild { get; set; } + + /// + /// Gets a value that determines if the linker is enabled. + /// + public bool linkerEnabled { get; set; } + + /// + /// Config files for the application + /// + public List config { get; set; } + + /// + /// Gets or sets the that determines how icu files are loaded. + /// + public ICUDataMode icuDataMode { get; set; } + + /// + /// Gets or sets a value that determines if the caching startup memory is enabled. + /// + public bool? startupMemoryCache { get; set; } + + /// + /// Gets a value for mono runtime options. + /// + public string[] runtimeOptions { get; set; } + + /// + /// Gets or sets configuration extensions. + /// + public Dictionary> extensions { get; set; } +} + +public class ResourcesData +{ + /// + /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. + /// + public ResourceHashesByNameDictionary runtime { get; set; } = new ResourceHashesByNameDictionary(); + + /// + /// "assembly" (.dll) resources + /// + public ResourceHashesByNameDictionary assembly { get; set; } = new ResourceHashesByNameDictionary(); + + /// + /// "debug" (.pdb) resources + /// + [DataMember(EmitDefaultValue = false)] + public ResourceHashesByNameDictionary pdb { get; set; } + + /// + /// localization (.satellite resx) resources + /// + [DataMember(EmitDefaultValue = false)] + public Dictionary satelliteResources { get; set; } + + /// + /// Assembly (.dll) resources that are loaded lazily during runtime + /// + [DataMember(EmitDefaultValue = false)] + public ResourceHashesByNameDictionary lazyAssembly { get; set; } + + /// + /// JavaScript module initializers that Blazor will be in charge of loading. + /// + [DataMember(EmitDefaultValue = false)] + public ResourceHashesByNameDictionary libraryInitializers { get; set; } + + /// + /// Extensions created by users customizing the initialization process. The format of the file(s) + /// is up to the user. + /// + [DataMember(EmitDefaultValue = false)] + public Dictionary extensions { get; set; } + + /// + /// Additional assets that the runtime consumes as part of the boot process. + /// + [DataMember(EmitDefaultValue = false)] + public Dictionary runtimeAssets { get; set; } + +} + +public enum ICUDataMode : int +{ + // Note that the numeric values are serialized and used in JS code, so don't change them without also updating the JS code + + /// + /// Load optimized icu data file based on the user's locale + /// + Sharded = 0, + + /// + /// Use the combined icudt.dat file + /// + All = 1, + + /// + /// Do not load any icu data files. + /// + Invariant = 2, + + /// + /// Load custom icu file provided by the developer. + /// + Custom = 3, + + Hybrid = 4 +} + +[DataContract] +public class AdditionalAsset +{ + [DataMember(Name = "hash")] + public string Hash { get; set; } + + [DataMember(Name = "behavior")] + public string Behavior { get; set; } +} diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index fca7a68ac69437..d291e4df1d5be7 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System; @@ -13,6 +13,7 @@ using System.Text.Json.Serialization; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; +using Microsoft.NET.Sdk.WebAssembly; namespace Microsoft.WebAssembly.Build.Tasks; @@ -37,107 +38,6 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask // public ITaskItem[]? ExtraConfig { get; set; } - private sealed class WasmAppConfig - { - [JsonPropertyName("mainAssemblyName")] - public string? MainAssemblyName { get; set; } - [JsonPropertyName("assemblyRootFolder")] - public string AssemblyRootFolder { get; set; } = "managed"; - [JsonPropertyName("debugLevel")] - public int DebugLevel { get; set; } = 0; - [JsonPropertyName("assets")] - public List Assets { get; } = new List(); - [JsonPropertyName("remoteSources")] - public List RemoteSources { get; set; } = new List(); - [JsonPropertyName("globalizationMode")] - public string? GlobalizationMode { get; set; } - [JsonExtensionData] - public Dictionary Extra { get; set; } = new(); - [JsonPropertyName("assetsHash")] - public string AssetsHash { get; set; } = "none"; - } - - private class AssetEntry - { - protected AssetEntry(string name, string hash, string behavior) - { - Name = name; - Behavior = behavior; - Hash = hash; - } - [JsonPropertyName("behavior")] - public string Behavior { get; init; } - [JsonPropertyName("name")] - public string Name { get; init; } - [JsonPropertyName("hash")] - public string? Hash { get; set; } - } - - private sealed class WasmEntry : AssetEntry - { - public WasmEntry(string name, string hash) : base(name, hash, "dotnetwasm") { } - } - - private sealed class LoaderJsEntry : AssetEntry - { - public LoaderJsEntry(string name, string hash) : base(name, hash, "js-module-dotnet") { } - } - - private sealed class NativeJsEntry : AssetEntry - { - public NativeJsEntry(string name, string hash) : base(name, hash, "js-module-native") { } - } - - private sealed class RuntimeJsEntry : AssetEntry - { - public RuntimeJsEntry(string name, string hash) : base(name, hash, "js-module-runtime") { } - } - - private sealed class ThreadsWorkerEntry : AssetEntry - { - public ThreadsWorkerEntry(string name, string hash) : base(name, hash, "js-module-threads") { } - } - - private sealed class AssemblyEntry : AssetEntry - { - public AssemblyEntry(string name, string hash) : base(name, hash, "assembly") { } - } - - private sealed class PdbEntry : AssetEntry - { - public PdbEntry(string name, string hash) : base(name, hash, "pdb") { } - } - - private sealed class SatelliteAssemblyEntry : AssetEntry - { - public SatelliteAssemblyEntry(string name, string hash, string culture) : base(name, hash, "resource") - { - CultureName = culture; - } - - [JsonPropertyName("culture")] - public string CultureName { get; set; } - } - - private sealed class VfsEntry : AssetEntry - { - public VfsEntry(string name, string hash) : base(name, hash, "vfs") { } - [JsonPropertyName("virtualPath")] - public string? VirtualPath { get; set; } - } - - private sealed class IcuData : AssetEntry - { - public IcuData(string name, string hash) : base(name, hash, "icu") { } - [JsonPropertyName("loadRemote")] - public bool LoadRemote { get; set; } - } - - private sealed class SymbolsData : AssetEntry - { - public SymbolsData(string name, string hash) : base(name, hash, "symbols") { } - } - protected override bool ValidateArguments() { if (!base.ValidateArguments()) @@ -168,14 +68,14 @@ protected override bool ExecuteInternal() } MainAssemblyName = Path.GetFileName(MainAssemblyName); - var config = new WasmAppConfig() + var config = new BootJsonData() { - MainAssemblyName = MainAssemblyName, - GlobalizationMode = InvariantGlobalization ? "invariant" : HybridGlobalization ? "hybrid" : "icu" + entryAssembly = MainAssemblyName, + icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.Sharded }; // Create app - var asmRootPath = Path.Combine(AppDir, config.AssemblyRootFolder); + var asmRootPath = AppDir; Directory.CreateDirectory(AppDir!); Directory.CreateDirectory(asmRootPath); if (UseWebcil) @@ -213,30 +113,11 @@ protected override bool ExecuteInternal() var dest = Path.Combine(AppDir!, name); if (!FileCopyChecked(item.ItemSpec, dest, "NativeAssets")) return false; - if (name == "dotnet.js") - { - config.Assets.Add(new LoaderJsEntry (name, Utils.ComputeIntegrity(item.ItemSpec)) ); - } - else if (name == "dotnet.native.wasm") - { - config.Assets.Add(new WasmEntry(name, Utils.ComputeIntegrity(item.ItemSpec))); - } - else if (name == "dotnet.native.js") - { - config.Assets.Add(new NativeJsEntry (name, Utils.ComputeIntegrity(item.ItemSpec)) ); - } - else if (name == "dotnet.runtime.js") - { - config.Assets.Add(new RuntimeJsEntry (name, Utils.ComputeIntegrity(item.ItemSpec)) ); - } - else if (IncludeThreadsWorker && name == "dotnet.native.worker.js") - { - config.Assets.Add(new ThreadsWorkerEntry(name, Utils.ComputeIntegrity(item.ItemSpec))); - } - else if (name == "dotnet.native.js.symbols") - { - config.Assets.Add(new SymbolsData(name, Utils.ComputeIntegrity(item.ItemSpec))); - } + + if (!IncludeThreadsWorker && name == "dotnet.native.worker.js") + continue; + + config.resources.runtime[name] = Utils.ComputeIntegrity(item.ItemSpec); } string packageJsonPath = Path.Combine(AppDir, "package.json"); @@ -264,23 +145,21 @@ protected override bool ExecuteInternal() bytes = File.ReadAllBytes(assemblyPath); } - config.Assets.Add(new AssemblyEntry(Path.GetFileName(assemblyPath), Utils.ComputeIntegrity(bytes))); + config.resources.assembly[Path.GetFileName(assemblyPath)] = Utils.ComputeIntegrity(bytes); if (DebugLevel != 0) { - var pdb = assembly; - pdb = Path.ChangeExtension(pdb, ".pdb"); - if (File.Exists(pdb)) - config.Assets.Add(new PdbEntry(Path.GetFileName(pdb), Utils.ComputeIntegrity(pdb))); + var pdb = Path.ChangeExtension(assembly, ".pdb"); + config.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); } } } - config.DebugLevel = DebugLevel; + config.debugBuild = DebugLevel > 0; ProcessSatelliteAssemblies(args => { string name = Path.GetFileName(args.fullPath); - string directory = Path.Combine(AppDir, config.AssemblyRootFolder, args.culture); + string directory = Path.Combine(AppDir, args.culture); Directory.CreateDirectory(directory); if (UseWebcil) { @@ -293,13 +172,21 @@ protected override bool ExecuteInternal() else Log.LogMessage(MessageImportance.Low, $"Skipped generating {finalWebcil} as the contents are unchanged."); _fileWrites.Add(finalWebcil); - config.Assets.Add(new SatelliteAssemblyEntry(Path.GetFileName(finalWebcil), Utils.ComputeIntegrity(finalWebcil), args.culture)); + + if (!config.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) + config.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); + + cultureSatelliteResources[Path.GetFileName(finalWebcil)] = Utils.ComputeIntegrity(finalWebcil); } else { var satellitePath = Path.Combine(directory, name); FileCopyChecked(args.fullPath, satellitePath, "SatelliteAssemblies"); - config.Assets.Add(new SatelliteAssemblyEntry(name, Utils.ComputeIntegrity(satellitePath), args.culture)); + + if (!config.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) + config.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); + + cultureSatelliteResources[name] = Utils.ComputeIntegrity(satellitePath); } }); @@ -340,6 +227,7 @@ protected override bool ExecuteInternal() var vfsPath = Path.Combine(supportFilesDir, generatedFileName); FileCopyChecked(item.ItemSpec, vfsPath, "FilesToIncludeInFileSystem"); + // TODO MF: Virtual path for VFS var asset = new VfsEntry($"supportFiles/{generatedFileName}", Utils.ComputeIntegrity(vfsPath)) { VirtualPath = targetPath @@ -358,7 +246,9 @@ protected override bool ExecuteInternal() Log.LogError($"Expected the file defined as ICU resource: {idfn} to exist but it does not."); return false; } - config.Assets.Add(new IcuData(Path.GetFileName(idfn), Utils.ComputeIntegrity(idfn)) { LoadRemote = loadRemote }); + + // TODO MF: LoadRemote + config.resources.runtime[Path.GetFileName(idfn)] = Utils.ComputeIntegrity(idfn); } } @@ -370,13 +260,15 @@ protected override bool ExecuteInternal() config.RemoteSources.Add(source.ItemSpec); } + var extraConfiguration = new Dictionary(); + if (PThreadPoolSize < -1) { throw new LogAsErrorException($"PThreadPoolSize must be -1, 0 or positive, but got {PThreadPoolSize}"); } else if (PThreadPoolSize > -1) { - config.Extra["pthreadPoolSize"] = PThreadPoolSize; + extraConfiguration["pthreadPoolSize"] = PThreadPoolSize; } foreach (ITaskItem extra in ExtraConfig ?? Enumerable.Empty()) @@ -385,7 +277,12 @@ protected override bool ExecuteInternal() if (!TryParseExtraConfigValue(extra, out object? valueObject)) return false; - config.Extra[name] = valueObject; + extraConfiguration[name] = valueObject; + } + + if (extraConfiguration.Count > 0) + { + config.extensions["extra"] = extraConfiguration; } string tmpMonoConfigPath = Path.GetTempFileName(); From 9d4ddc5be935bac44bd13ab3ff4def18fd7d8093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 15:08:52 +0200 Subject: [PATCH 02/77] Assets hash --- src/tasks/WasmAppBuilder/BootJsonData.cs | 5 +++++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index 9cf04a70dc8233..06c07fbd406d5d 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -72,6 +72,11 @@ public class BootJsonData public class ResourcesData { + /// + /// Gets a hash of all resources + /// + public string hash { get; set; } + /// /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. /// diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index d291e4df1d5be7..7f94c5c9da405b 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -255,6 +255,7 @@ protected override bool ExecuteInternal() if (RemoteSources?.Length > 0) { + // TODO MF: RemoteSources foreach (var source in RemoteSources) if (source != null && source.ItemSpec != null) config.RemoteSources.Add(source.ItemSpec); @@ -289,11 +290,26 @@ protected override bool ExecuteInternal() using (var sw = File.CreateText(tmpMonoConfigPath)) { var sb = new StringBuilder(); - foreach (AssetEntry asset in config.Assets) + + static void AddDictionary(StringBuilder sb, Dictionary res) { - sb.Append(asset.Hash); + foreach (var asset in res) + sb.Append(asset.Value); } - config.AssetsHash = Utils.ComputeTextIntegrity(sb.ToString()); + + AddDictionary(sb, config.resources.assembly); + AddDictionary(sb, config.resources.runtime); + + if (config.resources.lazyAssembly != null) + AddDictionary(sb, config.resources.lazyAssembly); + + if (config.resources.satelliteResources != null) + { + foreach (var culture in config.resources.satelliteResources) + AddDictionary(sb, culture.Value); + } + + config.resources.hash = Utils.ComputeTextIntegrity(sb.ToString()); var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); sw.Write(json); From 1c44c21dbcf76d851dbabf38f6f4b5406cd6488f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 15:13:10 +0200 Subject: [PATCH 03/77] VFS --- src/tasks/WasmAppBuilder/BootJsonData.cs | 3 +++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index 06c07fbd406d5d..e8dd2940e1b6d6 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -124,6 +124,9 @@ public class ResourcesData [DataMember(EmitDefaultValue = false)] public Dictionary runtimeAssets { get; set; } + [DataMember(EmitDefaultValue = false)] + public Dictionary vfs { get; set; } + } public enum ICUDataMode : int diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 7f94c5c9da405b..d383f0a00f0cbc 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -197,6 +197,7 @@ protected override bool ExecuteInternal() var i = 0; StringDictionary targetPathTable = new(); + var vfs = new Dictionary>(); foreach (var item in FilesToIncludeInFileSystem) { string? targetPath = item.GetMetadata("TargetPath"); @@ -227,13 +228,14 @@ protected override bool ExecuteInternal() var vfsPath = Path.Combine(supportFilesDir, generatedFileName); FileCopyChecked(item.ItemSpec, vfsPath, "FilesToIncludeInFileSystem"); - // TODO MF: Virtual path for VFS - var asset = new VfsEntry($"supportFiles/{generatedFileName}", Utils.ComputeIntegrity(vfsPath)) + vfs[targetPath] = new() { - VirtualPath = targetPath + [$"supportFiles/{generatedFileName}"] = Utils.ComputeIntegrity(vfsPath) }; - config.Assets.Add(asset); } + + if (vfs.Count > 0) + config.resources.vfs = vfs; } if (!InvariantGlobalization) @@ -309,6 +311,12 @@ static void AddDictionary(StringBuilder sb, Dictionary res) AddDictionary(sb, culture.Value); } + if (config.resources.vfs != null) + { + foreach (var entry in config.resources.vfs) + AddDictionary(sb, entry.Value); + } + config.resources.hash = Utils.ComputeTextIntegrity(sb.ToString()); var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); From c74bb2920daa22771eb76bddb08eb123e2a16c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 15:13:43 +0200 Subject: [PATCH 04/77] Drop RemoteSources --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index d383f0a00f0cbc..7848b6ea4a3b36 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -258,9 +258,9 @@ protected override bool ExecuteInternal() if (RemoteSources?.Length > 0) { // TODO MF: RemoteSources - foreach (var source in RemoteSources) - if (source != null && source.ItemSpec != null) - config.RemoteSources.Add(source.ItemSpec); + //foreach (var source in RemoteSources) + // if (source != null && source.ItemSpec != null) + // config.RemoteSources.Add(source.ItemSpec); } var extraConfiguration = new Dictionary(); From c1903bb8c68b3e64c6373bb795e1ee0226b76bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 17:46:28 +0200 Subject: [PATCH 05/77] Disable nullable in BootJsonData --- src/tasks/WasmAppBuilder/BootJsonData.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index e8dd2940e1b6d6..fffac66131de9a 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -7,6 +7,8 @@ namespace Microsoft.NET.Sdk.WebAssembly; +#nullable disable + /// /// Defines the structure of a Blazor boot JSON file /// @@ -67,7 +69,7 @@ public class BootJsonData /// /// Gets or sets configuration extensions. /// - public Dictionary> extensions { get; set; } + public Dictionary> extensions { get; set; } } public class ResourcesData From 09286524d83cfbe12f8396c2cf578b88a2e871a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 17:46:38 +0200 Subject: [PATCH 06/77] Load VFS in JS --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 12 ++++++++++++ src/mono/wasm/runtime/types/blazor.ts | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 393658b67668a7..cf10b1f3224f3e 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -85,6 +85,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.applicationEnvironment = applicationEnvironment; + moduleConfig.assetsHash = resourceLoader.bootConfig.resources.hash; moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; moduleConfig.environmentVariables = environmentVariables; @@ -162,6 +163,17 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl assets.push(asset); } + for (const virtualPath in resources.vfs) { + for (const name in resources.vfs[virtualPath]) { + const asset: AssetEntry = { + name, + hash: resources.vfs[virtualPath][name], + behavior: "vfs", + }; + assets.push(asset); + } + } + if (!hasIcuData) { moduleConfig.globalizationMode = "invariant"; } diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 95f88fd1017754..0555ed581d0d31 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -22,6 +22,7 @@ export interface BootJsonData { export type BootJsonDataExtension = { [extensionName: string]: ResourceList }; export interface ResourceGroups { + readonly hash?: string; readonly assembly: ResourceList; readonly lazyAssembly: ResourceList; readonly pdb?: ResourceList; @@ -30,6 +31,7 @@ export interface ResourceGroups { readonly libraryInitializers?: ResourceList, readonly extensions?: BootJsonDataExtension readonly runtimeAssets: ExtendedResourceList; + readonly vfs?: { [virtualPath: string]: ResourceList }; } export type ResourceList = { [name: string]: string }; From b8fe6e5025fc6025c211ac6a40e8e727648068c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 18:04:54 +0200 Subject: [PATCH 07/77] Add dotnetwasm to runtimeAssets --- src/mono/wasm/runtime/dotnet.d.ts | 4 ++++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index d5cbed9f3354f7..1a9bd8f5fd2b61 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -303,6 +303,7 @@ type BootJsonDataExtension = { [extensionName: string]: ResourceList; }; interface ResourceGroups { + readonly hash?: string; readonly assembly: ResourceList; readonly lazyAssembly: ResourceList; readonly pdb?: ResourceList; @@ -313,6 +314,9 @@ interface ResourceGroups { readonly libraryInitializers?: ResourceList; readonly extensions?: BootJsonDataExtension; readonly runtimeAssets: ExtendedResourceList; + readonly vfs?: { + [virtualPath: string]: ResourceList; + }; } type ResourceList = { [name: string]: string; diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 7848b6ea4a3b36..06265caa9177e5 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -117,6 +117,18 @@ protected override bool ExecuteInternal() if (!IncludeThreadsWorker && name == "dotnet.native.worker.js") continue; + if (name.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(name), ".wasm", StringComparison.OrdinalIgnoreCase)) + { + if (config.resources.runtimeAssets == null) + config.resources.runtimeAssets = new(); + + config.resources.runtimeAssets[name] = new() + { + Hash = $"sha256-{item.GetMetadata("FileHash")}", + Behavior = "dotnetwasm" + }; + } + config.resources.runtime[name] = Utils.ComputeIntegrity(item.ItemSpec); } @@ -149,7 +161,8 @@ protected override bool ExecuteInternal() if (DebugLevel != 0) { var pdb = Path.ChangeExtension(assembly, ".pdb"); - config.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); + if (File.Exists(pdb)) + config.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); } } } From eaca5a68809a57ea988dbf547380b538c44ce59d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 18:37:09 +0200 Subject: [PATCH 08/77] Fix null config.resources.pdb --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 06265caa9177e5..8297e0ae54f217 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -162,7 +162,12 @@ protected override bool ExecuteInternal() { var pdb = Path.ChangeExtension(assembly, ".pdb"); if (File.Exists(pdb)) + { + if (config.resources.pdb == null) + config.resources.pdb = new(); + config.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); + } } } } From 784a09a77bfab3f19b7923b645f42d3ad8784d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 15 May 2023 18:38:34 +0200 Subject: [PATCH 09/77] Fix null config.resources.satelliteResources --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 8297e0ae54f217..e7a8f049419223 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -176,6 +176,9 @@ protected override bool ExecuteInternal() ProcessSatelliteAssemblies(args => { + if (config.resources.satelliteResources == null) + config.resources.satelliteResources = new(); + string name = Path.GetFileName(args.fullPath); string directory = Path.Combine(AppDir, args.culture); Directory.CreateDirectory(directory); From 859c46f3b20206018a6324f34ba2bcd576760bbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 10:25:49 +0200 Subject: [PATCH 10/77] Fix dotnetwasm hash --- src/tasks/WasmAppBuilder/BootJsonData.cs | 4 ++-- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index fffac66131de9a..519dd0c6012fe1 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -162,8 +162,8 @@ public enum ICUDataMode : int public class AdditionalAsset { [DataMember(Name = "hash")] - public string Hash { get; set; } + public string hash { get; set; } [DataMember(Name = "behavior")] - public string Behavior { get; set; } + public string behavior { get; set; } } diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index e7a8f049419223..9794605b80611d 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -117,6 +117,8 @@ protected override bool ExecuteInternal() if (!IncludeThreadsWorker && name == "dotnet.native.worker.js") continue; + var itemHash = Utils.ComputeIntegrity(item.ItemSpec); + if (name.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(name), ".wasm", StringComparison.OrdinalIgnoreCase)) { if (config.resources.runtimeAssets == null) @@ -124,12 +126,12 @@ protected override bool ExecuteInternal() config.resources.runtimeAssets[name] = new() { - Hash = $"sha256-{item.GetMetadata("FileHash")}", - Behavior = "dotnetwasm" + hash = itemHash, + behavior = "dotnetwasm" }; } - config.resources.runtime[name] = Utils.ComputeIntegrity(item.ItemSpec); + config.resources.runtime[name] = itemHash; } string packageJsonPath = Path.Combine(AppDir, "package.json"); From 8ebcce8bc11399c52acda8d8e4a32104b6c52079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 10:43:25 +0200 Subject: [PATCH 11/77] Handle symbols in blazor path --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index cf10b1f3224f3e..4063f0c8629412 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -37,8 +37,9 @@ const behaviorByName = (name: string): AssetBehaviours | "other" => { : (name.startsWith("dotnet.native") && name.endsWith(".js")) ? "js-module-native" : (name.startsWith("dotnet.runtime") && name.endsWith(".js")) ? "js-module-runtime" : (name.startsWith("dotnet") && name.endsWith(".js")) ? "js-module-dotnet" - : name.startsWith("icudt") ? "icu" - : "other"; + : (name.startsWith("dotnet") && name.endsWith(".symbols")) ? "symbols" + : name.startsWith("icudt") ? "icu" + : "other"; }; const monoToBlazorAssetTypeMap: { [key: string]: WebAssemblyBootResourceType | undefined } = { From c709ba37907efd58051d653986a98fbf8bb3e83f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 10:43:44 +0200 Subject: [PATCH 12/77] Move everything in _framework folder --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 9794605b80611d..cb620da3543fd6 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -75,9 +75,9 @@ protected override bool ExecuteInternal() }; // Create app - var asmRootPath = AppDir; + var frameworkPath = Path.Combine(AppDir, "_framework"); Directory.CreateDirectory(AppDir!); - Directory.CreateDirectory(asmRootPath); + Directory.CreateDirectory(frameworkPath); if (UseWebcil) Log.LogMessage(MessageImportance.Normal, "Converting assemblies to Webcil"); foreach (var assembly in _assemblies) @@ -87,7 +87,7 @@ protected override bool ExecuteInternal() var tmpWebcil = Path.GetTempFileName(); var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: assembly, outputPath: tmpWebcil, logger: Log); webcilWriter.ConvertToWebcil(); - var finalWebcil = Path.Combine(asmRootPath, Path.ChangeExtension(Path.GetFileName(assembly), ".webcil")); + var finalWebcil = Path.Combine(frameworkPath, Path.ChangeExtension(Path.GetFileName(assembly), ".webcil")); if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true)) Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} ."); else @@ -96,21 +96,22 @@ protected override bool ExecuteInternal() } else { - FileCopyChecked(assembly, Path.Combine(asmRootPath, Path.GetFileName(assembly)), "Assemblies"); + FileCopyChecked(assembly, Path.Combine(frameworkPath, Path.GetFileName(assembly)), "Assemblies"); } if (DebugLevel != 0) { var pdb = assembly; pdb = Path.ChangeExtension(pdb, ".pdb"); if (File.Exists(pdb)) - FileCopyChecked(pdb, Path.Combine(asmRootPath, Path.GetFileName(pdb)), "Assemblies"); + FileCopyChecked(pdb, Path.Combine(frameworkPath, Path.GetFileName(pdb)), "Assemblies"); } } + Log.LogMessage(MessageImportance.High, $"MF NativeAssets length '{NativeAssets.Length}'"); foreach (ITaskItem item in NativeAssets) { var name = Path.GetFileName(item.ItemSpec); - var dest = Path.Combine(AppDir!, name); + var dest = Path.Combine(frameworkPath, name); if (!FileCopyChecked(item.ItemSpec, dest, "NativeAssets")) return false; @@ -119,8 +120,11 @@ protected override bool ExecuteInternal() var itemHash = Utils.ComputeIntegrity(item.ItemSpec); + Log.LogMessage(MessageImportance.High, $"MF NativeAssets '{name}', '{item.ItemSpec}'"); if (name.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(name), ".wasm", StringComparison.OrdinalIgnoreCase)) { + Log.LogMessage(MessageImportance.High, "MF dotnetwasm"); + if (config.resources.runtimeAssets == null) config.resources.runtimeAssets = new(); @@ -154,7 +158,7 @@ protected override bool ExecuteInternal() { if (UseWebcil) { - assemblyPath = Path.Combine(asmRootPath, Path.ChangeExtension(Path.GetFileName(assembly), ".webcil")); + assemblyPath = Path.Combine(frameworkPath, Path.ChangeExtension(Path.GetFileName(assembly), ".webcil")); // For the hash, read the bytes from the webcil file, not the dll file. bytes = File.ReadAllBytes(assemblyPath); } @@ -182,7 +186,7 @@ protected override bool ExecuteInternal() config.resources.satelliteResources = new(); string name = Path.GetFileName(args.fullPath); - string directory = Path.Combine(AppDir, args.culture); + string directory = Path.Combine(frameworkPath, args.culture); Directory.CreateDirectory(directory); if (UseWebcil) { @@ -215,7 +219,7 @@ protected override bool ExecuteInternal() if (FilesToIncludeInFileSystem.Length > 0) { - string supportFilesDir = Path.Combine(AppDir, "supportFiles"); + string supportFilesDir = Path.Combine(frameworkPath, "supportFiles"); Directory.CreateDirectory(supportFilesDir); var i = 0; @@ -346,11 +350,7 @@ static void AddDictionary(StringBuilder sb, Dictionary res) sw.Write(json); } - string monoConfigDir = Path.Combine(AppDir, "_framework"); - if (!Directory.Exists(monoConfigDir)) - Directory.CreateDirectory(monoConfigDir); - - string monoConfigPath = Path.Combine(monoConfigDir, "blazor.boot.json"); // TODO: Unify with Wasm SDK + string monoConfigPath = Path.Combine(frameworkPath, "blazor.boot.json"); // TODO: Unify with Wasm SDK Utils.CopyIfDifferent(tmpMonoConfigPath, monoConfigPath, useHash: false); _fileWrites.Add(monoConfigPath); From b32d5a3fc46b39a4a655cd3d31edbd4bbbccb081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 10:47:53 +0200 Subject: [PATCH 13/77] Update path to dotnet.js in imports --- src/mono/sample/mbr/browser/main.js | 4 ++-- .../sample/wasm/browser-advanced/index.html | 2 +- src/mono/sample/wasm/browser-advanced/main.js | 2 +- .../wasm/browser-bench/appstart-frame.html | 2 +- .../sample/wasm/browser-bench/frame-main.js | 2 +- src/mono/sample/wasm/browser-bench/main.js | 2 +- .../sample/wasm/browser-eventpipe/main.js | 2 +- src/mono/sample/wasm/browser-profile/main.js | 2 +- .../wasm/browser-threads-minimal/main.js | 22 +++++++++---------- src/mono/sample/wasm/browser-threads/main.js | 2 +- .../Wasm.Browser.WebPack.Sample.csproj | 16 +++++++------- src/mono/sample/wasm/browser/main.js | 2 +- src/mono/sample/wasm/console-node/main.mjs | 2 +- src/mono/sample/wasm/console-v8/main.mjs | 2 +- .../Wasm.Node.WebPack.Sample.csproj | 16 +++++++------- src/mono/sample/wasm/simple-raytracer/main.js | 2 +- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 10 ++++----- .../tests/debugger-test/debugger-main.js | 2 +- src/mono/wasm/test-main.js | 4 ++-- .../WebAssembly/Browser/HotReload/main.js | 2 +- .../WebAssembly/Browser/RuntimeConfig/main.js | 2 +- .../WebAssembly/Browser/StartupHook/main.js | 2 +- 22 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/mono/sample/mbr/browser/main.js b/src/mono/sample/mbr/browser/main.js index ff6a9d021f72eb..a3ffba9207be67 100644 --- a/src/mono/sample/mbr/browser/main.js +++ b/src/mono/sample/mbr/browser/main.js @@ -1,4 +1,4 @@ -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' try { const { getAssemblyExports } = await dotnet @@ -8,7 +8,7 @@ try { const exports = await getAssemblyExports("WasmDelta.dll"); const update = exports.Sample.Test.Update; const testMeaning = exports.Sample.Test.TestMeaning; - + const outElement = document.getElementById("out"); document.getElementById("update").addEventListener("click", function () { update(); diff --git a/src/mono/sample/wasm/browser-advanced/index.html b/src/mono/sample/wasm/browser-advanced/index.html index 179a0354970f34..ea7e3ae4d378e5 100644 --- a/src/mono/sample/wasm/browser-advanced/index.html +++ b/src/mono/sample/wasm/browser-advanced/index.html @@ -9,7 +9,7 @@ - + diff --git a/src/mono/sample/wasm/browser-advanced/main.js b/src/mono/sample/wasm/browser-advanced/main.js index 82be8cbaef1e75..bdd8036aba4c0d 100644 --- a/src/mono/sample/wasm/browser-advanced/main.js +++ b/src/mono/sample/wasm/browser-advanced/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' function add(a, b) { return a + b; diff --git a/src/mono/sample/wasm/browser-bench/appstart-frame.html b/src/mono/sample/wasm/browser-bench/appstart-frame.html index 684acbcb998de2..697f7ac01d1edc 100644 --- a/src/mono/sample/wasm/browser-bench/appstart-frame.html +++ b/src/mono/sample/wasm/browser-bench/appstart-frame.html @@ -8,7 +8,7 @@ - + diff --git a/src/mono/sample/wasm/browser-bench/frame-main.js b/src/mono/sample/wasm/browser-bench/frame-main.js index 667f5eec947d5e..c1042928d78d07 100644 --- a/src/mono/sample/wasm/browser-bench/frame-main.js +++ b/src/mono/sample/wasm/browser-bench/frame-main.js @@ -3,7 +3,7 @@ "use strict"; -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' class FrameApp { async init({ getAssemblyExports }) { diff --git a/src/mono/sample/wasm/browser-bench/main.js b/src/mono/sample/wasm/browser-bench/main.js index 28d9613fb7a948..eb9080e51914a1 100644 --- a/src/mono/sample/wasm/browser-bench/main.js +++ b/src/mono/sample/wasm/browser-bench/main.js @@ -3,7 +3,7 @@ "use strict"; -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' let runBenchmark; let setTasks; diff --git a/src/mono/sample/wasm/browser-eventpipe/main.js b/src/mono/sample/wasm/browser-eventpipe/main.js index 2bf5dc8d9ff9ac..48e2728ca80a02 100644 --- a/src/mono/sample/wasm/browser-eventpipe/main.js +++ b/src/mono/sample/wasm/browser-eventpipe/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from "./dotnet.js"; +import { dotnet, exit } from "./_framework/dotnet.js"; const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) diff --git a/src/mono/sample/wasm/browser-profile/main.js b/src/mono/sample/wasm/browser-profile/main.js index 455702ebbf5fc6..aa31ff50dd8c6c 100644 --- a/src/mono/sample/wasm/browser-profile/main.js +++ b/src/mono/sample/wasm/browser-profile/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' function saveProfile(aotProfileData) { if (!aotProfileData) { diff --git a/src/mono/sample/wasm/browser-threads-minimal/main.js b/src/mono/sample/wasm/browser-threads-minimal/main.js index 3179fd5739e5b4..ef939f84122a19 100644 --- a/src/mono/sample/wasm/browser-threads-minimal/main.js +++ b/src/mono/sample/wasm/browser-threads-minimal/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' const assemblyName = "Wasm.Browser.Threads.Minimal.Sample.dll"; @@ -19,36 +19,36 @@ try { await exports.Sample.Test.TestCanStartThread(); console.log("smoke: TestCanStartThread done"); - console.log ("smoke: running TestCallSetTimeoutOnWorker"); + console.log("smoke: running TestCallSetTimeoutOnWorker"); await exports.Sample.Test.TestCallSetTimeoutOnWorker(); - console.log ("smoke: TestCallSetTimeoutOnWorker done"); + console.log("smoke: TestCallSetTimeoutOnWorker done"); - console.log ("smoke: running FetchBackground(blurst.txt)"); + console.log("smoke: running FetchBackground(blurst.txt)"); let s = await exports.Sample.Test.FetchBackground("./blurst.txt"); - console.log ("smoke: FetchBackground(blurst.txt) done"); + console.log("smoke: FetchBackground(blurst.txt) done"); if (s !== "It was the best of times, it was the blurst of times.\n") { const msg = `Unexpected FetchBackground result ${s}`; document.getElementById("out").innerHTML = msg; - throw new Error (msg); + throw new Error(msg); } - console.log ("smoke: running FetchBackground(missing)"); + console.log("smoke: running FetchBackground(missing)"); s = await exports.Sample.Test.FetchBackground("./missing.txt"); - console.log ("smoke: FetchBackground(missing) done"); + console.log("smoke: FetchBackground(missing) done"); if (s !== "not-ok") { const msg = `Unexpected FetchBackground(missing) result ${s}`; document.getElementById("out").innerHTML = msg; - throw new Error (msg); + throw new Error(msg); } - console.log ("smoke: running TaskRunCompute"); + console.log("smoke: running TaskRunCompute"); const r1 = await exports.Sample.Test.RunBackgroundTaskRunCompute(); if (r1 !== 524) { const msg = `Unexpected result ${r1} from RunBackgorundTaskRunCompute()`; document.getElementById("out").innerHTML = msg; throw new Error(msg); } - console.log ("smoke: TaskRunCompute done"); + console.log("smoke: TaskRunCompute done"); let exit_code = await runMain(assemblyName, []); diff --git a/src/mono/sample/wasm/browser-threads/main.js b/src/mono/sample/wasm/browser-threads/main.js index 9b739d474e943b..c97e380797fc6e 100644 --- a/src/mono/sample/wasm/browser-threads/main.js +++ b/src/mono/sample/wasm/browser-threads/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' let progressElement = null; diff --git a/src/mono/sample/wasm/browser-webpack/Wasm.Browser.WebPack.Sample.csproj b/src/mono/sample/wasm/browser-webpack/Wasm.Browser.WebPack.Sample.csproj index bb694f24f38f5f..0459f5119b71eb 100644 --- a/src/mono/sample/wasm/browser-webpack/Wasm.Browser.WebPack.Sample.csproj +++ b/src/mono/sample/wasm/browser-webpack/Wasm.Browser.WebPack.Sample.csproj @@ -9,18 +9,18 @@ - - - - - + + + + diff --git a/src/mono/sample/wasm/browser/main.js b/src/mono/sample/wasm/browser/main.js index 27783085b924ce..ba84cca682189b 100644 --- a/src/mono/sample/wasm/browser/main.js +++ b/src/mono/sample/wasm/browser/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' function displayMeaning(meaning) { document.getElementById("out").innerHTML = `${meaning}`; diff --git a/src/mono/sample/wasm/console-node/main.mjs b/src/mono/sample/wasm/console-node/main.mjs index 3b9741a5398a73..d3cfafe5f61896 100644 --- a/src/mono/sample/wasm/console-node/main.mjs +++ b/src/mono/sample/wasm/console-node/main.mjs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' await dotnet .withDiagnosticTracing(false) diff --git a/src/mono/sample/wasm/console-v8/main.mjs b/src/mono/sample/wasm/console-v8/main.mjs index b336fe2884fd53..4350b81478f8d0 100644 --- a/src/mono/sample/wasm/console-v8/main.mjs +++ b/src/mono/sample/wasm/console-v8/main.mjs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' await dotnet .withDiagnosticTracing(false) diff --git a/src/mono/sample/wasm/node-webpack/Wasm.Node.WebPack.Sample.csproj b/src/mono/sample/wasm/node-webpack/Wasm.Node.WebPack.Sample.csproj index b10e78238aef41..88216d3e1258b8 100644 --- a/src/mono/sample/wasm/node-webpack/Wasm.Node.WebPack.Sample.csproj +++ b/src/mono/sample/wasm/node-webpack/Wasm.Node.WebPack.Sample.csproj @@ -4,18 +4,18 @@ main.mjs - - - - - + + + + diff --git a/src/mono/sample/wasm/simple-raytracer/main.js b/src/mono/sample/wasm/simple-raytracer/main.js index b0f685a71e6b13..decdf6453c9480 100644 --- a/src/mono/sample/wasm/simple-raytracer/main.js +++ b/src/mono/sample/wasm/simple-raytracer/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' function renderCanvas(rgbaView) { const canvas = document.getElementById("out"); diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 17bc1d17ae79f9..146fe44a2ab1da 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -668,11 +668,11 @@ protected static void AssertBasicAppBundle(string bundleDir, var filesToExist = new List() { mainJS, - "dotnet.native.wasm", + "_framework/dotnet.native.wasm", "_framework/blazor.boot.json", - "dotnet.js", - "dotnet.native.js", - "dotnet.runtime.js" + "_framework/dotnet.js", + "_framework/dotnet.native.js", + "_framework/dotnet.runtime.js" }; if (isBrowserProject) @@ -837,7 +837,7 @@ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasm same: dotnetWasmFromRuntimePack); } - protected void AssertBlazorBootJson(string config, bool isPublish, bool isNet7AndBelow, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir=null) + protected void AssertBlazorBootJson(string config, bool isPublish, bool isNet7AndBelow, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir = null) { binFrameworkDir ??= FindBlazorBinFrameworkDir(config, isPublish, targetFramework); diff --git a/src/mono/wasm/debugger/tests/debugger-test/debugger-main.js b/src/mono/wasm/debugger/tests/debugger-test/debugger-main.js index 6f39603f1dcffe..cb6273ed31e63b 100644 --- a/src/mono/wasm/debugger/tests/debugger-test/debugger-main.js +++ b/src/mono/wasm/debugger/tests/debugger-test/debugger-main.js @@ -3,7 +3,7 @@ "use strict"; -import { dotnet, exit } from './dotnet.js' +import { dotnet, exit } from './_framework/dotnet.js' try { const runtime = await dotnet diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.js index 79f5620e4b0a6e..ed2e5c1adc4ddf 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.js @@ -4,7 +4,7 @@ // // Run runtime tests under a JS shell or a browser // -import { dotnet, exit } from './dotnet.js'; +import { dotnet, exit } from './_framework/dotnet.js'; /***************************************************************************** @@ -296,7 +296,7 @@ async function dry_run(runArgs) { try { console.log("Silently starting separate runtime instance as another ES6 module to populate caches..."); // this separate instance of the ES6 module, in which we just populate the caches - const { dotnet } = await import('./dotnet.js?dry_run=true'); + const { dotnet } = await import('./_framework/dotnet.js?dry_run=true'); configureRuntime(dotnet, runArgs); // silent minimal startup await dotnet.withConfig({ diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/HotReload/main.js b/src/tests/FunctionalTests/WebAssembly/Browser/HotReload/main.js index ed7d0f24e9ee5b..b1ca242684f915 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/HotReload/main.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/HotReload/main.js @@ -1,4 +1,4 @@ -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' function wasm_exit(exit_code) { var tests_done_elem = document.createElement("label"); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/main.js b/src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/main.js index 249aa44c4143bc..7ca0a21d8c6742 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/main.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/RuntimeConfig/main.js @@ -1,4 +1,4 @@ -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' function wasm_exit(exit_code) { var tests_done_elem = document.createElement("label"); diff --git a/src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js b/src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js index a7323e1a89a925..10858c7d584525 100644 --- a/src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js +++ b/src/tests/FunctionalTests/WebAssembly/Browser/StartupHook/main.js @@ -1,4 +1,4 @@ -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' function wasm_exit(exit_code) { var tests_done_elem = document.createElement("label"); From 1581b7698b79f7e7866c7308223352e1f1286a67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 10:50:29 +0200 Subject: [PATCH 14/77] Fix configSrc path in advanced sample --- src/mono/sample/wasm/browser-advanced/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/sample/wasm/browser-advanced/main.js b/src/mono/sample/wasm/browser-advanced/main.js index bdd8036aba4c0d..87096cf374c715 100644 --- a/src/mono/sample/wasm/browser-advanced/main.js +++ b/src/mono/sample/wasm/browser-advanced/main.js @@ -31,7 +31,7 @@ try { // here we show how emscripten could be further configured // It is preferred to use specific 'with***' methods instead in all other cases. .withModuleConfig({ - configSrc: "./_framework/blazor.boot.json", + configSrc: "./blazor.boot.json", onConfigLoaded: (config) => { // This is called during emscripten `dotnet.wasm` instantiation, after we fetched config. console.log('user code Module.onConfigLoaded'); From d1abc9a51d8139dd8ee1e181b231dc0b252bf2f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 16 May 2023 13:02:00 +0200 Subject: [PATCH 15/77] Fix merge --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 9abbb0d5a833ea..da6bbf2fd547d5 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -36,9 +36,9 @@ const behaviorByName = (name: string): AssetBehaviours | "other" => { : (name.startsWith("dotnet.native") && name.endsWith(".js")) ? "js-module-native" : (name.startsWith("dotnet.runtime") && name.endsWith(".js")) ? "js-module-runtime" : (name.startsWith("dotnet") && name.endsWith(".js")) ? "js-module-dotnet" - : (name.startsWith("dotnet") && name.endsWith(".symbols")) ? "symbols" - : name.startsWith("icudt") ? "icu" - : "other"; + : (name.startsWith("dotnet") && name.endsWith(".symbols")) ? "symbols" + : name.startsWith("icudt") ? "icu" + : "other"; }; const monoToBlazorAssetTypeMap: { [key: string]: WebAssemblyBootResourceType | undefined } = { @@ -162,7 +162,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl }; assets.push(asset); } - + for (let i = 0; i < resourceLoader.bootConfig.config.length; i++) { const config = resourceLoader.bootConfig.config[i]; if (config === "appsettings.json" || config === `appsettings.${applicationEnvironment}.json`) { From dca3ae7144bae508da94e5773eb8ff7811eb54ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 May 2023 14:38:25 +0200 Subject: [PATCH 16/77] Drop logging --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index c63b0248ed73f3..9379e46b8c88c0 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -107,7 +107,6 @@ protected override bool ExecuteInternal() } } - Log.LogMessage(MessageImportance.High, $"MF NativeAssets length '{NativeAssets.Length}'"); foreach (ITaskItem item in NativeAssets) { var name = Path.GetFileName(item.ItemSpec); @@ -120,11 +119,8 @@ protected override bool ExecuteInternal() var itemHash = Utils.ComputeIntegrity(item.ItemSpec); - Log.LogMessage(MessageImportance.High, $"MF NativeAssets '{name}', '{item.ItemSpec}'"); if (name.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(name), ".wasm", StringComparison.OrdinalIgnoreCase)) { - Log.LogMessage(MessageImportance.High, "MF dotnetwasm"); - if (config.resources.runtimeAssets == null) config.resources.runtimeAssets = new(); From 7c2b3839bae79b6b099cfb82eaa2a57b0617bf46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 May 2023 15:24:33 +0200 Subject: [PATCH 17/77] Console friendly --- src/mono/wasm/runtime/loader/blazor/_Polyfill.ts | 3 +++ src/mono/wasm/runtime/loader/config.ts | 2 +- src/mono/wasm/runtime/loader/polyfills.ts | 2 ++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts b/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts index 4eeefe2060dd91..3636e1bb5ea495 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts @@ -12,6 +12,9 @@ export function toAbsoluteUri(relativeUri: string): string { export function hasDebuggingEnabled(bootConfig: BootJsonData): boolean { // Copied from blazor MonoDebugger.ts/attachDebuggerHotkey + if (!globalThis.navigator) { + return false; + } const hasReferencedPdbs = !!bootConfig.resources.pdb; const debugBuild = bootConfig.debugBuild; diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index 695911efe018be..c2f3d8b6f3eaf7 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -118,7 +118,7 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi } loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config); } catch (err) { - const errMessage = `Failed to load config file ${configFilePath} ${err}`; + const errMessage = `Failed to load config file ${configFilePath} ${err} ${err.stack}`; loaderHelpers.config = module.config = { message: errMessage, error: err, isError: true }; loaderHelpers.abort_startup(errMessage, true); throw err; diff --git a/src/mono/wasm/runtime/loader/polyfills.ts b/src/mono/wasm/runtime/loader/polyfills.ts index fb5c4bc2a6c2e6..c4abcc59f8607b 100644 --- a/src/mono/wasm/runtime/loader/polyfills.ts +++ b/src/mono/wasm/runtime/loader/polyfills.ts @@ -76,6 +76,7 @@ export async function fetch_like(url: string, init?: RequestInit): Promise{ ok: true, url, + headers: [], arrayBuffer: () => { return new Uint8Array(read(url, "binary")); }, @@ -90,6 +91,7 @@ export async function fetch_like(url: string, init?: RequestInit): Promise { throw e; }, json: () => { throw e; } diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 9379e46b8c88c0..52eabddbe12bd4 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -70,6 +70,7 @@ protected override bool ExecuteInternal() var config = new BootJsonData() { + config = new(), entryAssembly = MainAssemblyName, icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.Sharded }; From cfddfd64a0ae99922e0ca717a5685a5d247eadf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 29 May 2023 15:25:06 +0200 Subject: [PATCH 18/77] TMP TO REVERT --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 2801523e679de9..4b78f5fc471031 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -17,12 +17,12 @@ export async function loadBootConfig(config: MonoConfigInternal, module: DotnetM const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, config.applicationEnvironment); const bootConfigResult: BootConfigResult = await bootConfigPromise; await initializeBootConfig(bootConfigResult, module, config.startupOptions); + setupModuleForBlazor(module); } export async function initializeBootConfig(bootConfigResult: BootConfigResult, module: DotnetModuleInternal, startupOptions?: Partial) { INTERNAL.resourceLoader = resourceLoader = await WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, startupOptions ?? {}); mapBootConfigToMonoConfig(loaderHelpers.config, bootConfigResult.applicationEnvironment); - setupModuleForBlazor(module); } let resourcesLoaded = 0; From 280fe6992710d48a773c5247baf9b2d8418e7db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 09:22:35 +0200 Subject: [PATCH 19/77] Fix build --- src/mono/wasm/runtime/loader/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index c2f3d8b6f3eaf7..b32174483bbff7 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -118,7 +118,7 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi } loaderHelpers.afterConfigLoaded.promise_control.resolve(loaderHelpers.config); } catch (err) { - const errMessage = `Failed to load config file ${configFilePath} ${err} ${err.stack}`; + const errMessage = `Failed to load config file ${configFilePath} ${err} ${(err as Error)?.stack}`; loaderHelpers.config = module.config = { message: errMessage, error: err, isError: true }; loaderHelpers.abort_startup(errMessage, true); throw err; From bbde3682530f6913c95db86ae82bb5d13ace8911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 10:19:19 +0200 Subject: [PATCH 20/77] Console friendly --- .../wasm/runtime/loader/blazor/_Integration.ts | 2 +- src/mono/wasm/runtime/loader/polyfills.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 4b78f5fc471031..6c166058ebff6e 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -132,7 +132,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl assets.push(asset); } } - const applicationCulture = resourceLoader.startOptions.applicationCulture || (navigator.languages && navigator.languages[0]); + const applicationCulture = resourceLoader.startOptions.applicationCulture || (globalThis.navigator && navigator.languages && navigator.languages[0]); const icuDataResourceName = getICUResourceName(resourceLoader.bootConfig, applicationCulture); let hasIcuData = false; for (const name in resources.runtime) { diff --git a/src/mono/wasm/runtime/loader/polyfills.ts b/src/mono/wasm/runtime/loader/polyfills.ts index c4abcc59f8607b..d193cdcefeb4d1 100644 --- a/src/mono/wasm/runtime/loader/polyfills.ts +++ b/src/mono/wasm/runtime/loader/polyfills.ts @@ -61,7 +61,10 @@ export async function fetch_like(url: string, init?: RequestInit): Promise{ ok: true, - headers: [], + headers: { + length: 0, + get: () => null + }, url, arrayBuffer: () => arrayBuffer, json: () => JSON.parse(arrayBuffer) @@ -76,7 +79,10 @@ export async function fetch_like(url: string, init?: RequestInit): Promise{ ok: true, url, - headers: [], + headers: { + length: 0, + get: () => null + }, arrayBuffer: () => { return new Uint8Array(read(url, "binary")); }, @@ -91,7 +97,10 @@ export async function fetch_like(url: string, init?: RequestInit): Promise null + }, statusText: "ERR28: " + e, arrayBuffer: () => { throw e; }, json: () => { throw e; } From 3c7d14c6b212cee0f6972cf660c2c85f9546db5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 10:48:07 +0200 Subject: [PATCH 21/77] Fix null extensions --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 52eabddbe12bd4..10fffa46a11cda 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -71,6 +71,7 @@ protected override bool ExecuteInternal() var config = new BootJsonData() { config = new(), + extensions = new(), entryAssembly = MainAssemblyName, icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.Sharded }; From dac75e7fecf437ca6663e272162e3cccd6d1dc39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 11:01:54 +0200 Subject: [PATCH 22/77] A bit more work on WasmExtraConfig --- src/tasks/WasmAppBuilder/BootJsonData.cs | 15 +++++++++++++++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 15 ++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index 519dd0c6012fe1..5f3e1681c08a11 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -70,6 +70,21 @@ public class BootJsonData /// Gets or sets configuration extensions. /// public Dictionary> extensions { get; set; } + + /// + /// Gets or sets environment variables. + /// + public object environmentVariables { get; set; } + + /// + /// Gets or sets diagnostic tracing. + /// + public object diagnosticTracing { get; set; } + + /// + /// Gets or sets pthread pool size. + /// + public object pthreadPoolSize { get; set; } } public class ResourcesData diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 10fffa46a11cda..739aa6c26a61c3 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -71,7 +71,6 @@ protected override bool ExecuteInternal() var config = new BootJsonData() { config = new(), - extensions = new(), entryAssembly = MainAssemblyName, icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.Sharded }; @@ -305,12 +304,22 @@ protected override bool ExecuteInternal() if (!TryParseExtraConfigValue(extra, out object? valueObject)) return false; - extraConfiguration[name] = valueObject; + if (name == "environmentVariables") + config.environmentVariables = valueObject; + else if (name == "diagnosticTracing") + config.diagnosticTracing = valueObject; + else if (name == "pthreadPoolSize") + config.pthreadPoolSize = valueObject; + else + extraConfiguration[name] = valueObject; } if (extraConfiguration.Count > 0) { - config.extensions["extra"] = extraConfiguration; + config.extensions = new() + { + ["extra"] = extraConfiguration + }; } string tmpMonoConfigPath = Path.GetTempFileName(); From a3a33467ac4f96a1cd89757af4a8141d153fd69b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 12:20:20 +0200 Subject: [PATCH 23/77] Propagate assetUniqueQuery --- .../runtime/loader/blazor/_Integration.ts | 19 ++++++++++++++----- src/mono/wasm/runtime/loader/config.ts | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 45d150e3e9985a..31a7179217fa7a 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -75,6 +75,14 @@ export function setupModuleForBlazor(module: DotnetModuleInternal) { module.disableDotnet6Compatibility = false; } +function appendUniqueQuery(attemptUrl: string): string { + if (loaderHelpers.assetUniqueQuery) { + attemptUrl = attemptUrl + loaderHelpers.assetUniqueQuery; + } + + return attemptUrl; +} + export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, applicationEnvironment: string) { const resources = resourceLoader.bootConfig.resources; @@ -109,13 +117,13 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl for (const name in resources.runtimeAssets) { const asset = resources.runtimeAssets[name] as AssetEntry; asset.name = name; - asset.resolvedUrl = loaderHelpers.locateFile(name); + asset.resolvedUrl = appendUniqueQuery(loaderHelpers.locateFile(name)); assets.push(asset); } for (const name in resources.assembly) { const asset: AssetEntry = { name, - resolvedUrl: loaderHelpers.locateFile(name), + resolvedUrl: appendUniqueQuery(loaderHelpers.locateFile(name)), hash: resources.assembly[name], behavior: "assembly", }; @@ -125,7 +133,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl for (const name in resources.pdb) { const asset: AssetEntry = { name, - resolvedUrl: loaderHelpers.locateFile(name), + resolvedUrl: appendUniqueQuery(loaderHelpers.locateFile(name)), hash: resources.pdb[name], behavior: "pdb", }; @@ -151,7 +159,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl continue; } - const resolvedUrl = loaderHelpers.locateFile(name); + const resolvedUrl = appendUniqueQuery(loaderHelpers.locateFile(name)); const asset: AssetEntry = { name, resolvedUrl, @@ -166,7 +174,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl if (config === "appsettings.json" || config === `appsettings.${applicationEnvironment}.json`) { assets.push({ name: config, - resolvedUrl: (document ? document.baseURI : "/") + config, + resolvedUrl: appendUniqueQuery((document ? document.baseURI : "/") + config), behavior: "vfs", }); } @@ -176,6 +184,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl for (const name in resources.vfs[virtualPath]) { const asset: AssetEntry = { name, + resolvedUrl: appendUniqueQuery(loaderHelpers.locateFile(name)), hash: resources.vfs[virtualPath][name], behavior: "vfs", }; diff --git a/src/mono/wasm/runtime/loader/config.ts b/src/mono/wasm/runtime/loader/config.ts index b32174483bbff7..4d997a11865f19 100644 --- a/src/mono/wasm/runtime/loader/config.ts +++ b/src/mono/wasm/runtime/loader/config.ts @@ -94,6 +94,7 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi const loadedAnyConfig: any = (await configResponse.json()) || {}; if (loadedAnyConfig.resources) { // If we found boot config schema + normalizeConfig(); await initializeBootConfig(BootConfigResult.fromFetchResponse(configResponse, loadedAnyConfig as BootJsonData, loaderHelpers.config.applicationEnvironment), module, loaderHelpers.config.startupOptions); } else { // Otherwise we found mono config schema From 52f796dd181fea1d0119fde631d136520779c34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 13:18:48 +0200 Subject: [PATCH 24/77] Fix pthreadPoolSize --- src/tasks/WasmAppBuilder/BootJsonData.cs | 2 +- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tasks/WasmAppBuilder/BootJsonData.cs b/src/tasks/WasmAppBuilder/BootJsonData.cs index 5f3e1681c08a11..daf54973656b0a 100644 --- a/src/tasks/WasmAppBuilder/BootJsonData.cs +++ b/src/tasks/WasmAppBuilder/BootJsonData.cs @@ -84,7 +84,7 @@ public class BootJsonData /// /// Gets or sets pthread pool size. /// - public object pthreadPoolSize { get; set; } + public int pthreadPoolSize { get; set; } } public class ResourcesData diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 739aa6c26a61c3..70c065e5152881 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -295,7 +295,7 @@ protected override bool ExecuteInternal() } else if (PThreadPoolSize > -1) { - extraConfiguration["pthreadPoolSize"] = PThreadPoolSize; + config.pthreadPoolSize = PThreadPoolSize; } foreach (ITaskItem extra in ExtraConfig ?? Enumerable.Empty()) @@ -308,8 +308,6 @@ protected override bool ExecuteInternal() config.environmentVariables = valueObject; else if (name == "diagnosticTracing") config.diagnosticTracing = valueObject; - else if (name == "pthreadPoolSize") - config.pthreadPoolSize = valueObject; else extraConfiguration[name] = valueObject; } From 33843cbe8b23d4febab4182cc50709c0b1e37b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 13:54:00 +0200 Subject: [PATCH 25/77] Fix default globalization --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 70c065e5152881..4c194a03567b1f 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -72,7 +72,7 @@ protected override bool ExecuteInternal() { config = new(), entryAssembly = MainAssemblyName, - icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.Sharded + icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.All }; // Create app From 7f2a16ec14ba199c78928759bac77e7c64e57f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 14:04:25 +0200 Subject: [PATCH 26/77] Fix virtualPath for VFS entries --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 31a7179217fa7a..545b2fb74bf329 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -187,6 +187,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl resolvedUrl: appendUniqueQuery(loaderHelpers.locateFile(name)), hash: resources.vfs[virtualPath][name], behavior: "vfs", + virtualPath }; assets.push(asset); } From 4a398576139923529c2d3a54cc2d4805277ce17d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 14:18:29 +0200 Subject: [PATCH 27/77] Share BootJsonData --- .../BootJsonData.cs | 31 ++- .../GenerateWasmBootJson.cs | 4 +- src/tasks/WasmAppBuilder/BootJsonData.cs | 184 ------------------ .../WasmAppBuilder/WasmAppBuilder.csproj | 1 + 4 files changed, 32 insertions(+), 188 deletions(-) delete mode 100644 src/tasks/WasmAppBuilder/BootJsonData.cs 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 282d5cf6d0a580..c5d2e8e28f170b 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -7,6 +7,8 @@ namespace Microsoft.NET.Sdk.WebAssembly; +#nullable disable + /// /// Defines the structure of a Blazor boot JSON file /// @@ -68,10 +70,30 @@ public class BootJsonData /// Gets or sets configuration extensions. /// public Dictionary> extensions { get; set; } + + /// + /// Gets or sets environment variables. + /// + public object environmentVariables { get; set; } + + /// + /// Gets or sets diagnostic tracing. + /// + public object diagnosticTracing { get; set; } + + /// + /// Gets or sets pthread pool size. + /// + public int pthreadPoolSize { get; set; } } public class ResourcesData { + /// + /// Gets a hash of all resources + /// + public string hash { get; set; } + /// /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. /// @@ -119,6 +141,9 @@ public class ResourcesData [DataMember(EmitDefaultValue = false)] public Dictionary runtimeAssets { get; set; } + [DataMember(EmitDefaultValue = false)] + public Dictionary vfs { get; set; } + } public enum ICUDataMode : int @@ -144,14 +169,16 @@ public enum ICUDataMode : int /// Load custom icu file provided by the developer. /// Custom = 3, + + Hybrid = 4 } [DataContract] public class AdditionalAsset { [DataMember(Name = "hash")] - public string Hash { get; set; } + public string hash { get; set; } [DataMember(Name = "behavior")] - public string Behavior { get; set; } + public string behavior { get; set; } } 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 6a21c2886c5b1d..454f13cea17be0 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -328,8 +328,8 @@ private void AddToAdditionalResources(ITaskItem resource, Dictionary; - -namespace Microsoft.NET.Sdk.WebAssembly; - -#nullable disable - -/// -/// Defines the structure of a Blazor boot JSON file -/// -public class BootJsonData -{ - /// - /// Gets the name of the assembly with the application entry point - /// - public string entryAssembly { get; set; } - - /// - /// Gets the set of resources needed to boot the application. This includes the transitive - /// closure of .NET assemblies (including the entrypoint assembly), the dotnet.wasm file, - /// and any PDBs to be loaded. - /// - /// Within , dictionary keys are resource names, - /// and values are SHA-256 hashes formatted in prefixed base-64 style (e.g., 'sha256-abcdefg...') - /// as used for subresource integrity checking. - /// - public ResourcesData resources { get; set; } = new ResourcesData(); - - /// - /// Gets a value that determines whether to enable caching of the - /// inside a CacheStorage instance within the browser. - /// - public bool cacheBootResources { get; set; } - - /// - /// Gets a value that determines if this is a debug build. - /// - public bool debugBuild { get; set; } - - /// - /// Gets a value that determines if the linker is enabled. - /// - public bool linkerEnabled { get; set; } - - /// - /// Config files for the application - /// - public List config { get; set; } - - /// - /// Gets or sets the that determines how icu files are loaded. - /// - public ICUDataMode icuDataMode { get; set; } - - /// - /// Gets or sets a value that determines if the caching startup memory is enabled. - /// - public bool? startupMemoryCache { get; set; } - - /// - /// Gets a value for mono runtime options. - /// - public string[] runtimeOptions { get; set; } - - /// - /// Gets or sets configuration extensions. - /// - public Dictionary> extensions { get; set; } - - /// - /// Gets or sets environment variables. - /// - public object environmentVariables { get; set; } - - /// - /// Gets or sets diagnostic tracing. - /// - public object diagnosticTracing { get; set; } - - /// - /// Gets or sets pthread pool size. - /// - public int pthreadPoolSize { get; set; } -} - -public class ResourcesData -{ - /// - /// Gets a hash of all resources - /// - public string hash { get; set; } - - /// - /// .NET Wasm runtime resources (dotnet.wasm, dotnet.js) etc. - /// - public ResourceHashesByNameDictionary runtime { get; set; } = new ResourceHashesByNameDictionary(); - - /// - /// "assembly" (.dll) resources - /// - public ResourceHashesByNameDictionary assembly { get; set; } = new ResourceHashesByNameDictionary(); - - /// - /// "debug" (.pdb) resources - /// - [DataMember(EmitDefaultValue = false)] - public ResourceHashesByNameDictionary pdb { get; set; } - - /// - /// localization (.satellite resx) resources - /// - [DataMember(EmitDefaultValue = false)] - public Dictionary satelliteResources { get; set; } - - /// - /// Assembly (.dll) resources that are loaded lazily during runtime - /// - [DataMember(EmitDefaultValue = false)] - public ResourceHashesByNameDictionary lazyAssembly { get; set; } - - /// - /// JavaScript module initializers that Blazor will be in charge of loading. - /// - [DataMember(EmitDefaultValue = false)] - public ResourceHashesByNameDictionary libraryInitializers { get; set; } - - /// - /// Extensions created by users customizing the initialization process. The format of the file(s) - /// is up to the user. - /// - [DataMember(EmitDefaultValue = false)] - public Dictionary extensions { get; set; } - - /// - /// Additional assets that the runtime consumes as part of the boot process. - /// - [DataMember(EmitDefaultValue = false)] - public Dictionary runtimeAssets { get; set; } - - [DataMember(EmitDefaultValue = false)] - public Dictionary vfs { get; set; } - -} - -public enum ICUDataMode : int -{ - // Note that the numeric values are serialized and used in JS code, so don't change them without also updating the JS code - - /// - /// Load optimized icu data file based on the user's locale - /// - Sharded = 0, - - /// - /// Use the combined icudt.dat file - /// - All = 1, - - /// - /// Do not load any icu data files. - /// - Invariant = 2, - - /// - /// Load custom icu file provided by the developer. - /// - Custom = 3, - - Hybrid = 4 -} - -[DataContract] -public class AdditionalAsset -{ - [DataMember(Name = "hash")] - public string hash { get; set; } - - [DataMember(Name = "behavior")] - public string behavior { get; set; } -} diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj b/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj index 320586d8693944..a873b4d69f214e 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj @@ -19,6 +19,7 @@ + From 293d2704313c725a49ff9fb4b36ea3b46284e3ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 30 May 2023 14:30:08 +0200 Subject: [PATCH 28/77] Call setupModuleForBlazor on web. Drop disableDotnet6Compatibility because it's part of the blazor codebase --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 545b2fb74bf329..d7c302883b9505 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -5,7 +5,7 @@ import type { DotnetModuleInternal, MonoConfigInternal } from "../../types/inter import type { AssetBehaviours, AssetEntry, LoadingResource, WebAssemblyBootResourceType, WebAssemblyStartOptions } from "../../types"; import type { BootJsonData } from "../../types/blazor"; -import { INTERNAL, loaderHelpers } from "../globals"; +import { ENVIRONMENT_IS_WEB, INTERNAL, loaderHelpers } from "../globals"; import { BootConfigResult } from "./BootConfig"; import { WebAssemblyResourceLoader } from "./WebAssemblyResourceLoader"; import { hasDebuggingEnabled } from "./_Polyfill"; @@ -17,12 +17,15 @@ export async function loadBootConfig(config: MonoConfigInternal, module: DotnetM const bootConfigPromise = BootConfigResult.initAsync(config.startupOptions?.loadBootResource, config.applicationEnvironment); const bootConfigResult: BootConfigResult = await bootConfigPromise; await initializeBootConfig(bootConfigResult, module, config.startupOptions); - setupModuleForBlazor(module); } export async function initializeBootConfig(bootConfigResult: BootConfigResult, module: DotnetModuleInternal, startupOptions?: Partial) { INTERNAL.resourceLoader = resourceLoader = await WebAssemblyResourceLoader.initAsync(bootConfigResult.bootConfig, startupOptions ?? {}); mapBootConfigToMonoConfig(loaderHelpers.config, bootConfigResult.applicationEnvironment); + + if (ENVIRONMENT_IS_WEB) { + setupModuleForBlazor(module); + } } let resourcesLoaded = 0; @@ -72,7 +75,6 @@ export function setupModuleForBlazor(module: DotnetModuleInternal) { }; loaderHelpers.downloadResource = downloadResource; // polyfills were already assigned - module.disableDotnet6Compatibility = false; } function appendUniqueQuery(attemptUrl: string): string { From c08752def4e0afadd637bfae437a49389c076126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 31 May 2023 10:40:50 +0200 Subject: [PATCH 29/77] WBT fix paths --- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index da976b2eed2442..561cc8ae7ca59e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -728,16 +728,16 @@ void AssertIcuAssets() // predefined ICU name can be identical with the icu files from runtime pack switch (predefinedIcudt) { - case "icudt.dat": + case "_framework/icudt.dat": expectFULL = true; break; - case "icudt_EFIGS.dat": + case "_framework/icudt_EFIGS.dat": expectEFIGS = true; break; - case "icudt_CJK.dat": + case "_framework/icudt_CJK.dat": expectCJK = true; break; - case "icudt_no_CJK.dat": + case "_framework/icudt_no_CJK.dat": expectNOCJK = true; break; } @@ -749,29 +749,29 @@ void AssertIcuAssets() expectNOCJK = true; break; } - AssertFilesExist(bundleDir, new[] { "icudt.dat" }, expectToExist: expectFULL); - AssertFilesExist(bundleDir, new[] { "icudt_EFIGS.dat" }, expectToExist: expectEFIGS); - AssertFilesExist(bundleDir, new[] { "icudt_CJK.dat" }, expectToExist: expectCJK); - AssertFilesExist(bundleDir, new[] { "icudt_no_CJK.dat" }, expectToExist: expectNOCJK); + AssertFilesExist(bundleDir, new[] { "_framework/icudt.dat" }, expectToExist: expectFULL); + AssertFilesExist(bundleDir, new[] { "_framework/icudt_EFIGS.dat" }, expectToExist: expectEFIGS); + AssertFilesExist(bundleDir, new[] { "_framework/icudt_CJK.dat" }, expectToExist: expectCJK); + AssertFilesExist(bundleDir, new[] { "_framework/icudt_no_CJK.dat" }, expectToExist: expectNOCJK); } } protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack, string targetFramework) { AssertFile(Path.Combine(s_buildEnv.GetRuntimeNativeDir(targetFramework), "dotnet.native.wasm"), - Path.Combine(bundleDir, "dotnet.native.wasm"), + Path.Combine(bundleDir, "_framework/dotnet.native.wasm"), "Expected dotnet.native.wasm to be same as the runtime pack", same: fromRuntimePack); AssertFile(Path.Combine(s_buildEnv.GetRuntimeNativeDir(targetFramework), "dotnet.native.js"), - Path.Combine(bundleDir, "dotnet.native.js"), + Path.Combine(bundleDir, "_framework/dotnet.native.js"), "Expected dotnet.native.js to be same as the runtime pack", same: fromRuntimePack); } protected static void AssertDotNetJsSymbols(string bundleDir, bool fromRuntimePack, string targetFramework) => AssertFile(Path.Combine(s_buildEnv.GetRuntimeNativeDir(targetFramework), "dotnet.native.js.symbols"), - Path.Combine(bundleDir, "dotnet.native.js.symbols"), + Path.Combine(bundleDir, "_framework/dotnet.native.js.symbols"), same: fromRuntimePack); protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null) From 724cd781755364dc7a4630211beccd0fcd445b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 1 Jun 2023 12:03:22 +0200 Subject: [PATCH 30/77] Globalization --- src/mono/wasm/build/WasmApp.targets | 3 +++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 6a5d91ce57c626..c774711f123fbf 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -334,6 +334,7 @@ <_HasDotnetNativeJs Condition="'%(WasmNativeAsset.FileName)%(WasmNativeAsset.Extension)' == 'dotnet.native.js'">true <_WasmIcuDataFileName Condition="'$(WasmIcuDataFileName)' != '' and Exists('$(WasmIcuDataFileName)')">$(WasmIcuDataFileName) <_WasmIcuDataFileName Condition="'$(WasmIcuDataFileName)' != '' and !Exists('$(WasmIcuDataFileName)')">$(MicrosoftNetCoreAppRuntimePackRidNativeDir)$(WasmIcuDataFileName) + false @@ -403,6 +404,8 @@ IncludeThreadsWorker="$(_WasmAppIncludeThreadsWorker)" PThreadPoolSize="$(_WasmPThreadPoolSize)" UseWebcil="$(WasmEnableWebcil)" + WasmIncludeFullIcuData="$(WasmIncludeFullIcuData)" + WasmIcuDataFileName="$(WasmIcuDataFileName)" > diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 4c194a03567b1f..145234028e85a4 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -23,6 +23,8 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask public bool IncludeThreadsWorker { get; set; } public int PThreadPoolSize { get; set; } public bool UseWebcil { get; set; } + public bool WasmIncludeFullIcuData { get; set; } + public string? WasmIcuDataFileName { get; set; } // // Extra json elements to add to _framework/blazor.boot.json @@ -72,7 +74,15 @@ protected override bool ExecuteInternal() { config = new(), entryAssembly = MainAssemblyName, - icuDataMode = InvariantGlobalization ? ICUDataMode.Invariant : HybridGlobalization ? ICUDataMode.Hybrid : ICUDataMode.All + icuDataMode = InvariantGlobalization + ? ICUDataMode.Invariant + : !string.IsNullOrEmpty(WasmIcuDataFileName) + ? ICUDataMode.Custom + : HybridGlobalization + ? ICUDataMode.Hybrid + : WasmIncludeFullIcuData + ? ICUDataMode.All + : ICUDataMode.Sharded }; // Create app From b58f61b38e15d88fd2b406a11952755a31036dfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 1 Jun 2023 12:07:18 +0200 Subject: [PATCH 31/77] test-main arg --no-exit --- src/mono/wasm/test-main.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.js index ed2e5c1adc4ddf..b0fd50f9a1459f 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.js @@ -103,6 +103,7 @@ function initRunArgs(runArgs) { // default'ing to true for tests, unless debugging runArgs.forwardConsole = runArgs.forwardConsole === undefined ? !runArgs.debugging : runArgs.forwardConsole; runArgs.memorySnapshot = runArgs.memorySnapshot === undefined ? true : runArgs.memorySnapshot; + runArgs.exit = runArgs.exit === undefined ? true : runArgs.exit; return runArgs; } @@ -136,6 +137,8 @@ function processArguments(incomingArguments, runArgs) { runArgs.forwardConsole = false; } else if (currentArg == "--no-memory-snapshot") { runArgs.memorySnapshot = false; + } else if (currentArg == "--no-exit") { + runArgs.exit = false; } else if (currentArg.startsWith("--fetch-random-delay=")) { const arg = currentArg.substring("--fetch-random-delay=".length); if (is_browser) { @@ -336,7 +339,10 @@ async function run() { // this is subsequent run with the actual tests. It will use whatever was cached in the previous run. // This way, we are testing that the cached version works. - mono_exit = exit; + mono_exit = (code, reason) => { + if (runArgs.exit) + exit(code, reason); + }; if (runArgs.applicationArguments.length == 0) { mono_exit(1, "Missing required --run argument"); From c385a62f1049b3e20140ad00e9c11496f2cbbeb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 1 Jun 2023 14:11:28 +0200 Subject: [PATCH 32/77] Fix MonoJsTests --- src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs b/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs index 46e054e8d85c2d..9e365c05589260 100644 --- a/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs +++ b/src/mono/wasm/debugger/DebuggerTestSuite/MonoJsTests.cs @@ -94,8 +94,8 @@ public async Task DuplicateAssemblyLoadedEventNotLoadedFromBundle(bool load_pdb, public async Task DuplicateAssemblyLoadedEventForAssemblyFromBundle(bool load_pdb, int expected_count) => await AssemblyLoadedEventTest( "debugger-test", - Path.Combine(DebuggerTestAppPath, "managed/debugger-test.dll"), - load_pdb ? Path.Combine(DebuggerTestAppPath, "managed/debugger-test.pdb") : null, + Path.Combine(DebuggerTestAppPath, "_framework/debugger-test.dll"), + load_pdb ? Path.Combine(DebuggerTestAppPath, "_framework/debugger-test.pdb") : null, "/debugger-test.cs", expected_count ); From 29c52876d6072685510b9a6e0435684e9d404e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 1 Jun 2023 14:13:19 +0200 Subject: [PATCH 33/77] Fix wbt managed --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 561cc8ae7ca59e..35f49c6eefbea1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -687,7 +687,7 @@ protected static void AssertBasicAppBundle(string bundleDir, AssertFilesExist(bundleDir, new[] { "run-v8.sh" }, expectToExist: hasV8Script); AssertIcuAssets(); - string managedDir = Path.Combine(bundleDir, "managed"); + string managedDir = Path.Combine(bundleDir, "_framework"); string bundledMainAppAssembly = useWebcil ? $"{projectName}{WebcilInWasmExtension}" : $"{projectName}.dll"; AssertFilesExist(managedDir, new[] { bundledMainAppAssembly }); From 29eec4058554fab7de3d8df778f6266888e46a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 12:16:19 +0200 Subject: [PATCH 34/77] loadAllSatelliteResources on startup --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 13 +++++++++++++ src/mono/wasm/runtime/types/internal.ts | 3 ++- src/mono/wasm/test-main.js | 5 ++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index d7c302883b9505..3d590a2ee5044a 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -171,6 +171,19 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl assets.push(asset); } + if (moduleConfig.loadAllSatelliteResources && resources.satelliteResources) { + for (const culture in resources.satelliteResources) { + for (const name in resources.satelliteResources[culture]) { + assets.push({ + name, + culture, + behavior: "resource", + hash: resources.satelliteResources[culture][name], + }); + } + } + } + for (let i = 0; i < resourceLoader.bootConfig.config.length; i++) { const config = resourceLoader.bootConfig.config[i]; if (config === "appsettings.json" || config === `appsettings.${applicationEnvironment}.json`) { diff --git a/src/mono/wasm/runtime/types/internal.ts b/src/mono/wasm/runtime/types/internal.ts index f9a16235228ca2..5a521689d1348e 100644 --- a/src/mono/wasm/runtime/types/internal.ts +++ b/src/mono/wasm/runtime/types/internal.ts @@ -76,7 +76,8 @@ export type MonoConfigInternal = MonoConfig & { forwardConsoleLogsToWS?: boolean, asyncFlushOnExit?: boolean exitAfterSnapshot?: number, - startupOptions?: Partial + startupOptions?: Partial, + loadAllSatelliteResources?: boolean }; export type RunArguments = { diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.js index b0fd50f9a1459f..ca96bfc7c5bc84 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.js @@ -261,7 +261,10 @@ function configureRuntime(dotnet, runArgs) { .withDiagnosticTracing(runArgs.diagnosticTracing) .withExitOnUnhandledError() .withExitCodeLogging() - .withElementOnExit(); + .withElementOnExit() + .withConfig({ + loadAllSatelliteResources: true + }); if (is_node) { dotnet From d005783a120e2ab00d341b32cd3d190b0f300ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 12:52:21 +0200 Subject: [PATCH 35/77] Remote sources --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 4 ++++ src/mono/wasm/runtime/types/blazor.ts | 1 + .../BootJsonData.cs | 3 +++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 9 ++++----- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 3d590a2ee5044a..922d03b9026f01 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -93,6 +93,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.applicationEnvironment = applicationEnvironment; + moduleConfig.remoteSources = resourceLoader.bootConfig.resources.remoteSources; moduleConfig.assetsHash = resourceLoader.bootConfig.resources.hash; moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; @@ -147,6 +148,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl let hasIcuData = false; for (const name in resources.runtime) { const behavior = behaviorByName(name) as any; + let loadRemote = false; if (behavior === "icu") { if (resourceLoader.bootConfig.icuDataMode === ICUDataMode.Invariant) { continue; @@ -154,6 +156,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl if (name !== icuDataResourceName) { continue; } + loadRemote = true; hasIcuData = true; } else if (behavior === "js-module-dotnet") { continue; @@ -167,6 +170,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl resolvedUrl, hash: resources.runtime[name], behavior, + loadRemote }; assets.push(asset); } diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 8473ef6b558d72..6213c6818f203f 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -32,6 +32,7 @@ export interface ResourceGroups { readonly extensions?: BootJsonDataExtension readonly runtimeAssets: ExtendedResourceList; readonly vfs?: { [virtualPath: string]: ResourceList }; + readonly remoteSources?: string[]; } export type ResourceList = { [name: string]: string }; 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 c5d2e8e28f170b..b69957a767b5c3 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -144,6 +144,9 @@ public class ResourcesData [DataMember(EmitDefaultValue = false)] public Dictionary vfs { get; set; } + [DataMember(EmitDefaultValue = false)] + public List remoteSources { get; set; } + } public enum ICUDataMode : int diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 145234028e85a4..ad93fb15e025b4 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -283,7 +283,6 @@ protected override bool ExecuteInternal() return false; } - // TODO MF: LoadRemote config.resources.runtime[Path.GetFileName(idfn)] = Utils.ComputeIntegrity(idfn); } } @@ -291,10 +290,10 @@ protected override bool ExecuteInternal() if (RemoteSources?.Length > 0) { - // TODO MF: RemoteSources - //foreach (var source in RemoteSources) - // if (source != null && source.ItemSpec != null) - // config.RemoteSources.Add(source.ItemSpec); + config.resources.remoteSources = new(); + foreach (var source in RemoteSources) + if (source != null && source.ItemSpec != null) + config.resources.remoteSources.Add(source.ItemSpec); } var extraConfiguration = new Dictionary(); From 290a78ebe17f2322fa98e6f562f7b0918186625a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 2 Jun 2023 14:47:05 +0200 Subject: [PATCH 36/77] Fix environment variables --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 10 ++++++++-- src/mono/wasm/runtime/types/blazor.ts | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 922d03b9026f01..882f84ac07e104 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -89,7 +89,12 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl const resources = resourceLoader.bootConfig.resources; const assets: AssetEntry[] = []; - const environmentVariables: any = {}; + const environmentVariables: any = { + // From boot config + ...(resourceLoader.bootConfig.environmentVariables || {}), + // From JavaScript + ...(moduleConfig.environmentVariables || {}) + }; moduleConfig.applicationEnvironment = applicationEnvironment; @@ -97,7 +102,6 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.assetsHash = resourceLoader.bootConfig.resources.hash; moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; - moduleConfig.environmentVariables = environmentVariables; moduleConfig.debugLevel = hasDebuggingEnabled(resourceLoader.bootConfig) ? 1 : 0; moduleConfig.maxParallelDownloads = 1000000; // disable throttling parallel downloads moduleConfig.enableDownloadRetry = false; // disable retry downloads @@ -108,6 +112,8 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl ...resourceLoader.bootConfig, }); + moduleConfig.environmentVariables = environmentVariables; + if (resourceLoader.bootConfig.startupMemoryCache !== undefined) { moduleConfig.startupMemoryCache = resourceLoader.bootConfig.startupMemoryCache; } diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 6213c6818f203f..2c660f6f313bdb 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -13,6 +13,9 @@ export interface BootJsonData { readonly icuDataMode: ICUDataMode; readonly startupMemoryCache: boolean | undefined; readonly runtimeOptions: string[] | undefined; + readonly environmentVariables?: { [name: string]: string }; + readonly diagnosticTracing?: { [name: string]: string }; + readonly pthreadPoolSize: number; // These properties are tacked on, and not found in the boot.json file modifiableAssemblies: string | null; From 61a7ca4dc1fb4d4fe5292c27f0fe995c7a680058 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 5 Jun 2023 10:34:30 +0200 Subject: [PATCH 37/77] Fix relative path to the imported modules in JS tests --- .../JavaScript/JavaScriptTestHelper.cs | 12 ++++++------ .../InteropServices/JavaScript/SecondRuntimeTest.cs | 4 ++-- .../InteropServices/JavaScript/SecondRuntimeTest.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs index 2a06708017969f..fea5cc4a804893 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JavaScriptTestHelper.cs @@ -68,7 +68,7 @@ public static void Optimized0V() [JSExport] public static void Optimized1V(int a1) { - optimizedReached+= a1; + optimizedReached += a1; } [JSImport("invoke1V", "JavaScriptTestHelper")] public static partial void invoke1V(int a1); @@ -85,8 +85,8 @@ public static int Optimized1R(int a1) [JSExport] public static int Optimized2R(int a1, int a2) { - optimizedReached += a1+ a2; - return a1 + a2 +1; + optimizedReached += a1 + a2; + return a1 + a2 + 1; } [JSImport("invoke2R", "JavaScriptTestHelper")] public static partial int invoke2R(int a1, int a2); @@ -997,7 +997,7 @@ public static async Task InitializeAsync() if (_module == null) { // Log("JavaScriptTestHelper.mjs importing"); - _module = await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs"); + _module = await JSHost.ImportAsync("JavaScriptTestHelper", "../JavaScriptTestHelper.mjs"); await Setup(); // Log("JavaScriptTestHelper.mjs imported"); } @@ -1010,7 +1010,7 @@ namespace JavaScriptTestHelperNamespace public partial class JavaScriptTestHelper { [System.Runtime.InteropServices.JavaScript.JSExport] - public static string EchoString(string message) + public static string EchoString(string message) { return message + "11"; } @@ -1019,7 +1019,7 @@ private partial class NestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] public static string EchoString(string message) => message + "12"; - + private partial class DoubleNestedClass { [System.Runtime.InteropServices.JavaScript.JSExport] diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.cs index 6b65ff64b1eefe..7985ec95f116fb 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.cs @@ -12,9 +12,9 @@ namespace System.Runtime.InteropServices.JavaScript.Tests public partial class SecondRuntimeTest { [ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNodeJS))] - public static async Task RunSecondRuntimeAndTestStaticState() + public static async Task RunSecondRuntimeAndTestStaticState() { - await JSHost.ImportAsync("SecondRuntimeTest", "./SecondRuntimeTest.js"); + await JSHost.ImportAsync("SecondRuntimeTest", "../SecondRuntimeTest.js"); Interop.State = 42; var state2 = await Interop.RunSecondRuntimeAndTestStaticState(); diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.js b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.js index fa0b5d9f52eb8b..4230d51d1b545c 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.js +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/SecondRuntimeTest.js @@ -1,5 +1,5 @@ export async function runSecondRuntimeAndTestStaticState() { - const { dotnet: dotnet2 } = await import('./dotnet.js?instance=2'); + const { dotnet: dotnet2 } = await import('./_framework/dotnet.js?instance=2'); const runtime2 = await dotnet2 .withStartupMemoryCache(false) .withConfig({ From 76864f13d3f44403ad4a8def3bee98db9b4fd0dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 5 Jun 2023 11:53:52 +0200 Subject: [PATCH 38/77] Fix hybrid. These changes will come from a different PR --- src/mono/wasm/build/WasmApp.targets | 10 ++++++---- src/mono/wasm/runtime/dotnet.d.ts | 11 ++++++++++- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 7 ++++++- src/mono/wasm/runtime/types/blazor.ts | 3 ++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index c774711f123fbf..81ae32515998b2 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -356,10 +356,12 @@ - <_IcuAvailableDataFiles Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)icudt_*" /> - - - + <_HybridGlobalizationDataFiles Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)icudt_hybrid.dat"/> + <_IcuAvailableDataFiles Include="$(MicrosoftNetCoreAppRuntimePackRidNativeDir)icudt_*" Exclude="@(_HybridGlobalizationDataFiles)"/> + + + + diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index fe46f28efaf48a..d44b4e9f08abcf 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -315,6 +315,13 @@ interface BootJsonData { readonly icuDataMode: ICUDataMode; readonly startupMemoryCache: boolean | undefined; readonly runtimeOptions: string[] | undefined; + readonly environmentVariables?: { + [name: string]: string; + }; + readonly diagnosticTracing?: { + [name: string]: string; + }; + readonly pthreadPoolSize: number; modifiableAssemblies: string | null; aspnetCoreBrowserTools: string | null; } @@ -336,6 +343,7 @@ interface ResourceGroups { readonly vfs?: { [virtualPath: string]: ResourceList; }; + readonly remoteSources?: string[]; } type ResourceList = { [name: string]: string; @@ -350,7 +358,8 @@ declare enum ICUDataMode { Sharded = 0, All = 1, Invariant = 2, - Custom = 3 + Custom = 3, + Hybrid = 4 } declare global { diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 882f84ac07e104..ee145031563087 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -252,8 +252,13 @@ function getICUResourceName(bootConfig: BootJsonData, culture: string | undefine } } - const combinedICUResourceName = "icudt.dat"; + if (bootConfig.icuDataMode === ICUDataMode.Hybrid) { + const reducedICUResourceName = "icudt_hybrid.dat"; + return reducedICUResourceName; + } + if (!culture || bootConfig.icuDataMode === ICUDataMode.All) { + const combinedICUResourceName = "icudt.dat"; return combinedICUResourceName; } diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 2c660f6f313bdb..321bb3bf017aab 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -50,5 +50,6 @@ export enum ICUDataMode { Sharded = 0, All = 1, Invariant = 2, - Custom = 3 + Custom = 3, + Hybrid = 4 } \ No newline at end of file From 8efa39c09081bd6f8ef54feac788b7ad1ef19f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 5 Jun 2023 12:53:03 +0200 Subject: [PATCH 39/77] Threading --- src/mono/sample/wasm/browser-threads-minimal/Program.cs | 4 ++-- src/mono/sample/wasm/browser-threads-minimal/main.js | 8 +++++--- src/mono/wasm/runtime/pthreads/browser/index.ts | 2 +- .../BootJsonData.cs | 2 +- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mono/sample/wasm/browser-threads-minimal/Program.cs b/src/mono/sample/wasm/browser-threads-minimal/Program.cs index 0e9e5584c7c9d9..734566b260a23c 100644 --- a/src/mono/sample/wasm/browser-threads-minimal/Program.cs +++ b/src/mono/sample/wasm/browser-threads-minimal/Program.cs @@ -54,7 +54,7 @@ public static async Task TestCallSetTimeoutOnWorker() Console.WriteLine ($"XYZ: Main Thread caught task tid:{Thread.CurrentThread.ManagedThreadId}"); } - const string fetchhelper = "./fetchelper.js"; + const string fetchhelper = "../fetchhelper.js"; [JSImport("responseText", fetchhelper)] private static partial Task FetchHelperResponseText(JSObject response, int delayMs); @@ -66,7 +66,7 @@ public static async Task FetchBackground(string url) var t = Task.Run(async () => { Console.WriteLine($"smoke: FetchBackground 2 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); - var x=JSHost.ImportAsync(fetchhelper, "./fetchhelper.js"); + var x = JSHost.ImportAsync(fetchhelper, "../fetchhelper.js"); Console.WriteLine($"smoke: FetchBackground 3A ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); using var import = await x; Console.WriteLine($"smoke: FetchBackground 3B ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); diff --git a/src/mono/sample/wasm/browser-threads-minimal/main.js b/src/mono/sample/wasm/browser-threads-minimal/main.js index d6df4d23b9683e..9e58d916a6479b 100644 --- a/src/mono/sample/wasm/browser-threads-minimal/main.js +++ b/src/mono/sample/wasm/browser-threads-minimal/main.js @@ -7,7 +7,9 @@ const assemblyName = "Wasm.Browser.Threads.Minimal.Sample.dll"; try { - const { setModuleImports, getAssemblyExports, runMain } = await dotnet + const resolveUrl = (relativeUrl) => (new URL(relativeUrl, window.location.href)).toString() + + const { getAssemblyExports, runMain } = await dotnet .withEnvironmentVariable("MONO_LOG_LEVEL", "debug") .withElementOnExit() .withExitCodeLogging() @@ -24,7 +26,7 @@ try { console.log("smoke: TestCallSetTimeoutOnWorker done"); console.log("smoke: running FetchBackground(blurst.txt)"); - let s = await exports.Sample.Test.FetchBackground("./blurst.txt"); + let s = await exports.Sample.Test.FetchBackground(resolveUrl("./blurst.txt")); console.log("smoke: FetchBackground(blurst.txt) done"); if (!s.startsWith("It was the best of times, it was the blurst of times.")) { const msg = `Unexpected FetchBackground result ${s}`; @@ -33,7 +35,7 @@ try { } console.log("smoke: running FetchBackground(missing)"); - s = await exports.Sample.Test.FetchBackground("./missing.txt"); + s = await exports.Sample.Test.FetchBackground(resolveUrl("./missing.txt")); console.log("smoke: FetchBackground(missing) done"); if (s !== "not-ok") { const msg = `Unexpected FetchBackground(missing) result ${s}`; diff --git a/src/mono/wasm/runtime/pthreads/browser/index.ts b/src/mono/wasm/runtime/pthreads/browser/index.ts index 1369a3fdebe3c7..b9dbdaeedbb07a 100644 --- a/src/mono/wasm/runtime/pthreads/browser/index.ts +++ b/src/mono/wasm/runtime/pthreads/browser/index.ts @@ -117,7 +117,7 @@ export function afterLoadWasmModuleToWorker(worker: Worker): void { export function preAllocatePThreadWorkerPool(defaultPthreadPoolSize: number, config: MonoConfig): void { const poolSizeSpec = config?.pthreadPoolSize; let n: number; - if (poolSizeSpec === undefined) { + if (poolSizeSpec === undefined || poolSizeSpec === null) { n = defaultPthreadPoolSize; } else { mono_assert(typeof poolSizeSpec === "number", "pthreadPoolSize must be a number"); 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 b69957a767b5c3..d38d31dcb3a8c1 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -84,7 +84,7 @@ public class BootJsonData /// /// Gets or sets pthread pool size. /// - public int pthreadPoolSize { get; set; } + public int? pthreadPoolSize { get; set; } } public class ResourcesData From 3e9dd79b0321c720561e738ea60a5abbedc2a07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 6 Jun 2023 11:53:14 +0200 Subject: [PATCH 40/77] Fix imports --- .../InteropServices/JavaScript/TimerTests.cs | 2 +- .../JavaScript/JSImportExportTest.cs | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System/Runtime/InteropServices/JavaScript/TimerTests.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System/Runtime/InteropServices/JavaScript/TimerTests.cs index 3a12086a93aab1..9536de4e5b3cbb 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System/Runtime/InteropServices/JavaScript/TimerTests.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.Legacy.UnitTests/System/Runtime/InteropServices/JavaScript/TimerTests.cs @@ -90,7 +90,7 @@ public async Task InitializeAsync() { if (_module == null) { - _module = await JSHost.ImportAsync("Timers", "./timers.mjs"); + _module = await JSHost.ImportAsync("Timers", "../timers.mjs"); } } diff --git a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs index a66720c9a88fd5..5f16d507fa31e5 100644 --- a/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs +++ b/src/libraries/System.Runtime.InteropServices.JavaScript/tests/System.Runtime.InteropServices.JavaScript.UnitTests/System/Runtime/InteropServices/JavaScript/JSImportExportTest.cs @@ -22,8 +22,8 @@ public unsafe void StructSize() [Fact] public async Task MultipleImportAsync() { - var first = await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs"); - var second = await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs"); + var first = await JSHost.ImportAsync("JavaScriptTestHelper", "../JavaScriptTestHelper.mjs"); + var second = await JSHost.ImportAsync("JavaScriptTestHelper", "../JavaScriptTestHelper.mjs"); Assert.NotNull(first); Assert.NotNull(second); Assert.Equal("object", first.GetTypeOfProperty("instance")); @@ -36,12 +36,12 @@ public async Task MultipleImportAsync() public async Task CancelableImportAsync() { var cts = new CancellationTokenSource(); - var exTask = Assert.ThrowsAsync(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs", cts.Token)); + var exTask = Assert.ThrowsAsync(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "../JavaScriptTestHelper.mjs", cts.Token)); cts.Cancel(); var actualEx2 = await exTask; Assert.Equal("OperationCanceledException", actualEx2.Message); - var actualEx = await Assert.ThrowsAsync(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "./JavaScriptTestHelper.mjs", new CancellationToken(true))); + var actualEx = await Assert.ThrowsAsync(async () => await JSHost.ImportAsync("JavaScriptTestHelper", "../JavaScriptTestHelper.mjs", new CancellationToken(true))); Assert.Equal("OperationCanceledException", actualEx.Message); } @@ -300,7 +300,7 @@ public static IEnumerable MarshalObjectArrayCases() yield return new object[] { new object[] { "JSData" } }; // special cased, so we call createData in the test itself yield return new object[] { new object[] { new byte[] { }, new int[] { }, new double[] { }, new string[] { }, new object[] { } } }; yield return new object[] { new object[] { new byte[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new string[] { "a", "b", "c" }, new object[] { } } }; - yield return new object[] { new object[] { new object[] { new byte[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new string[] { "a", "b", "c" } , new object(), new SomethingRef(), new SomethingStruct(), new Exception("test") } } }; + yield return new object[] { new object[] { new object[] { new byte[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, new double[] { 1, 2, 3 }, new string[] { "a", "b", "c" }, new object(), new SomethingRef(), new SomethingStruct(), new Exception("test") } } }; yield return new object[] { new object[] { } }; yield return new object[] { null }; } @@ -317,10 +317,10 @@ public unsafe void JsImportObjectArray(object[]? expected) Assert.Equal(expected, actual); if (expected != null) for (int i = 0; i < expected.Length; i++) - { - var actualI = JavaScriptTestHelper.store_ObjectArray(expected, i); - Assert.Equal(expected[i], actualI); - } + { + var actualI = JavaScriptTestHelper.store_ObjectArray(expected, i); + Assert.Equal(expected[i], actualI); + } } public static IEnumerable MarshalObjectArrayCasesToDouble() @@ -362,7 +362,7 @@ public static IEnumerable MarshalObjectArrayCasesThrow() yield return new object[] { new object[] { (ushort)0 } }; yield return new object[] { new object[] { new SomethingStruct[] { } } }; yield return new object[] { new object[] { new SomethingRef[] { }, } }; - yield return new object[] { new object[] { new ArraySegment(new byte[] { 11 }) , } }; + yield return new object[] { new object[] { new ArraySegment(new byte[] { 11 }), } }; } delegate void dummyDelegate(); static void dummyDelegateA() From 0f4539542aa1ae31a4b9d746f016929446862e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 6 Jun 2023 11:53:28 +0200 Subject: [PATCH 41/77] Fix culture on v8/node --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index ee145031563087..6401d5df141429 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -149,7 +149,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl assets.push(asset); } } - const applicationCulture = resourceLoader.startOptions.applicationCulture || (globalThis.navigator && navigator.languages && navigator.languages[0]); + const applicationCulture = resourceLoader.startOptions.applicationCulture || ENVIRONMENT_IS_WEB ? (navigator.languages && navigator.languages[0]) : Intl.DateTimeFormat().resolvedOptions().locale; const icuDataResourceName = getICUResourceName(resourceLoader.bootConfig, applicationCulture); let hasIcuData = false; for (const name in resources.runtime) { From b137849be88866441580445c35ebfa07f9ae1cbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Jun 2023 13:32:46 +0200 Subject: [PATCH 42/77] Drop enableDownloadRetry=false and maxParallelDownloads --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 6401d5df141429..2128ee4794532d 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -103,8 +103,6 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; moduleConfig.debugLevel = hasDebuggingEnabled(resourceLoader.bootConfig) ? 1 : 0; - moduleConfig.maxParallelDownloads = 1000000; // disable throttling parallel downloads - moduleConfig.enableDownloadRetry = false; // disable retry downloads moduleConfig.mainAssemblyName = resourceLoader.bootConfig.entryAssembly; // FIXME this mix of both formats is ugly temporary hack From c4d3fa0e16fe6d26d6995a1ec0edbc0d2cc598f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Jun 2023 13:44:11 +0200 Subject: [PATCH 43/77] Properly set hybrid globalization --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 2128ee4794532d..20b510be7296cf 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -148,7 +148,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl } } const applicationCulture = resourceLoader.startOptions.applicationCulture || ENVIRONMENT_IS_WEB ? (navigator.languages && navigator.languages[0]) : Intl.DateTimeFormat().resolvedOptions().locale; - const icuDataResourceName = getICUResourceName(resourceLoader.bootConfig, applicationCulture); + const icuDataResourceName = getICUResourceName(resourceLoader.bootConfig, moduleConfig, applicationCulture); let hasIcuData = false; for (const name in resources.runtime) { const behavior = behaviorByName(name) as any; @@ -239,23 +239,26 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl } } -function getICUResourceName(bootConfig: BootJsonData, culture: string | undefined): string { +function getICUResourceName(bootConfig: BootJsonData, moduleConfig: MonoConfigInternal, culture: string | undefined): string { if (bootConfig.icuDataMode === ICUDataMode.Custom) { const icuFiles = Object .keys(bootConfig.resources.runtime) .filter(n => n.startsWith("icudt") && n.endsWith(".dat")); if (icuFiles.length === 1) { + moduleConfig.globalizationMode = "icu"; const customIcuFile = icuFiles[0]; return customIcuFile; } } if (bootConfig.icuDataMode === ICUDataMode.Hybrid) { + moduleConfig.globalizationMode = "hybrid"; const reducedICUResourceName = "icudt_hybrid.dat"; return reducedICUResourceName; } if (!culture || bootConfig.icuDataMode === ICUDataMode.All) { + moduleConfig.globalizationMode = "icu"; const combinedICUResourceName = "icudt.dat"; return combinedICUResourceName; } From c236198db39db694e602474e4dc9d26835603d2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 12 Jun 2023 19:53:21 +0200 Subject: [PATCH 44/77] Fix merging configs --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index 20b510be7296cf..bac3fda3b86987 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -105,6 +105,16 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.debugLevel = hasDebuggingEnabled(resourceLoader.bootConfig) ? 1 : 0; moduleConfig.mainAssemblyName = resourceLoader.bootConfig.entryAssembly; + const anyBootConfig = (resourceLoader.bootConfig as any); + for (const key in resourceLoader.bootConfig) { + if (Object.prototype.hasOwnProperty.call(anyBootConfig, key)) { + if (anyBootConfig[key] === null) { + delete anyBootConfig[key]; + } + + } + } + // FIXME this mix of both formats is ugly temporary hack Object.assign(moduleConfig, { ...resourceLoader.bootConfig, From 5ab1b0b7e5984f40d6586fab8b66d58fc26124eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 10:40:02 +0200 Subject: [PATCH 45/77] Use latest test-main for .NET 8.0 or empty target framework --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index b35b0b807cb0cb..fc904741b823e6 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -386,9 +386,15 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp options.InitProject?.Invoke(); File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents); - File.Copy(Path.Combine(AppContext.BaseDirectory, - options.TargetFramework == "net8.0" ? "test-main.js" : "data/test-main-7.0.js"), - Path.Combine(_projectDir, "test-main.js")); + File.Copy( + Path.Combine( + AppContext.BaseDirectory, + string.IsNullOrEmpty(options.TargetFramework) || options.TargetFramework == "net8.0" + ? "test-main.js" + : "data/test-main-7.0.js" + ), + Path.Combine(_projectDir, "test-main.js") + ); File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); } From 01c6104beb89062d8237d833b451559d0ca8e856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 11:49:46 +0200 Subject: [PATCH 46/77] Feedback --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 3 +-- src/mono/wasm/runtime/types/blazor.ts | 3 +-- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 2 +- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index bac3fda3b86987..fe28a88cd91f1b 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -98,7 +98,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.applicationEnvironment = applicationEnvironment; - moduleConfig.remoteSources = resourceLoader.bootConfig.resources.remoteSources; + moduleConfig.remoteSources = (resourceLoader.bootConfig.resources as any).remoteSources; moduleConfig.assetsHash = resourceLoader.bootConfig.resources.hash; moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; @@ -111,7 +111,6 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl if (anyBootConfig[key] === null) { delete anyBootConfig[key]; } - } } diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 35fed7b08995f1..2b89c6e6983600 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -14,7 +14,7 @@ export interface BootJsonData { readonly startupMemoryCache: boolean | undefined; readonly runtimeOptions: string[] | undefined; readonly environmentVariables?: { [name: string]: string }; - readonly diagnosticTracing?: { [name: string]: string }; + readonly diagnosticTracing?: boolean; readonly pthreadPoolSize: number; // These properties are tacked on, and not found in the boot.json file @@ -35,7 +35,6 @@ export interface ResourceGroups { readonly extensions?: BootJsonDataExtension readonly runtimeAssets: ExtendedResourceList; readonly vfs?: { [virtualPath: string]: ResourceList }; - readonly remoteSources?: string[]; } export type ResourceList = { [name: string]: string }; diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index ad93fb15e025b4..21110aaf32c297 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -316,7 +316,7 @@ protected override bool ExecuteInternal() if (name == "environmentVariables") config.environmentVariables = valueObject; else if (name == "diagnosticTracing") - config.diagnosticTracing = valueObject; + config.diagnosticTracing = valueObject == true || valueObject == bool.TrueString; else extraConfiguration[name] = valueObject; } From b0f7f4d7fb380480eea5b3844bfbafb45920bd65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 12:14:58 +0200 Subject: [PATCH 47/77] Fix WAB --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 21110aaf32c297..571a8b5c91db01 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -314,11 +314,22 @@ protected override bool ExecuteInternal() return false; if (name == "environmentVariables") + { config.environmentVariables = valueObject; + } else if (name == "diagnosticTracing") - config.diagnosticTracing = valueObject == true || valueObject == bool.TrueString; + { + if (valueObject is bool boolValue) + config.diagnosticTracing = boolValue; + else if (valueObject is string stringValue) + config.diagnosticTracing = stringValue == bool.TrueString; + else + throw new LogAsErrorException($"Unsupported value of type '{valueObject?.GetType()?.FullName}' for extra config 'diagnosticTracing'."); + } else + { extraConfiguration[name] = valueObject; + } } if (extraConfiguration.Count > 0) From 7c377fbe0047e30b1734c87328bfda44ad424f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 13:53:33 +0200 Subject: [PATCH 48/77] Fix threads-minimal sample --- .../wasm/browser-threads-minimal/Program.cs | 72 ++++++++++--------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/mono/sample/wasm/browser-threads-minimal/Program.cs b/src/mono/sample/wasm/browser-threads-minimal/Program.cs index a8dfbab526c5e9..dc5fde91da7832 100644 --- a/src/mono/sample/wasm/browser-threads-minimal/Program.cs +++ b/src/mono/sample/wasm/browser-threads-minimal/Program.cs @@ -28,7 +28,7 @@ public static int Main(string[] args) [JSImport("globalThis.console.log")] private static partial void GlobalThisConsoleLog(string text); - const string fetchhelper = "./fetchelper.js"; + const string fetchhelper = "../fetchhelper.js"; [JSImport("responseText", fetchhelper)] private static partial Task FetchHelperResponseText(JSObject response, int delayMs); @@ -40,7 +40,7 @@ public static int Main(string[] args) internal static Task TestHelloWebWorker() { Console.WriteLine($"smoke: TestHelloWebWorker 1 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); - Task t= WebWorker.RunAsync(() => + Task t = WebWorker.RunAsync(() => { Console.WriteLine($"smoke: TestHelloWebWorker 2 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); GlobalThisConsoleLog($"smoke: TestHelloWebWorker 3 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); @@ -50,7 +50,8 @@ internal static Task TestHelloWebWorker() return t.ContinueWith(Gogo); } - private static void Gogo(Task t){ + private static void Gogo(Task t) + { Console.WriteLine($"smoke: TestHelloWebWorker 6 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); } @@ -82,9 +83,9 @@ public static async Task TestCanStartThread() internal static void StartTimerFromWorker() { Console.WriteLine("smoke: StartTimerFromWorker 1 utc {0}", DateTime.UtcNow.ToUniversalTime()); - WebWorker.RunAsync(async () => + WebWorker.RunAsync(async () => { - while (!_timerDone) + while (!_timerDone) { await Task.Delay(1 * 1000); Console.WriteLine("smoke: StartTimerFromWorker 2 utc {0}", DateTime.UtcNow.ToUniversalTime()); @@ -97,26 +98,24 @@ internal static void StartTimerFromWorker() internal static void StartAllocatorFromWorker() { Console.WriteLine("smoke: StartAllocatorFromWorker 1 utc {0}", DateTime.UtcNow.ToUniversalTime()); - WebWorker.RunAsync(async () => + WebWorker.RunAsync(async () => { - while (!_timerDone) + while (!_timerDone) { await Task.Delay(1 * 100); var x = new List(); for (int i = 0; i < 1000; i++) { - var v=new int[1000]; + var v = new int[1000]; v[i] = i; x.Add(v); } - Console.WriteLine("smoke: StartAllocatorFromWorker 2 utc {0} {1} {2}", DateTime.UtcNow.ToUniversalTime(),x[1][1], GC.GetTotalAllocatedBytes()); + Console.WriteLine("smoke: StartAllocatorFromWorker 2 utc {0} {1} {2}", DateTime.UtcNow.ToUniversalTime(), x[1][1], GC.GetTotalAllocatedBytes()); } Console.WriteLine("smoke: StartAllocatorFromWorker done utc {0}", DateTime.UtcNow.ToUniversalTime()); }); } - const string fetchhelper = "../fetchhelper.js"; - [JSExport] internal static void StopTimerFromWorker() { @@ -127,7 +126,7 @@ internal static void StopTimerFromWorker() public static async Task TestCallSetTimeoutOnWorker() { await WebWorker.RunAsync(() => TimeOutThenComplete()); - Console.WriteLine ($"XYZ: Main Thread caught task tid:{Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"XYZ: Main Thread caught task tid:{Thread.CurrentThread.ManagedThreadId}"); } [JSExport] @@ -148,11 +147,11 @@ public static async Task FetchBackground(string url) Console.WriteLine($"smoke: FetchBackground 5 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); if (ok) { - #if DEBUG +#if DEBUG var text = await FetchHelperResponseText(r, 5000); - #else +#else var text = await FetchHelperResponseText(r, 25000); - #endif +#endif Console.WriteLine($"smoke: FetchBackground 6 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); return text; } @@ -190,21 +189,23 @@ await WebWorker.RunAsync(async () => private static async Task TimeOutThenComplete() { var tcs = new TaskCompletionSource(); - Console.WriteLine ($"smoke: Task running tid:{Thread.CurrentThread.ManagedThreadId}"); - GlobalThisSetTimeout(() => { + Console.WriteLine($"smoke: Task running tid:{Thread.CurrentThread.ManagedThreadId}"); + GlobalThisSetTimeout(() => + { tcs.SetResult(); - Console.WriteLine ($"smoke: Timeout fired tid:{Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"smoke: Timeout fired tid:{Thread.CurrentThread.ManagedThreadId}"); }, 250); - Console.WriteLine ($"smoke: Task sleeping tid:{Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"smoke: Task sleeping tid:{Thread.CurrentThread.ManagedThreadId}"); await tcs.Task; - Console.WriteLine ($"smoke: Task resumed tid:{Thread.CurrentThread.ManagedThreadId}"); + Console.WriteLine($"smoke: Task resumed tid:{Thread.CurrentThread.ManagedThreadId}"); } [JSExport] public static async Task RunBackgroundThreadCompute() { var tcs = new TaskCompletionSource(); - var t = new Thread(() => { + var t = new Thread(() => + { var n = CountingCollatzTest(); tcs.SetResult(n); }); @@ -216,7 +217,8 @@ public static async Task RunBackgroundThreadCompute() public static async Task RunBackgroundLongRunningTaskCompute() { var factory = new TaskFactory(); - var t = factory.StartNew (() => { + var t = factory.StartNew(() => + { var n = CountingCollatzTest(); return n; }, TaskCreationOptions.LongRunning); @@ -226,17 +228,19 @@ public static async Task RunBackgroundLongRunningTaskCompute() [JSExport] public static async Task RunBackgroundTaskRunCompute() { - var t1 = Task.Run (() => { + var t1 = Task.Run(() => + { var n = CountingCollatzTest(); return n; }); - var t2 = Task.Run (() => { + var t2 = Task.Run(() => + { var n = CountingCollatzTest(); return n; }); - var rs = await Task.WhenAll (new [] { t1, t2 }); + var rs = await Task.WhenAll(new[] { t1, t2 }); if (rs[0] != rs[1]) - throw new Exception ($"Results from two tasks {rs[0]}, {rs[1]}, differ"); + throw new Exception($"Results from two tasks {rs[0]}, {rs[1]}, differ"); return rs[0]; } @@ -255,8 +259,9 @@ public static int CountingCollatzTest() int bigly = 0; int hugely = 0; int maxSteps = 0; - for (int n = 1; n < maxInput; n++) { - int steps = CountingCollatz ((long)n, limit); + for (int n = 1; n < maxInput; n++) + { + int steps = CountingCollatz((long)n, limit); if (steps > maxSteps) maxSteps = steps; if (steps > 120) @@ -265,7 +270,7 @@ public static int CountingCollatzTest() hugely++; } - Console.WriteLine ($"Bigly: {bigly}, Hugely: {hugely}, maxSteps: {maxSteps}"); + Console.WriteLine($"Bigly: {bigly}, Hugely: {hugely}, maxSteps: {maxSteps}"); if (bigly == 86187 && hugely == 0 && maxSteps == 382) return 524; @@ -274,11 +279,12 @@ public static int CountingCollatzTest() } - private static int CountingCollatz (long n, int limit) + private static int CountingCollatz(long n, int limit) { int steps = 0; - while (n > 1) { - n = Collatz1 (n); + while (n > 1) + { + n = Collatz1(n); steps++; if (steps >= limit) break; @@ -286,7 +292,7 @@ private static int CountingCollatz (long n, int limit) return steps; } - private static long Collatz1 (long n) + private static long Collatz1(long n) { if (n <= 0) throw new Exception("Unexpected non-positive input"); From 91162cba9702e502f6baccf6db4bab6e622f57f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 14:02:53 +0200 Subject: [PATCH 49/77] Fix WBT using GetFilesTable --- .../NativeRebuildTests/NativeRebuildTestsBase.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/NativeRebuildTestsBase.cs b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/NativeRebuildTestsBase.cs index d31f9906593b3e..d190dc2199410b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/NativeRebuildTestsBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeRebuildTests/NativeRebuildTestsBase.cs @@ -164,8 +164,8 @@ internal void CompareStat(IDictionary oldStat, IDictionary oldStat, IDictionary Date: Tue, 13 Jun 2023 14:53:24 +0200 Subject: [PATCH 50/77] Feedback --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 571a8b5c91db01..c6189f3349ce8e 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -321,10 +321,10 @@ protected override bool ExecuteInternal() { if (valueObject is bool boolValue) config.diagnosticTracing = boolValue; - else if (valueObject is string stringValue) - config.diagnosticTracing = stringValue == bool.TrueString; + else if (valueObject is string stringValue && bool.TryParse(stringValue, out bool stringToboolValue)) + config.diagnosticTracing = stringToboolValue; else - throw new LogAsErrorException($"Unsupported value of type '{valueObject?.GetType()?.FullName}' for extra config 'diagnosticTracing'."); + throw new LogAsErrorException($"Unsupported value '{valueObject}' of type '{valueObject?.GetType()?.FullName}' for extra config 'diagnosticTracing'."); } else { From 90ccf1f5be3c570b35b933380b311aadedc32334 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 14:54:48 +0200 Subject: [PATCH 51/77] Syntax --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index c6189f3349ce8e..6a9c5750f7af3f 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -319,10 +319,8 @@ protected override bool ExecuteInternal() } else if (name == "diagnosticTracing") { - if (valueObject is bool boolValue) + if (valueObject is bool boolValue || (valueObject is string stringValue && bool.TryParse(stringValue, out boolValue))) config.diagnosticTracing = boolValue; - else if (valueObject is string stringValue && bool.TryParse(stringValue, out bool stringToboolValue)) - config.diagnosticTracing = stringToboolValue; else throw new LogAsErrorException($"Unsupported value '{valueObject}' of type '{valueObject?.GetType()?.FullName}' for extra config 'diagnosticTracing'."); } From b871e283808bceb49719ce2ff8f164005050e0ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 13 Jun 2023 15:01:42 +0200 Subject: [PATCH 52/77] WasmRuntimeAssetsLocation --- src/mono/wasm/build/WasmApp.targets | 8 ++++++++ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 8 +++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 70b45207c48232..f861934fdc237c 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -77,6 +77,11 @@ - $(WasmAllowUndefinedSymbols) - Controls whether undefined symbols are allowed or not, if true, appends 'allow-undefined' and sets 'ERROR_ON_UNDEFINED_SYMBOLS=0' as arguments for wasm-ld, if false (default), removes 'allow-undefined' and sets 'ERROR_ON_UNDEFINED_SYMBOLS=1'. + - $(WasmRuntimeAssetsLocation) - Allows to override a location for build generated files. Defaults to `_framework`. + Output structure + - AppBundle directly contains user files + - AppBundle/_framework contains generated files (dlls, runtime scripts, icu) + - AppBundle/_content contains web files from nuget packages (css, js, etc) Public items: - @(WasmExtraFilesToDeploy) - Files to copy to $(WasmAppDir). @@ -135,6 +140,8 @@ true + + _framework @@ -404,6 +411,7 @@ UseWebcil="$(WasmEnableWebcil)" WasmIncludeFullIcuData="$(WasmIncludeFullIcuData)" WasmIcuDataFileName="$(WasmIcuDataFileName)" + RuntimeAssetsLocation="$(WasmRuntimeAssetsLocation)" > diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 6a9c5750f7af3f..45632e49b31cde 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -25,6 +25,7 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask public bool UseWebcil { get; set; } public bool WasmIncludeFullIcuData { get; set; } public string? WasmIcuDataFileName { get; set; } + public string? RuntimeAssetsLocation { get; set; } // // Extra json elements to add to _framework/blazor.boot.json @@ -86,11 +87,16 @@ protected override bool ExecuteInternal() }; // Create app - var frameworkPath = Path.Combine(AppDir, "_framework"); + var frameworkPath = !string.IsNullOrEmpty(RuntimeAssetsLocation) + ? Path.Combine(AppDir, RuntimeAssetsLocation) + : AppDir; + Directory.CreateDirectory(AppDir!); Directory.CreateDirectory(frameworkPath); + if (UseWebcil) Log.LogMessage(MessageImportance.Normal, "Converting assemblies to Webcil"); + foreach (var assembly in _assemblies) { if (UseWebcil) From 51d7222787a763b73c73946ac41339cefcf016b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 19 Jun 2023 13:47:14 +0200 Subject: [PATCH 53/77] WasmEnableRuntimeAssetsLocation --- src/mono/wasm/build/WasmApp.targets | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index f861934fdc237c..a2e59e2babba2f 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -82,6 +82,8 @@ - AppBundle directly contains user files - AppBundle/_framework contains generated files (dlls, runtime scripts, icu) - AppBundle/_content contains web files from nuget packages (css, js, etc) + - $(WasmEnableRuntimeAssetsLocation) - Disables 'WasmRuntimeAssetsLocation' and merges user files and '_framework' into a single folder + It changes the relative path for module imports from nuget packages (using JSHost.ImportAsync). Public items: - @(WasmExtraFilesToDeploy) - Files to copy to $(WasmAppDir). @@ -141,7 +143,8 @@ true - _framework + true + _framework From 5a88c5cc39879203cc076f1ed544496ecc330ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 19 Jun 2023 13:48:34 +0200 Subject: [PATCH 54/77] Revert --no-exit --- src/mono/wasm/test-main.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.js index a09f7ab48cdd50..a6cd146f9652e1 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.js @@ -103,7 +103,6 @@ function initRunArgs(runArgs) { // default'ing to true for tests, unless debugging runArgs.forwardConsole = runArgs.forwardConsole === undefined ? !runArgs.debugging : runArgs.forwardConsole; runArgs.memorySnapshot = runArgs.memorySnapshot === undefined ? true : runArgs.memorySnapshot; - runArgs.exit = runArgs.exit === undefined ? true : runArgs.exit; return runArgs; } @@ -137,8 +136,6 @@ function processArguments(incomingArguments, runArgs) { runArgs.forwardConsole = false; } else if (currentArg == "--no-memory-snapshot") { runArgs.memorySnapshot = false; - } else if (currentArg == "--no-exit") { - runArgs.exit = false; } else if (currentArg.startsWith("--fetch-random-delay=")) { const arg = currentArg.substring("--fetch-random-delay=".length); if (is_browser) { @@ -342,10 +339,7 @@ async function run() { // this is subsequent run with the actual tests. It will use whatever was cached in the previous run. // This way, we are testing that the cached version works. - mono_exit = (code, reason) => { - if (runArgs.exit) - exit(code, reason); - }; + mono_exit = exit; if (runArgs.applicationArguments.length == 0) { mono_exit(1, "Missing required --run argument"); From 6fc1f06175fd724dd9a66bb310d5d3b2c919100a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 19 Jun 2023 13:52:10 +0200 Subject: [PATCH 55/77] WasmEnableRuntimeAssetsLocation default value comment --- src/mono/wasm/build/WasmApp.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index a2e59e2babba2f..7c0327e1be5079 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -82,7 +82,7 @@ - AppBundle directly contains user files - AppBundle/_framework contains generated files (dlls, runtime scripts, icu) - AppBundle/_content contains web files from nuget packages (css, js, etc) - - $(WasmEnableRuntimeAssetsLocation) - Disables 'WasmRuntimeAssetsLocation' and merges user files and '_framework' into a single folder + - $(WasmEnableRuntimeAssetsLocation) - Disables 'WasmRuntimeAssetsLocation' and merges user files and '_framework' into a single folder (default: true) It changes the relative path for module imports from nuget packages (using JSHost.ImportAsync). Public items: From f832ac0aa73a9d2b726526f5a0507ca71a80b3a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 19 Jun 2023 14:34:22 +0200 Subject: [PATCH 56/77] Flat output structure for advanced sample --- .../sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj | 3 +++ src/mono/sample/wasm/browser-advanced/main.js | 2 +- src/mono/wasm/runtime/dotnet.d.ts | 5 +---- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj b/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj index d37b17495581b5..f451f033e3f7f1 100644 --- a/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj +++ b/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj @@ -14,6 +14,9 @@ <_ServeHeaders>$(_ServeHeaders) -h "Content-Security-Policy: default-src 'self' 'wasm-unsafe-eval'" browser; + + + false diff --git a/src/mono/sample/wasm/browser-advanced/main.js b/src/mono/sample/wasm/browser-advanced/main.js index 87096cf374c715..38a7236ca0fb55 100644 --- a/src/mono/sample/wasm/browser-advanced/main.js +++ b/src/mono/sample/wasm/browser-advanced/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet, exit } from './_framework/dotnet.js' +import { dotnet, exit } from './dotnet.js' function add(a, b) { return a + b; diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index d44b4e9f08abcf..50c6324eeb0f0c 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -318,9 +318,7 @@ interface BootJsonData { readonly environmentVariables?: { [name: string]: string; }; - readonly diagnosticTracing?: { - [name: string]: string; - }; + readonly diagnosticTracing?: boolean; readonly pthreadPoolSize: number; modifiableAssemblies: string | null; aspnetCoreBrowserTools: string | null; @@ -343,7 +341,6 @@ interface ResourceGroups { readonly vfs?: { [virtualPath: string]: ResourceList; }; - readonly remoteSources?: string[]; } type ResourceList = { [name: string]: string; From f5c07cdc78f0a4fa035f080dd975c47afb47e3d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 19 Jun 2023 14:55:01 +0200 Subject: [PATCH 57/77] Feedback --- .../Wasm.Advanced.Sample.csproj | 2 +- src/mono/wasm/build/WasmApp.targets | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj b/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj index f451f033e3f7f1..6875be373a9c1d 100644 --- a/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj +++ b/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj @@ -16,7 +16,7 @@ browser; - false + ./ diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 7c0327e1be5079..d80d6ae3912ce8 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -77,13 +77,12 @@ - $(WasmAllowUndefinedSymbols) - Controls whether undefined symbols are allowed or not, if true, appends 'allow-undefined' and sets 'ERROR_ON_UNDEFINED_SYMBOLS=0' as arguments for wasm-ld, if false (default), removes 'allow-undefined' and sets 'ERROR_ON_UNDEFINED_SYMBOLS=1'. - - $(WasmRuntimeAssetsLocation) - Allows to override a location for build generated files. Defaults to `_framework`. + - $(WasmRuntimeAssetsLocation) - Allows to override a location for build generated files. + Defaults to '_framework', if you want to put framework files in the same directory as user files, use './' value. Output structure - AppBundle directly contains user files - AppBundle/_framework contains generated files (dlls, runtime scripts, icu) - AppBundle/_content contains web files from nuget packages (css, js, etc) - - $(WasmEnableRuntimeAssetsLocation) - Disables 'WasmRuntimeAssetsLocation' and merges user files and '_framework' into a single folder (default: true) - It changes the relative path for module imports from nuget packages (using JSHost.ImportAsync). Public items: - @(WasmExtraFilesToDeploy) - Files to copy to $(WasmAppDir). @@ -142,9 +141,6 @@ true - - true - _framework @@ -372,11 +368,18 @@ + + + + _framework + + + + DependsOnTargets="_WasmGenerateRuntimeConfig;_GetWasmGenerateAppBundleDependencies;_EnsureWasmRuntimeAssetsLocation"> From 2ff44c83328628e851b1aa6377d7d54eb61435f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 11:38:17 +0200 Subject: [PATCH 58/77] Fix browser-threads-minimal --- src/mono/sample/wasm/browser-threads-minimal/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/sample/wasm/browser-threads-minimal/Program.cs b/src/mono/sample/wasm/browser-threads-minimal/Program.cs index dc5fde91da7832..05d51b8dde0b06 100644 --- a/src/mono/sample/wasm/browser-threads-minimal/Program.cs +++ b/src/mono/sample/wasm/browser-threads-minimal/Program.cs @@ -175,7 +175,7 @@ await WebWorker.RunAsync(async () => { Console.WriteLine($"smoke {meaning}: TestTLS 2 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); meaning = 41; - await JSHost.ImportAsync(fetchhelper, "./fetchhelper.js"); + await JSHost.ImportAsync(fetchhelper, "../fetchhelper.js"); Console.WriteLine($"smoke {meaning}: TestTLS 3 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); meaning = 43; Console.WriteLine($"smoke {meaning}: TestTLS 4 ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}, SynchronizationContext: {SynchronizationContext.Current?.GetType().FullName ?? "null"}"); From 8a5f6573a52b66d2099dbe3d7061262eed33add1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 14:46:42 +0200 Subject: [PATCH 59/77] Use flat structure for template wbt --- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 8b582999aa2232..0fe02b7e364bd5 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -88,7 +88,7 @@ public void BrowserBuildThenPublish(string config) UpdateBrowserMainJs(DefaultTargetFramework); - var buildArgs = new BuildArgs(projectName, config, false, id, null); + var buildArgs = new BuildArgs(projectName, config, false, id, "./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -137,7 +137,7 @@ public void ConsoleBuildThenPublish(string config) UpdateConsoleMainJs(); - var buildArgs = new BuildArgs(projectName, config, false, id, null); + var buildArgs = new BuildArgs(projectName, config, false, id, "./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -209,7 +209,7 @@ private void ConsoleBuildAndRun(string config, bool relinking, string extraNewAr if (relinking) AddItemsPropertiesToProject(projectFile, "true"); - var buildArgs = new BuildArgs(projectName, config, false, id, null); + var buildArgs = new BuildArgs(projectName, config, false, id, "./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -273,6 +273,8 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st UpdateBrowserMainJs(DefaultTargetFramework); + extraProperties += "./"; + if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -307,6 +309,8 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP UpdateProgramCS(); UpdateConsoleMainJs(); + extraProperties += "./"; + if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -382,7 +386,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) AddItemsPropertiesToProject(projectFile, "true"); } - var buildArgs = new BuildArgs(projectName, config, aot, id, null); + var buildArgs = new BuildArgs(projectName, config, aot, id, "./"); buildArgs = ExpandBuildArgs(buildArgs); bool expectRelinking = config == "Release" || aot || relinking; @@ -437,7 +441,7 @@ public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")}") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} -p=WasmRuntimeAssetsLocation=./") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From cc0568c22a4d9b9b81df5fd5639610c2461e9657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 18:09:13 +0200 Subject: [PATCH 60/77] Use flat structure for template wbt (fix) --- src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs | 2 +- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index efe75b94352dcc..ecac43f816eb03 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -205,7 +205,7 @@ public void ProjectWithDllImportsRequiringMarshalIlGen_ArrayTypeParameter(string CommandResult result = new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", $"-c {config} -bl"); + .ExecuteWithCapturedOutput("build", $"-c {config} -bl -p:WasmRuntimeAssetsLocation=./"); Assert.True(result.ExitCode == 0, "Expected build to succeed"); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 0fe02b7e364bd5..6829f0f4255bf9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -88,7 +88,7 @@ public void BrowserBuildThenPublish(string config) UpdateBrowserMainJs(DefaultTargetFramework); - var buildArgs = new BuildArgs(projectName, config, false, id, "./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -137,7 +137,7 @@ public void ConsoleBuildThenPublish(string config) UpdateConsoleMainJs(); - var buildArgs = new BuildArgs(projectName, config, false, id, "./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -209,7 +209,7 @@ private void ConsoleBuildAndRun(string config, bool relinking, string extraNewAr if (relinking) AddItemsPropertiesToProject(projectFile, "true"); - var buildArgs = new BuildArgs(projectName, config, false, id, "./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -273,7 +273,7 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st UpdateBrowserMainJs(DefaultTargetFramework); - extraProperties += "./"; + extraProperties += "-p:WasmRuntimeAssetsLocation=./"; if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -309,7 +309,7 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP UpdateProgramCS(); UpdateConsoleMainJs(); - extraProperties += "./"; + extraProperties += "-p:WasmRuntimeAssetsLocation=./"; if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -386,7 +386,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) AddItemsPropertiesToProject(projectFile, "true"); } - var buildArgs = new BuildArgs(projectName, config, aot, id, "./"); + var buildArgs = new BuildArgs(projectName, config, aot, id, "-p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); bool expectRelinking = config == "Release" || aot || relinking; @@ -441,7 +441,7 @@ public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} -p=WasmRuntimeAssetsLocation=./") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} -p:WasmRuntimeAssetsLocation=./") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From 8c1f461be3cf720bc3f1aa70b31ba64bc89e7bd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 18:10:27 +0200 Subject: [PATCH 61/77] Fix WBT hybrid --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index fc904741b823e6..3a9fcdae87efde 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -767,7 +767,7 @@ void AssertIcuAssets() AssertFilesExist(bundleDir, new[] { "_framework/icudt_EFIGS.dat" }, expectToExist: expectEFIGS); AssertFilesExist(bundleDir, new[] { "_framework/icudt_CJK.dat" }, expectToExist: expectCJK); AssertFilesExist(bundleDir, new[] { "_framework/icudt_no_CJK.dat" }, expectToExist: expectNOCJK); - AssertFilesExist(bundleDir, new[] { "icudt_hybrid.dat" }, expectToExist: expectHYBRID); + AssertFilesExist(bundleDir, new[] { "_framework/icudt_hybrid.dat" }, expectToExist: expectHYBRID); } } From cb6ffa12f455680857064d96db85a847891783bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 18:12:04 +0200 Subject: [PATCH 62/77] More WBT fixes --- src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs | 2 +- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index ecac43f816eb03..65895c067380d9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -205,7 +205,7 @@ public void ProjectWithDllImportsRequiringMarshalIlGen_ArrayTypeParameter(string CommandResult result = new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", $"-c {config} -bl -p:WasmRuntimeAssetsLocation=./"); + .ExecuteWithCapturedOutput("build", $"-c {config} -bl /p:WasmRuntimeAssetsLocation=./"); Assert.True(result.ExitCode == 0, "Expected build to succeed"); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 6829f0f4255bf9..4620462a5bfe8f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -88,7 +88,7 @@ public void BrowserBuildThenPublish(string config) UpdateBrowserMainJs(DefaultTargetFramework); - var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -137,7 +137,7 @@ public void ConsoleBuildThenPublish(string config) UpdateConsoleMainJs(); - var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -209,7 +209,7 @@ private void ConsoleBuildAndRun(string config, bool relinking, string extraNewAr if (relinking) AddItemsPropertiesToProject(projectFile, "true"); - var buildArgs = new BuildArgs(projectName, config, false, id, "-p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -273,7 +273,7 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st UpdateBrowserMainJs(DefaultTargetFramework); - extraProperties += "-p:WasmRuntimeAssetsLocation=./"; + extraProperties += "./"; if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -309,7 +309,7 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP UpdateProgramCS(); UpdateConsoleMainJs(); - extraProperties += "-p:WasmRuntimeAssetsLocation=./"; + extraProperties += "./"; if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -386,7 +386,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) AddItemsPropertiesToProject(projectFile, "true"); } - var buildArgs = new BuildArgs(projectName, config, aot, id, "-p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, aot, id, "/p:WasmRuntimeAssetsLocation=./"); buildArgs = ExpandBuildArgs(buildArgs); bool expectRelinking = config == "Release" || aot || relinking; @@ -441,7 +441,7 @@ public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} -p:WasmRuntimeAssetsLocation=./") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} /p:WasmRuntimeAssetsLocation=./") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From b23186e4fcf5cfcdd2128b2f0822b29c886ec868 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 20 Jun 2023 20:30:11 +0200 Subject: [PATCH 63/77] Update dotnet.js import in templates --- src/mono/wasm/templates/templates/browser/main.js | 2 +- src/mono/wasm/templates/templates/console/main.mjs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/templates/templates/browser/main.js b/src/mono/wasm/templates/templates/browser/main.js index 6d9bd43f7eb7b3..a073fc9cf70327 100644 --- a/src/mono/wasm/templates/templates/browser/main.js +++ b/src/mono/wasm/templates/templates/browser/main.js @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' const { setModuleImports, getAssemblyExports, getConfig } = await dotnet .withDiagnosticTracing(false) diff --git a/src/mono/wasm/templates/templates/console/main.mjs b/src/mono/wasm/templates/templates/console/main.mjs index 6dd163a3741b32..ea131be48c1bf5 100644 --- a/src/mono/wasm/templates/templates/console/main.mjs +++ b/src/mono/wasm/templates/templates/console/main.mjs @@ -1,7 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -import { dotnet } from './dotnet.js' +import { dotnet } from './_framework/dotnet.js' const { setModuleImports, getAssemblyExports, getConfig } = await dotnet .withDiagnosticTracing(false) From 270c00d1c1f061c451f7caf838cbd478ec7ac215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 09:50:19 +0200 Subject: [PATCH 64/77] Rename test-main.js to test-main.mjs --- eng/pipelines/coreclr/templates/perf-job.yml | 2 +- eng/testing/WasmRunnerAOTTemplate.sh | 2 +- eng/testing/WasmRunnerTemplate.cmd | 2 +- eng/testing/WasmRunnerTemplate.sh | 2 +- eng/testing/tests.browser.targets | 2 +- .../wasm/browser-bench/Console/Makefile | 2 +- .../wasi/Wasi.Build.Tests/BuildTestBase.cs | 84 +++++++++---------- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 12 +-- .../SatelliteAssembliesTests.cs | 6 +- .../Wasm.Build.Tests/Wasm.Build.Tests.csproj | 2 +- .../WasmRunOutOfAppBundleTests.cs | 6 +- .../aot-tests/ProxyProjectForAOTOnHelix.proj | 2 +- src/mono/wasm/{test-main.js => test-main.mjs} | 2 +- src/tests/Common/Directory.Build.targets | 2 +- .../wasm-test-runner/WasmTestRunner.proj | 4 +- src/tests/Common/wasm-test-runner/index.html | 8 +- 16 files changed, 73 insertions(+), 67 deletions(-) rename src/mono/wasm/{test-main.js => test-main.mjs} (99%) diff --git a/eng/pipelines/coreclr/templates/perf-job.yml b/eng/pipelines/coreclr/templates/perf-job.yml index d0bc486d4b4041..d99bb835b43da5 100644 --- a/eng/pipelines/coreclr/templates/perf-job.yml +++ b/eng/pipelines/coreclr/templates/perf-job.yml @@ -196,7 +196,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest/* $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.js $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.js && + cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.mjs && find $(librariesDownloadDir)/bin/wasm -type d && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" diff --git a/eng/testing/WasmRunnerAOTTemplate.sh b/eng/testing/WasmRunnerAOTTemplate.sh index 856fb7ebbea1bc..4267d67afbed85 100644 --- a/eng/testing/WasmRunnerAOTTemplate.sh +++ b/eng/testing/WasmRunnerAOTTemplate.sh @@ -53,7 +53,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then fi if [[ -z "$MAIN_JS" ]]; then - MAIN_JS="--js-file=test-main.js" + MAIN_JS="--js-file=test-main.mjs" fi fi diff --git a/eng/testing/WasmRunnerTemplate.cmd b/eng/testing/WasmRunnerTemplate.cmd index a8c9c0ac571269..df51838661beb6 100644 --- a/eng/testing/WasmRunnerTemplate.cmd +++ b/eng/testing/WasmRunnerTemplate.cmd @@ -41,7 +41,7 @@ if /I [%XHARNESS_COMMAND%] == [test] ( ) ) if [%MAIN_JS%] == [] ( - set "MAIN_JS=--js-file^=test-main.js" + set "MAIN_JS=--js-file^=test-main.mjs" ) if [%JS_ENGINE_ARGS%] == [] ( diff --git a/eng/testing/WasmRunnerTemplate.sh b/eng/testing/WasmRunnerTemplate.sh index 8b4e9adb10c2ef..18e8f22ffb1735 100644 --- a/eng/testing/WasmRunnerTemplate.sh +++ b/eng/testing/WasmRunnerTemplate.sh @@ -43,7 +43,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then fi if [[ -z "$MAIN_JS" ]]; then - MAIN_JS="--js-file=test-main.js" + MAIN_JS="--js-file=test-main.mjs" fi if [[ -z "$JS_ENGINE_ARGS" ]]; then diff --git a/eng/testing/tests.browser.targets b/eng/testing/tests.browser.targets index e48831cc61d6ab..a287f353d24503 100644 --- a/eng/testing/tests.browser.targets +++ b/eng/testing/tests.browser.targets @@ -157,7 +157,7 @@ $(BundleDir) WasmTestRunner.dll - $(MonoProjectRoot)\wasm\test-main.js + $(MonoProjectRoot)\wasm\test-main.mjs $([System.IO.Path]::GetFileName('$(WasmMainJSPath)')) $(PublishDir)index.html $(InvariantGlobalization) diff --git a/src/mono/sample/wasm/browser-bench/Console/Makefile b/src/mono/sample/wasm/browser-bench/Console/Makefile index d301744fe74ee4..3e4e9a0d587ca6 100644 --- a/src/mono/sample/wasm/browser-bench/Console/Makefile +++ b/src/mono/sample/wasm/browser-bench/Console/Makefile @@ -8,7 +8,7 @@ endif PROJECT_NAME=Wasm.Console.Bench.Sample.csproj CONSOLE_DLL=Wasm.Console.Bench.Sample.dll -MAIN_JS=test-main.js +MAIN_JS=test-main.mjs ARGS= run: run-console diff --git a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs index e2980fc735746a..d2851e44fef520 100644 --- a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs @@ -37,7 +37,7 @@ public abstract class BuildTestBase : IClassFixture !s_buildEnv.IsWorkload; public static string GetNuGetConfigPathFor(string targetFramework) => Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with - // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config"); + // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config"); static BuildTestBase() { @@ -69,15 +69,15 @@ static BuildTestBase() else s_xharnessRunnerCommand = EnvironmentVariables.XHarnessCliPath; - Console.WriteLine (""); - Console.WriteLine ($"=============================================================================================="); - Console.WriteLine ($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ==============="); - Console.WriteLine ($"=============================================================================================="); - Console.WriteLine (""); + Console.WriteLine(""); + Console.WriteLine($"=============================================================================================="); + Console.WriteLine($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ==============="); + Console.WriteLine($"=============================================================================================="); + Console.WriteLine(""); } catch (Exception ex) { - Console.WriteLine ($"Exception: {ex}"); + Console.WriteLine($"Exception: {ex}"); throw; } } @@ -90,7 +90,7 @@ public BuildTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture bu _logPath = s_buildEnv.LogRootPath; // FIXME: } - public static IEnumerable> ConfigWithAOTData(bool aot, string? config=null) + public static IEnumerable> ConfigWithAOTData(bool aot, string? config = null) { if (config == null) { @@ -154,7 +154,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = {DefaultTargetFramework} Exe true - test-main.js + test-main.mjs ##EXTRA_PROPERTIES## @@ -163,7 +163,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = ##INSERT_AT_END## "; - protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties="", string extraItems="", string insertAtEnd="", string projectTemplate=SimpleProjectTemplate) + protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties = "", string extraItems = "", string insertAtEnd = "", string projectTemplate = SimpleProjectTemplate) { if (buildArgs.AOT) { @@ -185,7 +185,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp string msgPrefix = options.Label != null ? $"[{options.Label}] " : string.Empty; if (options.UseCache && _buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product)) { - _testOutput.WriteLine ($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}"); + _testOutput.WriteLine($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}"); if (!product.Result) throw new XunitException($"Found existing build at {product.ProjectDir}, but it had failed. Check build log at {product.LogFile}"); @@ -204,8 +204,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents); File.Copy(Path.Combine(AppContext.BaseDirectory, - options.TargetFramework == "net8.0" ? "test-main.js" : "data/test-main-7.0.js"), - Path.Combine(_projectDir, "test-main.js")); + options.TargetFramework == "net8.0" ? "test-main.mjs" : "data/test-main-7.0.js"), + Path.Combine(_projectDir, "test-main.mjs")); } else if (_projectDir is null) { @@ -254,7 +254,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp AssertBasicAppBundle(bundleDir, buildArgs.ProjectName, buildArgs.Config, - options.MainJS ?? "test-main.js", + options.MainJS ?? "test-main.mjs", options.HasV8Script, options.TargetFramework ?? DefaultTargetFramework, options.HasIcudt, @@ -309,7 +309,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse return projectfile; } - protected (CommandResult, string) BuildInternal(string id, string config, bool publish=false, bool setWasmDevel=true, params string[] extraArgs) + protected (CommandResult, string) BuildInternal(string id, string config, bool publish = false, bool setWasmDevel = true, params string[] extraArgs) { string label = publish ? "publish" : "build"; _testOutput.WriteLine($"{Environment.NewLine}** {label} **{Environment.NewLine}"); @@ -392,7 +392,7 @@ protected static void AssertBasicAppBundle(string bundleDir, protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null) => AssertFilesExist(dir, filenames, label, expectToExist: false); - protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist=true) + protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist = true) { string prefix = label != null ? $"{label}: " : string.Empty; if (!Directory.Exists(dir)) @@ -408,10 +408,10 @@ protected static void AssertFilesExist(string dir, string[] filenames, string? l } } - protected static void AssertSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: true); - protected static void AssertNotSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: false); + protected static void AssertSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: true); + protected static void AssertNotSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: false); - protected static void AssertFile(string file0, string file1, string? label=null, bool same=true) + protected static void AssertFile(string file0, string file1, string? label = null, bool same = true) { Assert.True(File.Exists(file0), $"{label}: Expected to find {file0}"); Assert.True(File.Exists(file1), $"{label}: Expected to find {file1}"); @@ -426,7 +426,7 @@ protected static void AssertFile(string file0, string file1, string? label=null, throw new XunitException($"{label}:{Environment.NewLine} File sizes should not match for {file0} ({finfo0.Length}), and {file1} ({finfo1.Length})"); } - protected (int exitCode, string buildOutput) AssertBuild(string args, string label="build", bool expectSuccess=true, IDictionary? envVars=null, int? timeoutMs=null) + protected (int exitCode, string buildOutput) AssertBuild(string args, string label = "build", bool expectSuccess = true, IDictionary? envVars = null, int? timeoutMs = null) { var result = RunProcess(s_buildEnv.DotNet, _testOutput, args, workingDir: _projectDir, label: label, envVars: envVars, timeoutMs: timeoutMs ?? s_defaultPerTestTimeoutMs); if (expectSuccess && result.exitCode != 0) @@ -450,14 +450,14 @@ private string FindSubDirIgnoringCase(string parentDir, string dirName) return first ?? Path.Combine(parentDir, dirName); } - protected string GetBinDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null) + protected string GetBinDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null) { var dir = baseDir ?? _projectDir; Assert.NotNull(dir); return Path.Combine(dir!, "bin", config, targetFramework, BuildEnvironment.DefaultRuntimeIdentifier); } - protected string GetObjDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null) + protected string GetObjDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null) { var dir = baseDir ?? _projectDir; Assert.NotNull(dir); @@ -489,7 +489,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path, { _testOutput.WriteLine($"Running {path} {args}"); _testOutput.WriteLine($"WorkingDirectory: {workingDir}"); - StringBuilder outputBuilder = new (); + StringBuilder outputBuilder = new(); object syncObj = new(); var processStartInfo = new ProcessStartInfo @@ -523,7 +523,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path, processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath"); } - Process process = new (); + Process process = new(); process.StartInfo = processStartInfo; process.EnableRaisingEvents = true; @@ -596,7 +596,7 @@ void LogData(string label, string? message) } } - public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties=null, string? extraItems=null, string? atTheEnd=null) + public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties = null, string? extraItems = null, string? atTheEnd = null) { if (extraProperties == null && extraItems == null && atTheEnd == null) return projectFile; @@ -643,7 +643,7 @@ private static string GetEnvironmentVariableOrDefault(string envVarName, string return string.IsNullOrEmpty(value) ? defaultValue : value; } - internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish=true) + internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish = true) { string objDir = GetObjDir(buildArgs.Config); string bundleDir = Path.Combine(GetBinDir(baseDir: _projectDir, config: buildArgs.Config), "AppBundle"); @@ -686,25 +686,25 @@ public record BuildArgs(string ProjectName, string ProjectFileContents, string? ExtraBuildArgs); public record BuildProduct(string ProjectDir, string LogFile, bool Result); - internal record FileStat (bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath); + internal record FileStat(bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath); internal record BuildPaths(string ObjWasmDir, string ObjDir, string BinDir, string BundleDir); public record BuildProjectOptions ( - Action? InitProject = null, - bool? DotnetWasmFromRuntimePack = null, - bool HasIcudt = true, - bool UseCache = true, - bool ExpectSuccess = true, - bool AssertAppBundle = true, - bool CreateProject = true, - bool Publish = true, - bool BuildOnlyAfterPublish = true, - bool HasV8Script = true, - string? Verbosity = null, - string? Label = null, - string? TargetFramework = null, - string? MainJS = null, + Action? InitProject = null, + bool? DotnetWasmFromRuntimePack = null, + bool HasIcudt = true, + bool UseCache = true, + bool ExpectSuccess = true, + bool AssertAppBundle = true, + bool CreateProject = true, + bool Publish = true, + bool BuildOnlyAfterPublish = true, + bool HasV8Script = true, + string? Verbosity = null, + string? Label = null, + string? TargetFramework = null, + string? MainJS = null, IDictionary? ExtraBuildEnvironmentVariables = null ); diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 3a9fcdae87efde..51137bf17b12da 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -155,7 +155,7 @@ protected string RunAndTestWasmApp(BuildArgs buildArgs, string targetFramework = DefaultTargetFramework, string? extraXHarnessMonoArgs = null, string? extraXHarnessArgs = null, - string jsRelativePath = "test-main.js", + string jsRelativePath = "test-main.mjs", string environmentLocale = DefaultEnvironmentLocale) { buildDir ??= _projectDir; @@ -330,7 +330,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = {DefaultTargetFramework} Exe true - test-main.js + test-main.mjs ##EXTRA_PROPERTIES## @@ -390,13 +390,13 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp Path.Combine( AppContext.BaseDirectory, string.IsNullOrEmpty(options.TargetFramework) || options.TargetFramework == "net8.0" - ? "test-main.js" + ? "test-main.mjs" : "data/test-main-7.0.js" ), - Path.Combine(_projectDir, "test-main.js") + Path.Combine(_projectDir, "test-main.mjs") ); - File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); + File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); } else if (_projectDir is null) { @@ -445,7 +445,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp AssertBasicAppBundle(bundleDir, buildArgs.ProjectName, buildArgs.Config, - options.MainJS ?? "test-main.js", + options.MainJS ?? "test-main.mjs", options.HasV8Script, options.TargetFramework ?? DefaultTargetFramework, options.GlobalizationMode, diff --git a/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs b/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs index b7c95aaae91e36..ef079071b5d036 100644 --- a/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs @@ -30,7 +30,7 @@ public SatelliteAssembliesTests(ITestOutputHelper output, SharedBuildPerTestClas [Theory] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ false, RunHost.All })] - [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] + [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ true, /*relinking*/ false, RunHost.All })] public void ResourcesFromMainAssembly(BuildArgs buildArgs, bool nativeRelink, @@ -72,7 +72,7 @@ public void ResourcesFromMainAssembly(BuildArgs buildArgs, [Theory] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ false, RunHost.All })] - [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] + [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ true, /*relinking*/ false, RunHost.All })] public void ResourcesFromProjectReference(BuildArgs buildArgs, bool nativeRelink, @@ -167,7 +167,7 @@ private void CreateProgramForCultureTest(string dir, string resourceName, string {DefaultTargetFramework} Exe true - test-main.js + test-main.mjs ##EXTRA_PROPERTIES## 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 0ff15466c29ef6..019d01ddfb1bcf 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj +++ b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj @@ -36,7 +36,7 @@ - + diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs index befd7ae029813d..84a99fb7c4c5cb 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs @@ -12,7 +12,7 @@ namespace Wasm.Build.Tests; public class WasmRunOutOfAppBundleTests : BuildTestBase { public WasmRunOutOfAppBundleTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) : base(output, buildContext) - {} + { } [Theory] [BuildAndRun] @@ -41,7 +41,7 @@ public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id) indexHtmlPath = Path.Combine(outerDir, "index.html"); if (!File.Exists(indexHtmlPath)) { - var html = @""; + var html = @""; File.WriteAllText(indexHtmlPath, html); } } @@ -51,6 +51,6 @@ public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id) host: host, id: id, bundleDir: outerDir, - jsRelativePath: "./AppBundle/test-main.js"); + jsRelativePath: "./AppBundle/test-main.mjs"); } } diff --git a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj index e5940d2784ae8d..f450d21cfbb739 100644 --- a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj @@ -30,7 +30,7 @@ $(TestRootDir)AppBundle\ $(OriginalPublishDir)WasmTestRunner.dll - $(OriginalPublishDir)test-main.js + $(OriginalPublishDir)test-main.mjs true diff --git a/src/mono/wasm/test-main.js b/src/mono/wasm/test-main.mjs similarity index 99% rename from src/mono/wasm/test-main.js rename to src/mono/wasm/test-main.mjs index a6cd146f9652e1..8718ba0cf41517 100644 --- a/src/mono/wasm/test-main.js +++ b/src/mono/wasm/test-main.mjs @@ -387,7 +387,7 @@ async function run() { const main_assembly_name = runArgs.applicationArguments[1]; const app_args = runArgs.applicationArguments.slice(2); const result = await App.runtime.runMain(main_assembly_name, app_args); - console.log(`test-main.js exiting ${app_args.length > 1 ? main_assembly_name + " " + app_args[0] : main_assembly_name} with result ${result}`); + console.log(`test-main.mjs exiting ${app_args.length > 1 ? main_assembly_name + " " + app_args[0] : main_assembly_name} with result ${result}`); mono_exit(result); } catch (error) { if (error.name != "ExitStatus") { diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index fd1d1af2c512ee..e3f56896da0b8e 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -152,7 +152,7 @@ TargetDir="wasm-test-runner/"/> $(TestAssemblyFileName) $(AppDir) - $(CORE_ROOT)\runtime-test\test-main.js + $(CORE_ROOT)\runtime-test\test-main.mjs true true true @@ -34,7 +34,7 @@ - + diff --git a/src/tests/Common/wasm-test-runner/index.html b/src/tests/Common/wasm-test-runner/index.html index aa53c88f3289d6..1fe9311709b163 100644 --- a/src/tests/Common/wasm-test-runner/index.html +++ b/src/tests/Common/wasm-test-runner/index.html @@ -1 +1,7 @@ - \ No newline at end of file + + + + + + + \ No newline at end of file From 16474e91a8c47e5f47b40628177322d4ba802bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 11:36:06 +0200 Subject: [PATCH 65/77] Rename test-main.js to test-main.mjs (2) --- eng/pipelines/coreclr/templates/run-scenarios-job.yml | 2 +- .../wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/eng/pipelines/coreclr/templates/run-scenarios-job.yml b/eng/pipelines/coreclr/templates/run-scenarios-job.yml index bc142530cc52df..abc340251c577b 100644 --- a/eng/pipelines/coreclr/templates/run-scenarios-job.yml +++ b/eng/pipelines/coreclr/templates/run-scenarios-job.yml @@ -142,7 +142,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/data && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest $(librariesDownloadDir)/bin/wasm && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.js $(librariesDownloadDir)/bin/wasm/data/test-main.js && + cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/data/test-main.mjs && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" condition: and(succeeded(), eq('${{ parameters.runtimeType }}', 'wasm')) diff --git a/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj b/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj index d43314d4b31826..32d53379d96005 100644 --- a/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj +++ b/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) true - $(MonoProjectRoot)\wasm\test-main.js + $(MonoProjectRoot)\wasm\test-main.mjs true true false From f8b415e319d201c268f21e2455c2c8d00cb02510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 15:04:55 +0200 Subject: [PATCH 66/77] WBT icu --- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 51137bf17b12da..808809bb5ddd54 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -738,20 +738,20 @@ void AssertIcuAssets() case GlobalizationMode.PredefinedIcu: if (string.IsNullOrEmpty(predefinedIcudt)) throw new ArgumentException("WasmBuildTest is invalid, value for predefinedIcudt is required when GlobalizationMode=PredefinedIcu."); - AssertFilesExist(bundleDir, new[] { predefinedIcudt }, expectToExist: true); + AssertFilesExist(bundleDir, new[] { Path.Combine("_framework", predefinedIcudt) }, expectToExist: true); // predefined ICU name can be identical with the icu files from runtime pack switch (predefinedIcudt) { - case "_framework/icudt.dat": + case "icudt.dat": expectFULL = true; break; - case "_framework/icudt_EFIGS.dat": + case "icudt_EFIGS.dat": expectEFIGS = true; break; - case "_framework/icudt_CJK.dat": + case "icudt_CJK.dat": expectCJK = true; break; - case "_framework/icudt_no_CJK.dat": + case "icudt_no_CJK.dat": expectNOCJK = true; break; } @@ -763,11 +763,13 @@ void AssertIcuAssets() expectNOCJK = true; break; } - AssertFilesExist(bundleDir, new[] { "_framework/icudt.dat" }, expectToExist: expectFULL); - AssertFilesExist(bundleDir, new[] { "_framework/icudt_EFIGS.dat" }, expectToExist: expectEFIGS); - AssertFilesExist(bundleDir, new[] { "_framework/icudt_CJK.dat" }, expectToExist: expectCJK); - AssertFilesExist(bundleDir, new[] { "_framework/icudt_no_CJK.dat" }, expectToExist: expectNOCJK); - AssertFilesExist(bundleDir, new[] { "_framework/icudt_hybrid.dat" }, expectToExist: expectHYBRID); + + var frameworkDir = Path.Combine(bundleDir, "_framework"); + AssertFilesExist(frameworkDir, new[] { "icudt.dat" }, expectToExist: expectFULL); + AssertFilesExist(frameworkDir, new[] { "icudt_EFIGS.dat" }, expectToExist: expectEFIGS); + AssertFilesExist(frameworkDir, new[] { "icudt_CJK.dat" }, expectToExist: expectCJK); + AssertFilesExist(frameworkDir, new[] { "icudt_no_CJK.dat" }, expectToExist: expectNOCJK); + AssertFilesExist(frameworkDir, new[] { "icudt_hybrid.dat" }, expectToExist: expectHYBRID); } } From aed2640b67e00bd826269ea9e009db16efc6b0bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 15:16:53 +0200 Subject: [PATCH 67/77] WBT templates --- .../wasm/Wasm.Build.Tests/NativeBuildTests.cs | 2 +- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 17 +++++++---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs index 65895c067380d9..efe75b94352dcc 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeBuildTests.cs @@ -205,7 +205,7 @@ public void ProjectWithDllImportsRequiringMarshalIlGen_ArrayTypeParameter(string CommandResult result = new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir) - .ExecuteWithCapturedOutput("build", $"-c {config} -bl /p:WasmRuntimeAssetsLocation=./"); + .ExecuteWithCapturedOutput("build", $"-c {config} -bl"); Assert.True(result.ExitCode == 0, "Expected build to succeed"); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 4620462a5bfe8f..feedb177958ffd 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -88,7 +88,7 @@ public void BrowserBuildThenPublish(string config) UpdateBrowserMainJs(DefaultTargetFramework); - var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, null); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -137,7 +137,7 @@ public void ConsoleBuildThenPublish(string config) UpdateConsoleMainJs(); - var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, null); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -209,7 +209,7 @@ private void ConsoleBuildAndRun(string config, bool relinking, string extraNewAr if (relinking) AddItemsPropertiesToProject(projectFile, "true"); - var buildArgs = new BuildArgs(projectName, config, false, id, "/p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, false, id, null); buildArgs = ExpandBuildArgs(buildArgs); BuildProject(buildArgs, @@ -259,7 +259,8 @@ void AddTestData(bool forConsole, bool runOutsideProjectDirectory) return data; } - [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + // [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + [Theory] [MemberData(nameof(TestDataForAppBundleDir))] public async Task RunWithDifferentAppBundleLocations(bool forConsole, bool runOutsideProjectDirectory, string extraProperties) => await (forConsole @@ -273,8 +274,6 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st UpdateBrowserMainJs(DefaultTargetFramework); - extraProperties += "./"; - if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -309,8 +308,6 @@ private Task ConsoleRunWithAndThenWithoutBuildAsync(string config, string extraP UpdateProgramCS(); UpdateConsoleMainJs(); - extraProperties += "./"; - if (!string.IsNullOrEmpty(extraProperties)) AddItemsPropertiesToProject(projectFile, extraProperties: extraProperties); @@ -386,7 +383,7 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) AddItemsPropertiesToProject(projectFile, "true"); } - var buildArgs = new BuildArgs(projectName, config, aot, id, "/p:WasmRuntimeAssetsLocation=./"); + var buildArgs = new BuildArgs(projectName, config, aot, id, null); buildArgs = ExpandBuildArgs(buildArgs); bool expectRelinking = config == "Release" || aot || relinking; @@ -441,7 +438,7 @@ public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} /p:WasmRuntimeAssetsLocation=./") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")}") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From 0445f7c87e91ecb21d3e3185147606e35943c486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 16:54:13 +0200 Subject: [PATCH 68/77] WBT with flat output --- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index feedb177958ffd..ecaa2c708e32ca 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -36,7 +36,7 @@ private void UpdateProgramCS() File.WriteAllText(path, text); } - private void UpdateBrowserMainJs(string targetFramework) + private void UpdateBrowserMainJs(string targetFramework, bool flatOutput = false) { string mainJsPath = Path.Combine(_projectDir!, "main.js"); string mainJsContent = File.ReadAllText(mainJsPath); @@ -46,6 +46,10 @@ private void UpdateBrowserMainJs(string targetFramework) targetFramework == "net8.0" ? ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().withExitOnUnhandledError().create()" : ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().create()"); + + if (flatOutput) + mainJsContent = mainJsContent.Replace("from './_framework/dotnet.js'", "from './dotnet.js'"); + File.WriteAllText(mainJsPath, mainJsContent); } @@ -424,21 +428,23 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) } [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - [InlineData("", BuildTestBase.DefaultTargetFramework)] + [InlineData("", BuildTestBase.DefaultTargetFramework, false)] + [InlineData("", BuildTestBase.DefaultTargetFramework, true)] // [ActiveIssue("https://github.com/dotnet/runtime/issues/79313")] // [InlineData("-f net7.0", "net7.0")] - [InlineData("-f net8.0", "net8.0")] - public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework) + [InlineData("-f net8.0", "net8.0", false)] + [InlineData("-f net8.0", "net8.0", true)] + public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework, bool flatOutput) { string config = "Debug"; string id = $"browser_{config}_{Path.GetRandomFileName()}"; CreateWasmTemplateProject(id, "wasmbrowser", extraNewArgs); - UpdateBrowserMainJs(targetFramework); + UpdateBrowserMainJs(targetFramework, flatOutput); new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")}") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {(flatOutput ? "-p:WasmRuntimeAssetsLocation=./" : "")}") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From d4c4db814a2074f3fabfb82bb10292e31f3a7aaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 21 Jun 2023 16:55:18 +0200 Subject: [PATCH 69/77] Always asume blazor.boot.json is next to the dotnet.js (if not specified otherwise) --- src/mono/wasm/runtime/loader/run.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/mono/wasm/runtime/loader/run.ts b/src/mono/wasm/runtime/loader/run.ts index a147f9fed19d5c..6d8b480554bb4b 100644 --- a/src/mono/wasm/runtime/loader/run.ts +++ b/src/mono/wasm/runtime/loader/run.ts @@ -395,13 +395,7 @@ async function createEmscriptenMain(): Promise { if (!module.configSrc && (!module.config || Object.keys(module.config).length === 0 || !module.config.assets)) { // if config file location nor assets are provided - if (loaderHelpers.scriptDirectory.indexOf("/_framework") == -1) { - // we are not inside _framework (= wasm template) - module.configSrc = "./_framework/blazor.boot.json"; - } else { - // blazor app - module.configSrc = "./blazor.boot.json"; - } + module.configSrc = "./blazor.boot.json"; } // download config From 71ec25074ac48fdc02092d061da2f6bf6e16953a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 23 Jun 2023 10:01:36 +0200 Subject: [PATCH 70/77] Feedback --- eng/pipelines/coreclr/templates/perf-job.yml | 2 +- .../coreclr/templates/run-scenarios-job.yml | 2 +- .../Wasm.Build.Tests/WasmTemplateTests.cs | 3 +- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 130 ++++++++++-------- 4 files changed, 75 insertions(+), 62 deletions(-) diff --git a/eng/pipelines/coreclr/templates/perf-job.yml b/eng/pipelines/coreclr/templates/perf-job.yml index d99bb835b43da5..33b00a32ce3fb6 100644 --- a/eng/pipelines/coreclr/templates/perf-job.yml +++ b/eng/pipelines/coreclr/templates/perf-job.yml @@ -196,7 +196,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest/* $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.mjs && + cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.js && find $(librariesDownloadDir)/bin/wasm -type d && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" diff --git a/eng/pipelines/coreclr/templates/run-scenarios-job.yml b/eng/pipelines/coreclr/templates/run-scenarios-job.yml index abc340251c577b..d8d54c7f2854a5 100644 --- a/eng/pipelines/coreclr/templates/run-scenarios-job.yml +++ b/eng/pipelines/coreclr/templates/run-scenarios-job.yml @@ -142,7 +142,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/data && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest $(librariesDownloadDir)/bin/wasm && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/data/test-main.mjs && + cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/data/test-main.js && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" condition: and(succeeded(), eq('${{ parameters.runtimeType }}', 'wasm')) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index ecaa2c708e32ca..c690bb9d1d13de 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -263,8 +263,7 @@ void AddTestData(bool forConsole, bool runOutsideProjectDirectory) return data; } - // [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - [Theory] + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] [MemberData(nameof(TestDataForAppBundleDir))] public async Task RunWithDifferentAppBundleLocations(bool forConsole, bool runOutsideProjectDirectory, string extraProperties) => await (forConsole diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 45632e49b31cde..25b0527f63d0f5 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -58,6 +58,28 @@ protected override bool ValidateArguments() return true; } + private ICUDataMode GetICUDataMode() + { + // Invariant has always precedence + if (InvariantGlobalization) + return ICUDataMode.Invariant; + + // If user provided a path to a custom ICU data file, use it + if (!string.IsNullOrEmpty(WasmIcuDataFileName)) + return ICUDataMode.Custom; + + // Hybrid mode + if (HybridGlobalization) + return ICUDataMode.Hybrid; + + // If user requested to include full ICU data, use it + if (WasmIncludeFullIcuData) + return ICUDataMode.All; + + // Otherwise, use sharded mode + return ICUDataMode.Sharded; + } + protected override bool ExecuteInternal() { if (!ValidateArguments()) @@ -71,28 +93,20 @@ protected override bool ExecuteInternal() } MainAssemblyName = Path.GetFileName(MainAssemblyName); - var config = new BootJsonData() + var bootConfig = new BootJsonData() { config = new(), entryAssembly = MainAssemblyName, - icuDataMode = InvariantGlobalization - ? ICUDataMode.Invariant - : !string.IsNullOrEmpty(WasmIcuDataFileName) - ? ICUDataMode.Custom - : HybridGlobalization - ? ICUDataMode.Hybrid - : WasmIncludeFullIcuData - ? ICUDataMode.All - : ICUDataMode.Sharded + icuDataMode = GetICUDataMode() }; // Create app - var frameworkPath = !string.IsNullOrEmpty(RuntimeAssetsLocation) + var runtimeAssetsPath = !string.IsNullOrEmpty(RuntimeAssetsLocation) ? Path.Combine(AppDir, RuntimeAssetsLocation) : AppDir; Directory.CreateDirectory(AppDir!); - Directory.CreateDirectory(frameworkPath); + Directory.CreateDirectory(runtimeAssetsPath); if (UseWebcil) Log.LogMessage(MessageImportance.Normal, "Converting assemblies to Webcil"); @@ -104,7 +118,7 @@ protected override bool ExecuteInternal() var tmpWebcil = Path.GetTempFileName(); var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: assembly, outputPath: tmpWebcil, logger: Log); webcilWriter.ConvertToWebcil(); - var finalWebcil = Path.Combine(frameworkPath, Path.ChangeExtension(Path.GetFileName(assembly), Utils.WebcilInWasmExtension)); + var finalWebcil = Path.Combine(runtimeAssetsPath, Path.ChangeExtension(Path.GetFileName(assembly), Utils.WebcilInWasmExtension)); if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true)) Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} ."); else @@ -113,21 +127,21 @@ protected override bool ExecuteInternal() } else { - FileCopyChecked(assembly, Path.Combine(frameworkPath, Path.GetFileName(assembly)), "Assemblies"); + FileCopyChecked(assembly, Path.Combine(runtimeAssetsPath, Path.GetFileName(assembly)), "Assemblies"); } if (DebugLevel != 0) { var pdb = assembly; pdb = Path.ChangeExtension(pdb, ".pdb"); if (File.Exists(pdb)) - FileCopyChecked(pdb, Path.Combine(frameworkPath, Path.GetFileName(pdb)), "Assemblies"); + FileCopyChecked(pdb, Path.Combine(runtimeAssetsPath, Path.GetFileName(pdb)), "Assemblies"); } } foreach (ITaskItem item in NativeAssets) { var name = Path.GetFileName(item.ItemSpec); - var dest = Path.Combine(frameworkPath, name); + var dest = Path.Combine(runtimeAssetsPath, name); if (!FileCopyChecked(item.ItemSpec, dest, "NativeAssets")) return false; @@ -138,17 +152,17 @@ protected override bool ExecuteInternal() if (name.StartsWith("dotnet", StringComparison.OrdinalIgnoreCase) && string.Equals(Path.GetExtension(name), ".wasm", StringComparison.OrdinalIgnoreCase)) { - if (config.resources.runtimeAssets == null) - config.resources.runtimeAssets = new(); + if (bootConfig.resources.runtimeAssets == null) + bootConfig.resources.runtimeAssets = new(); - config.resources.runtimeAssets[name] = new() + bootConfig.resources.runtimeAssets[name] = new() { hash = itemHash, behavior = "dotnetwasm" }; } - config.resources.runtime[name] = itemHash; + bootConfig.resources.runtime[name] = itemHash; } string packageJsonPath = Path.Combine(AppDir, "package.json"); @@ -171,60 +185,60 @@ protected override bool ExecuteInternal() { if (UseWebcil) { - assemblyPath = Path.Combine(frameworkPath, Path.ChangeExtension(Path.GetFileName(assembly), Utils.WebcilInWasmExtension)); + assemblyPath = Path.Combine(runtimeAssetsPath, Path.ChangeExtension(Path.GetFileName(assembly), Utils.WebcilInWasmExtension)); // For the hash, read the bytes from the webcil file, not the dll file. bytes = File.ReadAllBytes(assemblyPath); } - config.resources.assembly[Path.GetFileName(assemblyPath)] = Utils.ComputeIntegrity(bytes); + bootConfig.resources.assembly[Path.GetFileName(assemblyPath)] = Utils.ComputeIntegrity(bytes); if (DebugLevel != 0) { var pdb = Path.ChangeExtension(assembly, ".pdb"); if (File.Exists(pdb)) { - if (config.resources.pdb == null) - config.resources.pdb = new(); + if (bootConfig.resources.pdb == null) + bootConfig.resources.pdb = new(); - config.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); + bootConfig.resources.pdb[Path.GetFileName(pdb)] = Utils.ComputeIntegrity(pdb); } } } } - config.debugBuild = DebugLevel > 0; + bootConfig.debugBuild = DebugLevel > 0; ProcessSatelliteAssemblies(args => { - if (config.resources.satelliteResources == null) - config.resources.satelliteResources = new(); + if (bootConfig.resources.satelliteResources == null) + bootConfig.resources.satelliteResources = new(); string name = Path.GetFileName(args.fullPath); - string directory = Path.Combine(frameworkPath, args.culture); - Directory.CreateDirectory(directory); + string cultureDirectory = Path.Combine(runtimeAssetsPath, args.culture); + Directory.CreateDirectory(cultureDirectory); if (UseWebcil) { var tmpWebcil = Path.GetTempFileName(); var webcilWriter = Microsoft.WebAssembly.Build.Tasks.WebcilConverter.FromPortableExecutable(inputPath: args.fullPath, outputPath: tmpWebcil, logger: Log); webcilWriter.ConvertToWebcil(); - var finalWebcil = Path.Combine(directory, Path.ChangeExtension(name, Utils.WebcilInWasmExtension)); + var finalWebcil = Path.Combine(cultureDirectory, Path.ChangeExtension(name, Utils.WebcilInWasmExtension)); if (Utils.CopyIfDifferent(tmpWebcil, finalWebcil, useHash: true)) Log.LogMessage(MessageImportance.Low, $"Generated {finalWebcil} ."); else Log.LogMessage(MessageImportance.Low, $"Skipped generating {finalWebcil} as the contents are unchanged."); _fileWrites.Add(finalWebcil); - if (!config.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) - config.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); + if (!bootConfig.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) + bootConfig.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); cultureSatelliteResources[Path.GetFileName(finalWebcil)] = Utils.ComputeIntegrity(finalWebcil); } else { - var satellitePath = Path.Combine(directory, name); + var satellitePath = Path.Combine(cultureDirectory, name); FileCopyChecked(args.fullPath, satellitePath, "SatelliteAssemblies"); - if (!config.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) - config.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); + if (!bootConfig.resources.satelliteResources.TryGetValue(args.culture, out var cultureSatelliteResources)) + bootConfig.resources.satelliteResources[args.culture] = cultureSatelliteResources = new(); cultureSatelliteResources[name] = Utils.ComputeIntegrity(satellitePath); } @@ -232,7 +246,7 @@ protected override bool ExecuteInternal() if (FilesToIncludeInFileSystem.Length > 0) { - string supportFilesDir = Path.Combine(frameworkPath, "supportFiles"); + string supportFilesDir = Path.Combine(runtimeAssetsPath, "supportFiles"); Directory.CreateDirectory(supportFilesDir); var i = 0; @@ -275,7 +289,7 @@ protected override bool ExecuteInternal() } if (vfs.Count > 0) - config.resources.vfs = vfs; + bootConfig.resources.vfs = vfs; } if (!InvariantGlobalization) @@ -289,17 +303,17 @@ protected override bool ExecuteInternal() return false; } - config.resources.runtime[Path.GetFileName(idfn)] = Utils.ComputeIntegrity(idfn); + bootConfig.resources.runtime[Path.GetFileName(idfn)] = Utils.ComputeIntegrity(idfn); } } if (RemoteSources?.Length > 0) { - config.resources.remoteSources = new(); + bootConfig.resources.remoteSources = new(); foreach (var source in RemoteSources) if (source != null && source.ItemSpec != null) - config.resources.remoteSources.Add(source.ItemSpec); + bootConfig.resources.remoteSources.Add(source.ItemSpec); } var extraConfiguration = new Dictionary(); @@ -310,7 +324,7 @@ protected override bool ExecuteInternal() } else if (PThreadPoolSize > -1) { - config.pthreadPoolSize = PThreadPoolSize; + bootConfig.pthreadPoolSize = PThreadPoolSize; } foreach (ITaskItem extra in ExtraConfig ?? Enumerable.Empty()) @@ -319,14 +333,14 @@ protected override bool ExecuteInternal() if (!TryParseExtraConfigValue(extra, out object? valueObject)) return false; - if (name == "environmentVariables") + if (string.Equals(name, nameof(BootJsonData.environmentVariables), StringComparison.OrdinalIgnoreCase)) { - config.environmentVariables = valueObject; + bootConfig.environmentVariables = valueObject; } - else if (name == "diagnosticTracing") + else if (string.Equals(name, nameof(BootJsonData.diagnosticTracing), StringComparison.OrdinalIgnoreCase)) { if (valueObject is bool boolValue || (valueObject is string stringValue && bool.TryParse(stringValue, out boolValue))) - config.diagnosticTracing = boolValue; + bootConfig.diagnosticTracing = boolValue; else throw new LogAsErrorException($"Unsupported value '{valueObject}' of type '{valueObject?.GetType()?.FullName}' for extra config 'diagnosticTracing'."); } @@ -338,7 +352,7 @@ protected override bool ExecuteInternal() if (extraConfiguration.Count > 0) { - config.extensions = new() + bootConfig.extensions = new() { ["extra"] = extraConfiguration }; @@ -355,31 +369,31 @@ static void AddDictionary(StringBuilder sb, Dictionary res) sb.Append(asset.Value); } - AddDictionary(sb, config.resources.assembly); - AddDictionary(sb, config.resources.runtime); + AddDictionary(sb, bootConfig.resources.assembly); + AddDictionary(sb, bootConfig.resources.runtime); - if (config.resources.lazyAssembly != null) - AddDictionary(sb, config.resources.lazyAssembly); + if (bootConfig.resources.lazyAssembly != null) + AddDictionary(sb, bootConfig.resources.lazyAssembly); - if (config.resources.satelliteResources != null) + if (bootConfig.resources.satelliteResources != null) { - foreach (var culture in config.resources.satelliteResources) + foreach (var culture in bootConfig.resources.satelliteResources) AddDictionary(sb, culture.Value); } - if (config.resources.vfs != null) + if (bootConfig.resources.vfs != null) { - foreach (var entry in config.resources.vfs) + foreach (var entry in bootConfig.resources.vfs) AddDictionary(sb, entry.Value); } - config.resources.hash = Utils.ComputeTextIntegrity(sb.ToString()); + bootConfig.resources.hash = Utils.ComputeTextIntegrity(sb.ToString()); - var json = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true }); + var json = JsonSerializer.Serialize(bootConfig, new JsonSerializerOptions { WriteIndented = true }); sw.Write(json); } - string monoConfigPath = Path.Combine(frameworkPath, "blazor.boot.json"); // TODO: Unify with Wasm SDK + string monoConfigPath = Path.Combine(runtimeAssetsPath, "blazor.boot.json"); // TODO: Unify with Wasm SDK Utils.CopyIfDifferent(tmpMonoConfigPath, monoConfigPath, useHash: false); _fileWrites.Add(monoConfigPath); From 023387ffa045faa741141a95817313d9bd2d5e79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 23 Jun 2023 11:04:29 +0200 Subject: [PATCH 71/77] Feedback WBT templates --- .../Wasm.Build.Tests/WasmTemplateTests.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index c690bb9d1d13de..88af535d0895d1 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -36,7 +36,9 @@ private void UpdateProgramCS() File.WriteAllText(path, text); } - private void UpdateBrowserMainJs(string targetFramework, bool flatOutput = false) + private const string DefaultRuntimeAssetsRelativePath = "./_framework/"; + + private void UpdateBrowserMainJs(string targetFramework, string runtimeAssetsRelativePath = DefaultRuntimeAssetsRelativePath) { string mainJsPath = Path.Combine(_projectDir!, "main.js"); string mainJsContent = File.ReadAllText(mainJsPath); @@ -47,8 +49,7 @@ private void UpdateBrowserMainJs(string targetFramework, bool flatOutput = false ? ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().withExitOnUnhandledError().create()" : ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().create()"); - if (flatOutput) - mainJsContent = mainJsContent.Replace("from './_framework/dotnet.js'", "from './dotnet.js'"); + mainJsContent = mainJsContent.Replace("from './_framework/dotnet.js'", $"from '{runtimeAssetsRelativePath}dotnet.js'"); File.WriteAllText(mainJsPath, mainJsContent); } @@ -427,23 +428,23 @@ public void ConsolePublishAndRun(string config, bool aot, bool relinking) } [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - [InlineData("", BuildTestBase.DefaultTargetFramework, false)] - [InlineData("", BuildTestBase.DefaultTargetFramework, true)] + [InlineData("", BuildTestBase.DefaultTargetFramework, DefaultRuntimeAssetsRelativePath)] + [InlineData("", BuildTestBase.DefaultTargetFramework, "./")] // [ActiveIssue("https://github.com/dotnet/runtime/issues/79313")] // [InlineData("-f net7.0", "net7.0")] - [InlineData("-f net8.0", "net8.0", false)] - [InlineData("-f net8.0", "net8.0", true)] - public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework, bool flatOutput) + [InlineData("-f net8.0", "net8.0", DefaultRuntimeAssetsRelativePath)] + [InlineData("-f net8.0", "net8.0", "./")] + public async Task BrowserBuildAndRun(string extraNewArgs, string targetFramework, string runtimeAssetsRelativePath) { string config = "Debug"; string id = $"browser_{config}_{Path.GetRandomFileName()}"; CreateWasmTemplateProject(id, "wasmbrowser", extraNewArgs); - UpdateBrowserMainJs(targetFramework, flatOutput); + UpdateBrowserMainJs(targetFramework, runtimeAssetsRelativePath); new DotNetCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!) - .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {(flatOutput ? "-p:WasmRuntimeAssetsLocation=./" : "")}") + .Execute($"build -c {config} -bl:{Path.Combine(s_buildEnv.LogRootPath, $"{id}.binlog")} {(runtimeAssetsRelativePath != DefaultRuntimeAssetsRelativePath ? "-p:WasmRuntimeAssetsLocation=" + runtimeAssetsRelativePath : "")}") .EnsureSuccessful(); using var runCommand = new RunCommand(s_buildEnv, _testOutput) From e690d6e22d3f29f5bc3ad2b45612e2d2b3c4e144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 23 Jun 2023 11:06:10 +0200 Subject: [PATCH 72/77] Feedback symbols --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index fe28a88cd91f1b..c64f27bc957f63 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -37,7 +37,7 @@ const behaviorByName = (name: string): AssetBehaviours | "other" => { : (name.startsWith("dotnet.native") && name.endsWith(".js")) ? "js-module-native" : (name.startsWith("dotnet.runtime") && name.endsWith(".js")) ? "js-module-runtime" : (name.startsWith("dotnet") && name.endsWith(".js")) ? "js-module-dotnet" - : (name.startsWith("dotnet") && name.endsWith(".symbols")) ? "symbols" + : (name.startsWith("dotnet.native") && name.endsWith(".symbols")) ? "symbols" : name.startsWith("icudt") ? "icu" : "other"; }; From 6c7eb287466cce9507325a644c896355a2e9f6d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 23 Jun 2023 11:28:46 +0200 Subject: [PATCH 73/77] DebugLevel --- src/mono/wasm/runtime/loader/blazor/_Integration.ts | 2 +- src/mono/wasm/runtime/loader/blazor/_Polyfill.ts | 4 +--- src/mono/wasm/runtime/types/blazor.ts | 1 + .../Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs | 5 +++++ .../GenerateWasmBootJson.cs | 1 + src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 1 + 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/loader/blazor/_Integration.ts b/src/mono/wasm/runtime/loader/blazor/_Integration.ts index c64f27bc957f63..32ca65ae28e719 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Integration.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Integration.ts @@ -102,7 +102,7 @@ export function mapBootConfigToMonoConfig(moduleConfig: MonoConfigInternal, appl moduleConfig.assetsHash = resourceLoader.bootConfig.resources.hash; moduleConfig.assets = assets; moduleConfig.globalizationMode = "icu"; - moduleConfig.debugLevel = hasDebuggingEnabled(resourceLoader.bootConfig) ? 1 : 0; + moduleConfig.debugLevel = hasDebuggingEnabled(resourceLoader.bootConfig) ? resourceLoader.bootConfig.debugLevel : 0; moduleConfig.mainAssemblyName = resourceLoader.bootConfig.entryAssembly; const anyBootConfig = (resourceLoader.bootConfig as any); diff --git a/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts b/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts index 5ae85498e2e907..efe700b72bcca3 100644 --- a/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts +++ b/src/mono/wasm/runtime/loader/blazor/_Polyfill.ts @@ -18,7 +18,5 @@ export function hasDebuggingEnabled(bootConfig: BootJsonData): boolean { } const hasReferencedPdbs = !!bootConfig.resources.pdb; - const debugBuild = bootConfig.debugBuild; - - return (hasReferencedPdbs || debugBuild) && (loaderHelpers.isChromium || loaderHelpers.isFirefox); + return (hasReferencedPdbs || bootConfig.debugBuild || bootConfig.debugLevel != 0) && (loaderHelpers.isChromium || loaderHelpers.isFirefox); } \ No newline at end of file diff --git a/src/mono/wasm/runtime/types/blazor.ts b/src/mono/wasm/runtime/types/blazor.ts index 2b89c6e6983600..20cfb1a97c0cf0 100644 --- a/src/mono/wasm/runtime/types/blazor.ts +++ b/src/mono/wasm/runtime/types/blazor.ts @@ -7,6 +7,7 @@ export interface BootJsonData { readonly resources: ResourceGroups; /** Gets a value that determines if this boot config was produced from a non-published build (i.e. dotnet build or dotnet run) */ readonly debugBuild: boolean; + readonly debugLevel: number; readonly linkerEnabled: boolean; readonly cacheBootResources: boolean; readonly config: string[]; 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 e7f624c2180b51..bf4beb053507fe 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/BootJsonData.cs @@ -41,6 +41,11 @@ public class BootJsonData /// public bool debugBuild { get; set; } + /// + /// Gets a value that determines what level of debugging is configured. + /// + public int debugLevel { get; set; } + /// /// Gets a value that determines if the linker is enabled. /// 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 d6da72cfc330ae..9690097816258d 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -103,6 +103,7 @@ public void WriteBootJson(Stream output, string entryAssemblyName) entryAssembly = entryAssemblyName, cacheBootResources = CacheBootResources, debugBuild = DebugBuild, + debugLevel = DebugBuild ? 1 : 0, linkerEnabled = LinkerEnabled, resources = new ResourcesData(), config = new List(), diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 25b0527f63d0f5..c6c6c2fc9918b8 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -206,6 +206,7 @@ protected override bool ExecuteInternal() } bootConfig.debugBuild = DebugLevel > 0; + bootConfig.debugLevel = DebugLevel; ProcessSatelliteAssemblies(args => { From ccf8234698512f725a5934dee6f68001dbdac3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 23 Jun 2023 14:15:51 +0200 Subject: [PATCH 74/77] Feedback WasmRuntimeAssetsLocation message --- src/mono/wasm/build/WasmApp.targets | 11 +++-------- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 2 ++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 9c9b285caabaf5..2f8c5ab73014c2 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -141,6 +141,8 @@ true + + _framework @@ -368,18 +370,11 @@ - - - - _framework - - - + DependsOnTargets="_WasmGenerateRuntimeConfig;_GetWasmGenerateAppBundleDependencies"> diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index c6c6c2fc9918b8..88cf5faf255f30 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -105,6 +105,8 @@ protected override bool ExecuteInternal() ? Path.Combine(AppDir, RuntimeAssetsLocation) : AppDir; + Log.LogMessage(MessageImportance.Low, $"Runtime assets output path {runtimeAssetsPath}"); + Directory.CreateDirectory(AppDir!); Directory.CreateDirectory(runtimeAssetsPath); From 2e119ce7e2fddf6d662263e487c40992c924d1bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Tue, 27 Jun 2023 20:46:47 +0200 Subject: [PATCH 75/77] Revert "Rename test-main.js to test-main.mjs" --- eng/pipelines/coreclr/templates/perf-job.yml | 2 +- .../coreclr/templates/run-scenarios-job.yml | 2 +- eng/testing/WasmRunnerAOTTemplate.sh | 2 +- eng/testing/WasmRunnerTemplate.cmd | 2 +- eng/testing/WasmRunnerTemplate.sh | 2 +- eng/testing/tests.browser.targets | 2 +- .../wasm/browser-bench/Console/Makefile | 2 +- .../Console/Wasm.Console.Bench.Sample.csproj | 2 +- .../wasi/Wasi.Build.Tests/BuildTestBase.cs | 84 +++++++++---------- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 12 +-- .../SatelliteAssembliesTests.cs | 6 +- .../Wasm.Build.Tests/Wasm.Build.Tests.csproj | 2 +- .../WasmRunOutOfAppBundleTests.cs | 6 +- .../aot-tests/ProxyProjectForAOTOnHelix.proj | 2 +- src/mono/wasm/{test-main.mjs => test-main.js} | 2 +- src/tests/Common/Directory.Build.targets | 2 +- .../wasm-test-runner/WasmTestRunner.proj | 4 +- src/tests/Common/wasm-test-runner/index.html | 8 +- 18 files changed, 69 insertions(+), 75 deletions(-) rename src/mono/wasm/{test-main.mjs => test-main.js} (99%) diff --git a/eng/pipelines/coreclr/templates/perf-job.yml b/eng/pipelines/coreclr/templates/perf-job.yml index 33b00a32ce3fb6..d0bc486d4b4041 100644 --- a/eng/pipelines/coreclr/templates/perf-job.yml +++ b/eng/pipelines/coreclr/templates/perf-job.yml @@ -196,7 +196,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest/* $(librariesDownloadDir)/bin/wasm/dotnet && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.js && + cp src/mono/wasm/test-main.js $(librariesDownloadDir)/bin/wasm/wasm-data/test-main.js && find $(librariesDownloadDir)/bin/wasm -type d && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" diff --git a/eng/pipelines/coreclr/templates/run-scenarios-job.yml b/eng/pipelines/coreclr/templates/run-scenarios-job.yml index d8d54c7f2854a5..bc142530cc52df 100644 --- a/eng/pipelines/coreclr/templates/run-scenarios-job.yml +++ b/eng/pipelines/coreclr/templates/run-scenarios-job.yml @@ -142,7 +142,7 @@ jobs: mkdir -p $(librariesDownloadDir)/bin/wasm/data && cp -r $(librariesDownloadDir)/BrowserWasm/staging/dotnet-latest $(librariesDownloadDir)/bin/wasm && cp -r $(librariesDownloadDir)/BrowserWasm/staging/built-nugets $(librariesDownloadDir)/bin/wasm && - cp src/mono/wasm/test-main.mjs $(librariesDownloadDir)/bin/wasm/data/test-main.js && + cp src/mono/wasm/test-main.js $(librariesDownloadDir)/bin/wasm/data/test-main.js && find $(librariesDownloadDir)/bin/wasm -type f -exec chmod 664 {} \; displayName: "Create wasm directory (Linux)" condition: and(succeeded(), eq('${{ parameters.runtimeType }}', 'wasm')) diff --git a/eng/testing/WasmRunnerAOTTemplate.sh b/eng/testing/WasmRunnerAOTTemplate.sh index 4267d67afbed85..856fb7ebbea1bc 100644 --- a/eng/testing/WasmRunnerAOTTemplate.sh +++ b/eng/testing/WasmRunnerAOTTemplate.sh @@ -53,7 +53,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then fi if [[ -z "$MAIN_JS" ]]; then - MAIN_JS="--js-file=test-main.mjs" + MAIN_JS="--js-file=test-main.js" fi fi diff --git a/eng/testing/WasmRunnerTemplate.cmd b/eng/testing/WasmRunnerTemplate.cmd index df51838661beb6..a8c9c0ac571269 100644 --- a/eng/testing/WasmRunnerTemplate.cmd +++ b/eng/testing/WasmRunnerTemplate.cmd @@ -41,7 +41,7 @@ if /I [%XHARNESS_COMMAND%] == [test] ( ) ) if [%MAIN_JS%] == [] ( - set "MAIN_JS=--js-file^=test-main.mjs" + set "MAIN_JS=--js-file^=test-main.js" ) if [%JS_ENGINE_ARGS%] == [] ( diff --git a/eng/testing/WasmRunnerTemplate.sh b/eng/testing/WasmRunnerTemplate.sh index 18e8f22ffb1735..8b4e9adb10c2ef 100644 --- a/eng/testing/WasmRunnerTemplate.sh +++ b/eng/testing/WasmRunnerTemplate.sh @@ -43,7 +43,7 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then fi if [[ -z "$MAIN_JS" ]]; then - MAIN_JS="--js-file=test-main.mjs" + MAIN_JS="--js-file=test-main.js" fi if [[ -z "$JS_ENGINE_ARGS" ]]; then diff --git a/eng/testing/tests.browser.targets b/eng/testing/tests.browser.targets index 600147e005912c..837c0589501f2e 100644 --- a/eng/testing/tests.browser.targets +++ b/eng/testing/tests.browser.targets @@ -157,7 +157,7 @@ $(BundleDir) WasmTestRunner.dll - $(MonoProjectRoot)\wasm\test-main.mjs + $(MonoProjectRoot)\wasm\test-main.js $([System.IO.Path]::GetFileName('$(WasmMainJSPath)')) $(PublishDir)index.html $(InvariantGlobalization) diff --git a/src/mono/sample/wasm/browser-bench/Console/Makefile b/src/mono/sample/wasm/browser-bench/Console/Makefile index 3e4e9a0d587ca6..d301744fe74ee4 100644 --- a/src/mono/sample/wasm/browser-bench/Console/Makefile +++ b/src/mono/sample/wasm/browser-bench/Console/Makefile @@ -8,7 +8,7 @@ endif PROJECT_NAME=Wasm.Console.Bench.Sample.csproj CONSOLE_DLL=Wasm.Console.Bench.Sample.dll -MAIN_JS=test-main.mjs +MAIN_JS=test-main.js ARGS= run: run-console diff --git a/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj b/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj index 32d53379d96005..d43314d4b31826 100644 --- a/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj +++ b/src/mono/sample/wasm/browser-bench/Console/Wasm.Console.Bench.Sample.csproj @@ -2,7 +2,7 @@ $(NetCoreAppCurrent) true - $(MonoProjectRoot)\wasm\test-main.mjs + $(MonoProjectRoot)\wasm\test-main.js true true false diff --git a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs index d2851e44fef520..e2980fc735746a 100644 --- a/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs @@ -37,7 +37,7 @@ public abstract class BuildTestBase : IClassFixture !s_buildEnv.IsWorkload; public static string GetNuGetConfigPathFor(string targetFramework) => Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with - // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config"); + // targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config"); static BuildTestBase() { @@ -69,15 +69,15 @@ static BuildTestBase() else s_xharnessRunnerCommand = EnvironmentVariables.XHarnessCliPath; - Console.WriteLine(""); - Console.WriteLine($"=============================================================================================="); - Console.WriteLine($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ==============="); - Console.WriteLine($"=============================================================================================="); - Console.WriteLine(""); + Console.WriteLine (""); + Console.WriteLine ($"=============================================================================================="); + Console.WriteLine ($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ==============="); + Console.WriteLine ($"=============================================================================================="); + Console.WriteLine (""); } catch (Exception ex) { - Console.WriteLine($"Exception: {ex}"); + Console.WriteLine ($"Exception: {ex}"); throw; } } @@ -90,7 +90,7 @@ public BuildTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture bu _logPath = s_buildEnv.LogRootPath; // FIXME: } - public static IEnumerable> ConfigWithAOTData(bool aot, string? config = null) + public static IEnumerable> ConfigWithAOTData(bool aot, string? config=null) { if (config == null) { @@ -154,7 +154,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = {DefaultTargetFramework} Exe true - test-main.mjs + test-main.js ##EXTRA_PROPERTIES## @@ -163,7 +163,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = ##INSERT_AT_END## "; - protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties = "", string extraItems = "", string insertAtEnd = "", string projectTemplate = SimpleProjectTemplate) + protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties="", string extraItems="", string insertAtEnd="", string projectTemplate=SimpleProjectTemplate) { if (buildArgs.AOT) { @@ -185,7 +185,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp string msgPrefix = options.Label != null ? $"[{options.Label}] " : string.Empty; if (options.UseCache && _buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product)) { - _testOutput.WriteLine($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}"); + _testOutput.WriteLine ($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}"); if (!product.Result) throw new XunitException($"Found existing build at {product.ProjectDir}, but it had failed. Check build log at {product.LogFile}"); @@ -204,8 +204,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents); File.Copy(Path.Combine(AppContext.BaseDirectory, - options.TargetFramework == "net8.0" ? "test-main.mjs" : "data/test-main-7.0.js"), - Path.Combine(_projectDir, "test-main.mjs")); + options.TargetFramework == "net8.0" ? "test-main.js" : "data/test-main-7.0.js"), + Path.Combine(_projectDir, "test-main.js")); } else if (_projectDir is null) { @@ -254,7 +254,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp AssertBasicAppBundle(bundleDir, buildArgs.ProjectName, buildArgs.Config, - options.MainJS ?? "test-main.mjs", + options.MainJS ?? "test-main.js", options.HasV8Script, options.TargetFramework ?? DefaultTargetFramework, options.HasIcudt, @@ -309,7 +309,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse return projectfile; } - protected (CommandResult, string) BuildInternal(string id, string config, bool publish = false, bool setWasmDevel = true, params string[] extraArgs) + protected (CommandResult, string) BuildInternal(string id, string config, bool publish=false, bool setWasmDevel=true, params string[] extraArgs) { string label = publish ? "publish" : "build"; _testOutput.WriteLine($"{Environment.NewLine}** {label} **{Environment.NewLine}"); @@ -392,7 +392,7 @@ protected static void AssertBasicAppBundle(string bundleDir, protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null) => AssertFilesExist(dir, filenames, label, expectToExist: false); - protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist = true) + protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist=true) { string prefix = label != null ? $"{label}: " : string.Empty; if (!Directory.Exists(dir)) @@ -408,10 +408,10 @@ protected static void AssertFilesExist(string dir, string[] filenames, string? l } } - protected static void AssertSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: true); - protected static void AssertNotSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: false); + protected static void AssertSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: true); + protected static void AssertNotSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: false); - protected static void AssertFile(string file0, string file1, string? label = null, bool same = true) + protected static void AssertFile(string file0, string file1, string? label=null, bool same=true) { Assert.True(File.Exists(file0), $"{label}: Expected to find {file0}"); Assert.True(File.Exists(file1), $"{label}: Expected to find {file1}"); @@ -426,7 +426,7 @@ protected static void AssertFile(string file0, string file1, string? label = nul throw new XunitException($"{label}:{Environment.NewLine} File sizes should not match for {file0} ({finfo0.Length}), and {file1} ({finfo1.Length})"); } - protected (int exitCode, string buildOutput) AssertBuild(string args, string label = "build", bool expectSuccess = true, IDictionary? envVars = null, int? timeoutMs = null) + protected (int exitCode, string buildOutput) AssertBuild(string args, string label="build", bool expectSuccess=true, IDictionary? envVars=null, int? timeoutMs=null) { var result = RunProcess(s_buildEnv.DotNet, _testOutput, args, workingDir: _projectDir, label: label, envVars: envVars, timeoutMs: timeoutMs ?? s_defaultPerTestTimeoutMs); if (expectSuccess && result.exitCode != 0) @@ -450,14 +450,14 @@ private string FindSubDirIgnoringCase(string parentDir, string dirName) return first ?? Path.Combine(parentDir, dirName); } - protected string GetBinDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null) + protected string GetBinDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null) { var dir = baseDir ?? _projectDir; Assert.NotNull(dir); return Path.Combine(dir!, "bin", config, targetFramework, BuildEnvironment.DefaultRuntimeIdentifier); } - protected string GetObjDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null) + protected string GetObjDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null) { var dir = baseDir ?? _projectDir; Assert.NotNull(dir); @@ -489,7 +489,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path, { _testOutput.WriteLine($"Running {path} {args}"); _testOutput.WriteLine($"WorkingDirectory: {workingDir}"); - StringBuilder outputBuilder = new(); + StringBuilder outputBuilder = new (); object syncObj = new(); var processStartInfo = new ProcessStartInfo @@ -523,7 +523,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path, processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath"); } - Process process = new(); + Process process = new (); process.StartInfo = processStartInfo; process.EnableRaisingEvents = true; @@ -596,7 +596,7 @@ void LogData(string label, string? message) } } - public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties = null, string? extraItems = null, string? atTheEnd = null) + public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties=null, string? extraItems=null, string? atTheEnd=null) { if (extraProperties == null && extraItems == null && atTheEnd == null) return projectFile; @@ -643,7 +643,7 @@ private static string GetEnvironmentVariableOrDefault(string envVarName, string return string.IsNullOrEmpty(value) ? defaultValue : value; } - internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish = true) + internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish=true) { string objDir = GetObjDir(buildArgs.Config); string bundleDir = Path.Combine(GetBinDir(baseDir: _projectDir, config: buildArgs.Config), "AppBundle"); @@ -686,25 +686,25 @@ public record BuildArgs(string ProjectName, string ProjectFileContents, string? ExtraBuildArgs); public record BuildProduct(string ProjectDir, string LogFile, bool Result); - internal record FileStat(bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath); + internal record FileStat (bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath); internal record BuildPaths(string ObjWasmDir, string ObjDir, string BinDir, string BundleDir); public record BuildProjectOptions ( - Action? InitProject = null, - bool? DotnetWasmFromRuntimePack = null, - bool HasIcudt = true, - bool UseCache = true, - bool ExpectSuccess = true, - bool AssertAppBundle = true, - bool CreateProject = true, - bool Publish = true, - bool BuildOnlyAfterPublish = true, - bool HasV8Script = true, - string? Verbosity = null, - string? Label = null, - string? TargetFramework = null, - string? MainJS = null, + Action? InitProject = null, + bool? DotnetWasmFromRuntimePack = null, + bool HasIcudt = true, + bool UseCache = true, + bool ExpectSuccess = true, + bool AssertAppBundle = true, + bool CreateProject = true, + bool Publish = true, + bool BuildOnlyAfterPublish = true, + bool HasV8Script = true, + string? Verbosity = null, + string? Label = null, + string? TargetFramework = null, + string? MainJS = null, IDictionary? ExtraBuildEnvironmentVariables = null ); diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 808809bb5ddd54..1966ca35c68643 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -155,7 +155,7 @@ protected string RunAndTestWasmApp(BuildArgs buildArgs, string targetFramework = DefaultTargetFramework, string? extraXHarnessMonoArgs = null, string? extraXHarnessArgs = null, - string jsRelativePath = "test-main.mjs", + string jsRelativePath = "test-main.js", string environmentLocale = DefaultEnvironmentLocale) { buildDir ??= _projectDir; @@ -330,7 +330,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = {DefaultTargetFramework} Exe true - test-main.mjs + test-main.js ##EXTRA_PROPERTIES## @@ -390,13 +390,13 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp Path.Combine( AppContext.BaseDirectory, string.IsNullOrEmpty(options.TargetFramework) || options.TargetFramework == "net8.0" - ? "test-main.mjs" + ? "test-main.js" : "data/test-main-7.0.js" ), - Path.Combine(_projectDir, "test-main.mjs") + Path.Combine(_projectDir, "test-main.js") ); - File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); + File.WriteAllText(Path.Combine(_projectDir!, "index.html"), @""); } else if (_projectDir is null) { @@ -445,7 +445,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp AssertBasicAppBundle(bundleDir, buildArgs.ProjectName, buildArgs.Config, - options.MainJS ?? "test-main.mjs", + options.MainJS ?? "test-main.js", options.HasV8Script, options.TargetFramework ?? DefaultTargetFramework, options.GlobalizationMode, diff --git a/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs b/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs index ef079071b5d036..b7c95aaae91e36 100644 --- a/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs @@ -30,7 +30,7 @@ public SatelliteAssembliesTests(ITestOutputHelper output, SharedBuildPerTestClas [Theory] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ false, RunHost.All })] - [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] + [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ true, /*relinking*/ false, RunHost.All })] public void ResourcesFromMainAssembly(BuildArgs buildArgs, bool nativeRelink, @@ -72,7 +72,7 @@ public void ResourcesFromMainAssembly(BuildArgs buildArgs, [Theory] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ false, RunHost.All })] - [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] + [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ false, /*relinking*/ true, RunHost.All })] [MemberData(nameof(SatelliteAssemblyTestData), parameters: new object[] { /*aot*/ true, /*relinking*/ false, RunHost.All })] public void ResourcesFromProjectReference(BuildArgs buildArgs, bool nativeRelink, @@ -167,7 +167,7 @@ private void CreateProgramForCultureTest(string dir, string resourceName, string {DefaultTargetFramework} Exe true - test-main.mjs + test-main.js ##EXTRA_PROPERTIES## 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 019d01ddfb1bcf..0ff15466c29ef6 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj +++ b/src/mono/wasm/Wasm.Build.Tests/Wasm.Build.Tests.csproj @@ -36,7 +36,7 @@ - + diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs index 84a99fb7c4c5cb..befd7ae029813d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmRunOutOfAppBundleTests.cs @@ -12,7 +12,7 @@ namespace Wasm.Build.Tests; public class WasmRunOutOfAppBundleTests : BuildTestBase { public WasmRunOutOfAppBundleTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) : base(output, buildContext) - { } + {} [Theory] [BuildAndRun] @@ -41,7 +41,7 @@ public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id) indexHtmlPath = Path.Combine(outerDir, "index.html"); if (!File.Exists(indexHtmlPath)) { - var html = @""; + var html = @""; File.WriteAllText(indexHtmlPath, html); } } @@ -51,6 +51,6 @@ public void RunOutOfAppBundle(BuildArgs buildArgs, RunHost host, string id) host: host, id: id, bundleDir: outerDir, - jsRelativePath: "./AppBundle/test-main.mjs"); + jsRelativePath: "./AppBundle/test-main.js"); } } diff --git a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj index f450d21cfbb739..e5940d2784ae8d 100644 --- a/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj +++ b/src/mono/wasm/data/aot-tests/ProxyProjectForAOTOnHelix.proj @@ -30,7 +30,7 @@ $(TestRootDir)AppBundle\ $(OriginalPublishDir)WasmTestRunner.dll - $(OriginalPublishDir)test-main.mjs + $(OriginalPublishDir)test-main.js true diff --git a/src/mono/wasm/test-main.mjs b/src/mono/wasm/test-main.js similarity index 99% rename from src/mono/wasm/test-main.mjs rename to src/mono/wasm/test-main.js index 8718ba0cf41517..a6cd146f9652e1 100644 --- a/src/mono/wasm/test-main.mjs +++ b/src/mono/wasm/test-main.js @@ -387,7 +387,7 @@ async function run() { const main_assembly_name = runArgs.applicationArguments[1]; const app_args = runArgs.applicationArguments.slice(2); const result = await App.runtime.runMain(main_assembly_name, app_args); - console.log(`test-main.mjs exiting ${app_args.length > 1 ? main_assembly_name + " " + app_args[0] : main_assembly_name} with result ${result}`); + console.log(`test-main.js exiting ${app_args.length > 1 ? main_assembly_name + " " + app_args[0] : main_assembly_name} with result ${result}`); mono_exit(result); } catch (error) { if (error.name != "ExitStatus") { diff --git a/src/tests/Common/Directory.Build.targets b/src/tests/Common/Directory.Build.targets index e3f56896da0b8e..fd1d1af2c512ee 100644 --- a/src/tests/Common/Directory.Build.targets +++ b/src/tests/Common/Directory.Build.targets @@ -152,7 +152,7 @@ TargetDir="wasm-test-runner/"/> $(TestAssemblyFileName) $(AppDir) - $(CORE_ROOT)\runtime-test\test-main.mjs + $(CORE_ROOT)\runtime-test\test-main.js true true true @@ -34,7 +34,7 @@ - + diff --git a/src/tests/Common/wasm-test-runner/index.html b/src/tests/Common/wasm-test-runner/index.html index 1fe9311709b163..aa53c88f3289d6 100644 --- a/src/tests/Common/wasm-test-runner/index.html +++ b/src/tests/Common/wasm-test-runner/index.html @@ -1,7 +1 @@ - - - - - - - \ No newline at end of file + \ No newline at end of file From e027248aac4f4ca28501ec3eaac8c1c97754bad8 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 27 Jun 2023 22:37:47 +0000 Subject: [PATCH 76/77] [wasm] WBT: Add --module for enabling use of es6 modules --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 8e0f23548a5755..07593f41ada606 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -224,6 +224,7 @@ protected static string RunWithXHarness(string testCommand, string testLogPath, args.Append($" --app=."); args.Append($" --output-directory={testLogPath}"); args.Append($" --expected-exit-code={expectedAppExitCode}"); + args.Append(" --module"); // for ES6 modules args.Append($" {extraXHarnessArgs ?? string.Empty}"); if (File.Exists("/.dockerenv")) From d059cec50bb6fe0d98aa62d8bfb731bbb1cb36c0 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 27 Jun 2023 22:39:48 +0000 Subject: [PATCH 77/77] Add --module only for v8 --- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 1 - src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 07593f41ada606..8e0f23548a5755 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -224,7 +224,6 @@ protected static string RunWithXHarness(string testCommand, string testLogPath, args.Append($" --app=."); args.Append($" --output-directory={testLogPath}"); args.Append($" --expected-exit-code={expectedAppExitCode}"); - args.Append(" --module"); // for ES6 modules args.Append($" {extraXHarnessArgs ?? string.Empty}"); if (File.Exists("/.dockerenv")) diff --git a/src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs b/src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs index 76067e46417794..8a797ef5705766 100644 --- a/src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs +++ b/src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs @@ -9,7 +9,7 @@ namespace Wasm.Build.Tests; public class V8HostRunner : IHostRunner { - private string GetXharnessArgs(string jsRelativePath) => $"--js-file={jsRelativePath} --engine=V8 -v trace --engine-arg=--experimental-wasm-simd"; + private string GetXharnessArgs(string jsRelativePath) => $"--js-file={jsRelativePath} --engine=V8 -v trace --engine-arg=--experimental-wasm-simd --engine-arg=--module"; public string GetTestCommand() => "wasm test"; public string GetXharnessArgsWindowsOS(XHarnessArgsOptions options) => GetXharnessArgs(options.jsRelativePath);