From f10fe15586f6a60732017a0536d21b3e156bbbfd Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 2 Nov 2021 14:39:20 -0400 Subject: [PATCH 1/6] [wasm] Surface `emcc --version` failure output as Errors We can use the captured output from the `Exec` task, but it would have to be weirdly formatted to get the proper looking errors. Instead, since the command itself is light, we just run it again, and this time surface the output as Errors. Fixes https://github.com/dotnet/runtime/issues/61067 --- src/mono/wasm/build/WasmApp.Native.targets | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 8476977afef42..9b45c700ba823 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -427,10 +427,24 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_ - + + <_EmccVersionCommand>emcc --version + + + + + + + From 7e433fb73e03b167817b5ace3b418349fa4be87b Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Fri, 5 Nov 2021 19:17:35 -0400 Subject: [PATCH 2/6] [wasm] WasmAppBuilder: log IO exceptions when copying files, as errors inspired by https://github.com/dotnet/runtime/issues/61081 --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 4c3054cad30e9..bf6708d4268f8 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -365,9 +365,16 @@ private bool FileCopyChecked(string src, string dst, string label) } Log.LogMessage(MessageImportance.Low, $"Copying file from '{src}' to '{dst}'"); - File.Copy(src, dst, true); - _fileWrites.Add(dst); + try + { + File.Copy(src, dst, true); + _fileWrites.Add(dst); - return true; + return true; + } + catch (IOException ioex) + { + throw new LogAsErrorException($"{label} Failed to copy {src} to {dst} because {ioex.Message}"); + } } } From 421bd1d65e8960ceda8fb3b0f6595365b2321949 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Fri, 5 Nov 2021 21:55:12 -0400 Subject: [PATCH 3/6] [wasm] IcallTableGenerator: For unsupported types, log a warning instead .. of throwing an exception. ``` The "IcallTableGenerator" task failed unexpectedly. [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] System.NotImplementedException: System.Enum [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at IcallTableGenerator.AppendType(StringBuilder sb, Type t) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at IcallTableGenerator.ProcessType(Type type) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at IcallTableGenerator.GenIcallTable(String runtimeIcallTableFile, String[] assemblies) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at IcallTableGenerator.Execute() [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [C:\uselessStuff\GameBuddy\src\Client\GameBuddy.Client.csproj] ``` becomes: ``` C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\7.0.0-alpha.1.21551.1\Sdk\WasmApp.Native.targets(258,5): warning : Failed to generate icall function for [System.Private.CoreLib]System.Enum::InternalHasFlag because type System.Enum is not supported for parameter named flags. Ignoring. [C:\Users\Ankit Jain\bl0\bl0.csproj] ``` Prompted by https://github.com/dotnet/runtime/issues/61053 --- .../WasmAppBuilder/IcallTableGenerator.cs | 56 +++++++++++++------ 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/src/tasks/WasmAppBuilder/IcallTableGenerator.cs b/src/tasks/WasmAppBuilder/IcallTableGenerator.cs index 7101815a73ba8..d9e0bd11c63b7 100644 --- a/src/tasks/WasmAppBuilder/IcallTableGenerator.cs +++ b/src/tasks/WasmAppBuilder/IcallTableGenerator.cs @@ -31,8 +31,16 @@ public class IcallTableGenerator : Task public override bool Execute() { - GenIcallTable(RuntimeIcallTableFile!, Assemblies!.Select(item => item.ItemSpec).ToArray()); - return true; + try + { + GenIcallTable(RuntimeIcallTableFile!, Assemblies!.Select(item => item.ItemSpec).ToArray()); + return !Log.HasLoggedErrors; + } + catch (LogAsErrorException laee) + { + Log.LogError(laee.Message); + return false; + } } // @@ -152,20 +160,9 @@ private void ProcessType (Type type) icallClass.Icalls.TryGetValue (method.Name, out icall); if (icall == null) { - // Then with signature - var sig = new StringBuilder (method.Name + "("); - int pindex = 0; - foreach (var par in method.GetParameters()) - { - if (pindex > 0) - sig.Append (','); - var t = par.ParameterType; - AppendType (sig, t); - pindex++; - } - sig.Append (')'); - if (icallClass.Icalls.ContainsKey (sig.ToString ())) - icall = icallClass.Icalls [sig.ToString ()]; + string? methodSig = BuildSignature(method, className); + if (methodSig != null && icallClass.Icalls.ContainsKey (methodSig)) + icall = icallClass.Icalls [methodSig]; } if (icall == null) // Registered at runtime @@ -178,6 +175,33 @@ private void ProcessType (Type type) foreach (var nestedType in type.GetNestedTypes()) ProcessType(nestedType); + + string? BuildSignature(MethodInfo method, string className) + { + // Then with signature + var sig = new StringBuilder (method.Name + "("); + int pindex = 0; + foreach (var par in method.GetParameters()) + { + if (pindex > 0) + sig.Append (','); + var t = par.ParameterType; + try + { + AppendType (sig, t); + } + catch (NotImplementedException nie) + { + Log.LogWarning($"Failed to generate icall function for '[{method.DeclaringType!.Assembly.GetName().Name}] {className}::{method.Name}'" + + $" because type '{nie.Message}' is not supported for parameter named '{par.Name}'. Ignoring."); + return null; + } + pindex++; + } + sig.Append (')'); + + return sig.ToString(); + } } // Append the type name used by the runtime icall tables From bf34e7f6b063e597908299876b0ae5b54a433639 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 6 Nov 2021 15:44:20 -0400 Subject: [PATCH 4/6] [wasm] Wasm.Build.Tests: Re-enable net5.0 tests because 5.0.11 packages .. are now available. fixes https://github.com/dotnet/runtime/issues/59538 --- src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs b/src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs index 727e6589c4c6d..6c7e3ed788be5 100644 --- a/src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs +++ b/src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs @@ -79,7 +79,6 @@ private CommandResult PublishForRequiresWorkloadTest(string config, string extra [Theory] [InlineData("Debug")] [InlineData("Release")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/59538")] public void Net50Projects_NativeReference(string config) => BuildNet50Project(config, aot: false, expectError: true, @""); @@ -93,7 +92,6 @@ public void Net50Projects_NativeReference(string config) [Theory] [MemberData(nameof(Net50TestData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/59538")] public void Net50Projects_AOT(string config, bool aot, bool expectError) => BuildNet50Project(config, aot: aot, expectError: expectError); From 134b6a1a88b07d414914019b93fad4e4ef5d5382 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 6 Nov 2021 18:53:13 -0400 Subject: [PATCH 5/6] [wasm] Add _CheckEmccIsExpectedVersion as explicit dependency for targets using emcc --- src/mono/wasm/build/WasmApp.Native.targets | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 9b45c700ba823..ca1f5041eabc2 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -7,7 +7,6 @@ <_WasmBuildNativeCoreDependsOn> - _CheckEmccIsExpectedVersion; _PrepareForWasmBuildNative; _GenerateDriverGenC; _GeneratePInvokeTable; @@ -260,14 +259,17 @@ - - + OutputPath="$(_WasmICallTablePath)" /> + + + + + - + <_EmBuilder Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">embuilder.bat <_EmBuilder Condition="!$([MSBuild]::IsOSPlatform('WINDOWS'))">embuilder.py @@ -304,7 +306,7 @@ Inputs="@(_BitcodeFile);$(_EmccDefaultFlagsRsp);$(_EmccCompileBitcodeRsp)" Outputs="@(_BitcodeFile->'%(ObjectFile)')" Condition="'$(_WasmShouldAOT)' == 'true' and @(_BitcodeFile->Count()) > 0" - DependsOnTargets="_WasmWriteRspForCompilingBitcode" + DependsOnTargets="_CheckEmccIsExpectedVersion;_WasmWriteRspForCompilingBitcode" Returns="@(FileWrites)"> @@ -372,7 +374,7 @@ From ec1719d0dce76175f141eb824ecdc7c0f68cffe4 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 9 Nov 2021 15:32:36 -0500 Subject: [PATCH 6/6] cleanup --- src/tasks/WasmAppBuilder/IcallTableGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/WasmAppBuilder/IcallTableGenerator.cs b/src/tasks/WasmAppBuilder/IcallTableGenerator.cs index d9e0bd11c63b7..08a560aa37bf3 100644 --- a/src/tasks/WasmAppBuilder/IcallTableGenerator.cs +++ b/src/tasks/WasmAppBuilder/IcallTableGenerator.cs @@ -192,7 +192,7 @@ private void ProcessType (Type type) } catch (NotImplementedException nie) { - Log.LogWarning($"Failed to generate icall function for '[{method.DeclaringType!.Assembly.GetName().Name}] {className}::{method.Name}'" + + Log.LogWarning($"Failed to generate icall function for method '[{method.DeclaringType!.Assembly.GetName().Name}] {className}::{method.Name}'" + $" because type '{nie.Message}' is not supported for parameter named '{par.Name}'. Ignoring."); return null; }