From b0762e860652d3fc35a2bb42afc24e9908bd389d Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Wed, 10 Nov 2021 16:33:33 +0000 Subject: [PATCH] [wasm] Build improvements (#61276) Fixes #61067 Fixes #59538 (cherry picked from commit 43c3e9a79a241d044f747373bf483da23807afff) --- src/mono/wasm/build/WasmApp.Native.targets | 32 ++++++++--- .../WasmAppBuilder/IcallTableGenerator.cs | 56 +++++++++++++------ src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 13 ++++- .../Wasm.Build.Tests/BlazorWasmTests.cs | 2 - 4 files changed, 74 insertions(+), 29 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 7404e74554ac7..be45ed8d04511 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; @@ -261,14 +260,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)"> @@ -371,7 +373,7 @@ @@ -426,10 +428,24 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_ - + + <_EmccVersionCommand>emcc --version + + + + + + + diff --git a/src/tasks/WasmAppBuilder/IcallTableGenerator.cs b/src/tasks/WasmAppBuilder/IcallTableGenerator.cs index a9f5f95161575..96d24f75e33fb 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 '[{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 diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index 58b4b9259e629..5dce643f9ad39 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -348,9 +348,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}"); + } } } 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);