From a9a3c090d11a1b5160ab433396b0d502716071e1 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 21 Sep 2023 06:32:13 +0000 Subject: [PATCH 1/6] Linux fails, test others. --- src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs b/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs index 5180c6e77bc3a..554accac249b4 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs @@ -30,7 +30,7 @@ public class BuildEnvironment public static readonly string RelativeTestAssetsPath = @"..\testassets\"; public static readonly string TestAssetsPath = Path.Combine(AppContext.BaseDirectory, "testassets"); public static readonly string TestDataPath = Path.Combine(AppContext.BaseDirectory, "data"); - public static readonly string TmpPath = Path.Combine(AppContext.BaseDirectory, "wbt"); + public static readonly string TmpPath = Path.Combine(AppContext.BaseDirectory, "wbt artifacts"); public static readonly string DefaultRuntimeIdentifier = #if TARGET_WASI From 529665be4a6af62f421ed37f0e463f5e98d9e905 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Mon, 2 Oct 2023 08:38:05 +0000 Subject: [PATCH 2/6] Fix spaced paths on Unix. --- 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 57763bab47ab6..be1e0e69eecaa 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -486,7 +486,7 @@ - + From 39ae63a068504569900fd789a4af5895d2e7668d Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:14:17 +0000 Subject: [PATCH 3/6] Fix spaces for dedup. --- src/tasks/AotCompilerTask/MonoAOTCompiler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs index 9e52322770b04..7d22da51109fa 100644 --- a/src/tasks/AotCompilerTask/MonoAOTCompiler.cs +++ b/src/tasks/AotCompilerTask/MonoAOTCompiler.cs @@ -951,7 +951,7 @@ private PrecompileArguments GetPrecompileArgumentsFor(ITaskItem assemblyItem, st if (isDedup) { foreach (var aItem in _assembliesToCompile!) - processArgs.Add(aItem.ItemSpec); + processArgs.Add('"' + aItem.ItemSpec + '"'); } else { From 920563ecb7fae2c5cc81ffa607733b7fc3a7d555 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 27 Oct 2023 13:48:44 +0000 Subject: [PATCH 4/6] Escape spaces with backslash. --- src/mono/wasm/build/WasmApp.Native.targets | 9 +- .../WasmAppBuilder/CreateResponseFile.cs | 99 +++++++++++++++++++ 2 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 src/tasks/WasmAppBuilder/CreateResponseFile.cs diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index d9595b16c2eb4..18d05a5f863f2 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -3,7 +3,8 @@ - + + <_WasmBuildNativeCoreDependsOn> @@ -211,7 +212,7 @@ <_EmccCompileBitcodeRsp>$(_WasmIntermediateOutputPath)emcc-compile-bc.rsp <_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp - + $(EmccTotalMemory) 5MB false @@ -250,7 +251,7 @@ <_EmccCFlags Include="-DGEN_PINVOKE=1" /> <_EmccCFlags Include="-emit-llvm" /> - <_EmccCFlags Include=""-I%(_EmccIncludePaths.Identity)"" /> + <_EmccCFlags Include="-I"%(_EmccIncludePaths.Identity)"" /> <_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" /> @@ -355,7 +356,7 @@ <_EmccCFlags Include="$(EmccExtraCFlags)" /> - + diff --git a/src/tasks/WasmAppBuilder/CreateResponseFile.cs b/src/tasks/WasmAppBuilder/CreateResponseFile.cs new file mode 100644 index 0000000000000..55815d7f3b1f7 --- /dev/null +++ b/src/tasks/WasmAppBuilder/CreateResponseFile.cs @@ -0,0 +1,99 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.WebAssembly.Build.Tasks +{ + /// + /// This cannot be done with WriteLinesToFile task because we need to parse EmccCFlags before saving to file + /// by escaping spaces with backslashes. MsBuild converts all backslashes to forward slashes automatically, + /// so it cannot be done directly in the .targets (https://github.com/dotnet/msbuild/issues/3468). + /// + public class CreateResponseFile : Microsoft.Build.Utilities.Task + { + [NotNull] + [Required] + public ITaskItem[]? EmccCFlags { get; set; } + [Required] + public string? FilePath { get; set; } + public bool Overwrite { get; set; } = true; + public bool WriteOnlyWhenDifferent{ get; set; } = true; + public override bool Execute() + { + try + { + return ExecuteActual(); + } + catch (LogAsErrorException laee) + { + Log.LogError(laee.Message); + return false; + } + } + + private bool ExecuteActual() + { + if (EmccCFlags.Length == 0) + { + Log.LogError($"No Emcc flags to write"); + return false; + } + + if (string.IsNullOrEmpty(FilePath)) + { + Log.LogError($"FilePath is empty"); + return false; + } + + if (File.Exists(FilePath)) + { + if (!Overwrite) + return true; + var lines = File.ReadLines(FilePath); + bool isDifferent = lines.Count() != EmccCFlags.Length; + if (!isDifferent) + { + foreach (var element in lines.Zip(EmccCFlags, (line, flag) => new { Line = line, Flag = flag }) ) + { + if (element.Line != element.Flag.ItemSpec) + { + Log.LogMessage($"Has a different line, element.Line={element.Line}, element.Flag.ItemSpec={element.Flag.ItemSpec}"); + isDifferent = true; + break; + } + } + } + if (WriteOnlyWhenDifferent && isDifferent) + return true; + Write(FilePath, EmccCFlags); + } + else + { + Write(FilePath, EmccCFlags); + } + return !Log.HasLoggedErrors; + } + + private void Write(string path, ITaskItem[] flags) + { + using (StreamWriter outputFile = new StreamWriter(path)) + { + foreach (ITaskItem flag in flags) + { + outputFile.WriteLine(flag.ItemSpec.Replace(" ", "\\ ")); + } + } + } + } +} From c56be8b0583527e8ecad2224d99c8660154b040b Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Fri, 27 Oct 2023 14:07:41 +0000 Subject: [PATCH 5/6] Build error --- src/tasks/WasmAppBuilder/CreateResponseFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tasks/WasmAppBuilder/CreateResponseFile.cs b/src/tasks/WasmAppBuilder/CreateResponseFile.cs index 55815d7f3b1f7..c3206b9149629 100644 --- a/src/tasks/WasmAppBuilder/CreateResponseFile.cs +++ b/src/tasks/WasmAppBuilder/CreateResponseFile.cs @@ -85,7 +85,7 @@ private bool ExecuteActual() return !Log.HasLoggedErrors; } - private void Write(string path, ITaskItem[] flags) + private static void Write(string path, ITaskItem[] flags) { using (StreamWriter outputFile = new StreamWriter(path)) { From 28456f416e613a0169b3bf7332c1b4b9b748ce50 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:13:28 +0000 Subject: [PATCH 6/6] Test only shifted after -I quotations, revert backslash. --- src/mono/wasm/build/WasmApp.Native.targets | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index 18d05a5f863f2..49b1ad7cb4a3c 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -3,7 +3,6 @@ - @@ -356,7 +355,7 @@ <_EmccCFlags Include="$(EmccExtraCFlags)" /> - +