From 2585a04b1b859b92be85c490c34f38c91af578db Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 16 May 2023 11:12:28 -0400 Subject: [PATCH 1/2] [wasm] Set WasmEnableWebcil to true by default --- src/libraries/sendtohelix-wasm.targets | 2 +- src/libraries/sendtohelixhelp.proj | 2 +- ...Microsoft.NET.Sdk.WebAssembly.Browser.targets | 2 +- .../browser-advanced/Wasm.Advanced.Sample.csproj | 2 +- src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs | 16 +++++++++------- .../Wasm.Build.Tests/data/RunScriptTemplate.cmd | 6 +++--- .../Wasm.Build.Tests/data/RunScriptTemplate.sh | 6 +++--- src/mono/wasm/build/WasmApp.targets | 6 +++--- 8 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/libraries/sendtohelix-wasm.targets b/src/libraries/sendtohelix-wasm.targets index 7a73b732b94e24..89326207f9401e 100644 --- a/src/libraries/sendtohelix-wasm.targets +++ b/src/libraries/sendtohelix-wasm.targets @@ -276,7 +276,7 @@ $(RepositoryEngineeringDir)testing\scenarios\BuildWasmAppsJobsList.txt Workloads- NoWorkload- - $(WorkItemPrefix)Webcil- + $(WorkItemPrefix)NoWebcil- diff --git a/src/libraries/sendtohelixhelp.proj b/src/libraries/sendtohelixhelp.proj index 663d24ec1e316e..96f56bf10a11ff 100644 --- a/src/libraries/sendtohelixhelp.proj +++ b/src/libraries/sendtohelixhelp.proj @@ -146,7 +146,7 @@ - + diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 78f63db4c3ef63..ecad1cf03168a4 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -171,7 +171,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmEnableThreads>$(WasmEnableThreads) <_WasmEnableThreads Condition="'$(_WasmEnableThreads)' == ''">false <_WasmEnableWebcil>$(WasmEnableWebcil) - <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">false + <_WasmEnableWebcil Condition="'$(_WasmEnableWebcil)' == ''">true <_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache) <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) 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 006e3c3a7aae5b..d37b17495581b5 100644 --- a/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj +++ b/src/mono/sample/wasm/browser-advanced/Wasm.Advanced.Sample.csproj @@ -4,7 +4,7 @@ true true false - true + false true true web,worker diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index e7c948eefea1b0..cda5afe8e6dce7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -83,6 +83,8 @@ static BuildTestBase() Console.WriteLine($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ==============="); if (UseWebcil) Console.WriteLine($"=============== Using webcil-in-wasm ==============="); + else + Console.WriteLine($"=============== Webcil disabled ==============="); Console.WriteLine($"=============================================================================================="); Console.WriteLine(""); } @@ -343,9 +345,9 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp extraProperties += $"\n{s_isWindows}\n"; } - if (UseWebcil) + if (!UseWebcil) { - extraProperties += "true\n"; + extraProperties += "false\n"; } extraItems += ""; @@ -508,8 +510,8 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse extraProperties += "true"; if (runAnalyzers) extraProperties += "true"; - if (UseWebcil) - extraProperties += "true"; + if (!UseWebcil) + extraProperties += "false"; // TODO: Can be removed after updated templates propagate in. string extraItems = string.Empty; @@ -533,8 +535,8 @@ public string CreateBlazorWasmTemplateProject(string id) .EnsureSuccessful(); string projectFile = Path.Combine(_projectDir!, $"{id}.csproj"); - if (UseWebcil) - AddItemsPropertiesToProject(projectFile, "true"); + if (!UseWebcil) + AddItemsPropertiesToProject(projectFile, "false"); return projectFile; } @@ -595,7 +597,7 @@ public string CreateBlazorWasmTemplateProject(string id) label, // same as the command name $"-bl:{logPath}", $"-p:Configuration={config}", - UseWebcil ? "-p:WasmEnableWebcil=true" : string.Empty, + !UseWebcil ? "-p:WasmEnableWebcil=false" : string.Empty, "-p:BlazorEnableCompression=false", "-nr:false", setWasmDevel ? "-p:_WasmDevel=true" : string.Empty diff --git a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd index 8ce4e7a46f1590..ff131266cec528 100644 --- a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd +++ b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.cmd @@ -51,10 +51,10 @@ if [%TEST_USING_WORKLOADS%] == [true] ( ) else ( set SDK_HAS_WORKLOAD_INSTALLED=false ) -if [%TEST_USING_WEBCIL%] == [true] ( - set USE_WEBCIL_FOR_TESTS=true -) else ( +if [%TEST_USING_WEBCIL%] == [false] ( set USE_WEBCIL_FOR_TESTS=false +) else ( + set USE_WEBCIL_FOR_TESTS=true ) if [%HELIX_CORRELATION_PAYLOAD%] NEQ [] ( diff --git a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh index 5ba72dfad34e9e..67e87c9afe2912 100644 --- a/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh +++ b/src/mono/wasm/Wasm.Build.Tests/data/RunScriptTemplate.sh @@ -33,10 +33,10 @@ function set_env_vars() export SDK_HAS_WORKLOAD_INSTALLED=false fi - if [ "x$TEST_USING_WEBCIL" = "xtrue" ]; then - export USE_WEBCIL_FOR_TESTS=true - else + if [ "x$TEST_USING_WEBCIL" = "xfalse" ]; then export USE_WEBCIL_FOR_TESTS=false + else + export USE_WEBCIL_FOR_TESTS=true fi local _SDK_DIR= diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 465c0a1c44cd88..d96c84131533f4 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -71,7 +71,7 @@ - $(WasmEnableLegacyJsInterop) - Include support for legacy JS interop. Defaults to true. - $(WasmEnableExceptionHandling) - Enable support for the WASM post MVP Exception Handling runtime extension. - $(WasmEnableSIMD) - Enable support for the WASM post MVP SIMD runtime extension. - - $(WasmEnableWebcil) - Enable conversion of assembly .dlls to Webcil wrapped in .wasm + - $(WasmEnableWebcil) - Enable conversion of assembly .dlls to Webcil wrapped in .wasm (default: true) - $(WasmIncludeFullIcuData) - Loads full ICU data (icudt.dat). Defaults to false. Only applicable when InvariantGlobalization=false. - $(WasmIcuDataFileName) - Name/path of ICU globalization file loaded to app. Only when InvariantGloblization=false and WasmIncludeFullIcuData=false. - $(WasmAllowUndefinedSymbols) - Controls whether undefined symbols are allowed or not, @@ -133,8 +133,8 @@ -1 - - false + + true From 9d563a905d2aba208fd6b6444a025c347e14a161 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 16 May 2023 16:02:46 -0400 Subject: [PATCH 2/2] WebcilReader: copy updated struct for BlobReader.ReadUtf8NullTerminated When using reflection to call a method on BlobReader, make sure to copy the struct after the call since the internal state is modified Fixes PdbChecksum extraction from Webcil files (This was a problem even before webcil-in-wasm) --- .../src/Webcil/WebcilReader.Reflection.cs | 8 +++++++- .../src/Webcil/WebcilReader.cs | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.Reflection.cs b/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.Reflection.cs index 56eae848a4aa5b..d4b6c878ec223f 100644 --- a/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.Reflection.cs +++ b/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.Reflection.cs @@ -29,7 +29,13 @@ internal static class Reflection return mi; }); - internal static string? ReadUtf8NullTerminated(BlobReader reader) => (string?)s_readUtf8NullTerminated.Value.Invoke(reader, null); + internal static string? ReadUtf8NullTerminated(ref BlobReader reader) + { + object boxedReader = reader; + string? result = (string?)s_readUtf8NullTerminated.Value.Invoke(boxedReader, null); + reader = (BlobReader) boxedReader; // the call modifies the struct state, make sure to copy it back. + return result; + } private static readonly Lazy s_codeViewDebugDirectoryDataCtor = new Lazy(() => { diff --git a/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.cs b/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.cs index c6e24931834d3c..bda8cca394df2f 100644 --- a/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.cs +++ b/src/libraries/Microsoft.NET.WebAssembly.Webcil/src/Webcil/WebcilReader.cs @@ -220,12 +220,12 @@ private static CodeViewDebugDirectoryData DecodeCodeViewDebugDirectoryData(BlobR Guid guid = reader.ReadGuid(); int age = reader.ReadInt32(); - string path = ReadUtf8NullTerminated(reader)!; + string path = ReadUtf8NullTerminated(ref reader)!; return MakeCodeViewDebugDirectoryData(guid, age, path); } - private static string? ReadUtf8NullTerminated(BlobReader reader) => Reflection.ReadUtf8NullTerminated(reader); + private static string? ReadUtf8NullTerminated(ref BlobReader reader) => Reflection.ReadUtf8NullTerminated(ref reader); private static CodeViewDebugDirectoryData MakeCodeViewDebugDirectoryData(Guid guid, int age, string path) => Reflection.MakeCodeViewDebugDirectoryData(guid, age, path); @@ -316,7 +316,7 @@ public PdbChecksumDebugDirectoryData ReadPdbChecksumDebugDirectoryData(DebugDire private static PdbChecksumDebugDirectoryData DecodePdbChecksumDebugDirectoryData(BlobReader reader) { - var algorithmName = ReadUtf8NullTerminated(reader); + var algorithmName = ReadUtf8NullTerminated(ref reader); byte[]? checksum = reader.ReadBytes(reader.RemainingBytes); if (string.IsNullOrEmpty(algorithmName) || checksum == null || checksum.Length == 0) {