未验证 提交 26ae0978 编写于 作者: A Ankit Jain 提交者: GitHub

[wasm] Fix up conditions to trigger relink, and require `wasm-tools` workload (#89754)

- Trigger relinking (`WasmBuildNative=true`) if:
   - `WasmNativeStrip=false`
   - `WasmEnableSIMD=false`
   - `WasmEnableExceptionHandling=false`
   - The above are in addition to the existing conditions

- Also, trigger "workload required" when:
   - `WasmNativeStrip=false`
   - `WasmEnableExceptionHandling=true`
   - `InvariantGlobalization=true`
   - `InvariantTimeZone=true`
   - The above are in addition to the existing conditions

- Rationalize `WasmNativeDebugSymbols`, and `WasmNativeStrip`
	- `WasmNativeDebugSymbols` will cause symbols to be included
	  (essentially `-g`)
	- `WasmNativeStrip` will cause these to be stripped with `wasm-opt
	  --strip-dwarf ...`

Fixes https://github.com/dotnet/runtime/issues/85778 .
上级 678fd6a7
......@@ -13,6 +13,7 @@ Wasm.Build.Tests.Blazor.MiscTests2
Wasm.Build.Tests.Blazor.MiscTests3
Wasm.Build.Tests.Blazor.NativeTests
Wasm.Build.Tests.Blazor.NoopNativeRebuildTest
Wasm.Build.Tests.Blazor.WorkloadRequiredTests
Wasm.Build.Tests.Blazor.IcuTests
Wasm.Build.Tests.BuildPublishTests
Wasm.Build.Tests.ConfigSrcTests
......
......@@ -15,7 +15,7 @@
- For regular library tests, it will use the symbols file from the runtime pack.
- for AOT library tests, we use WasmNativeStrip=false, so we already have symbols
-->
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(RunAOTCompilation)' == 'true'">false</WasmNativeStrip>
<WasmEmitSymbolMap Condition="'$(WasmEmitSymbolMap)' == ''">true</WasmEmitSymbolMap>
<_WasmMainJSFileName Condition="'$(WasmMainJSPath)' != ''">$([System.IO.Path]::GetFileName('$(WasmMainJSPath)'))</_WasmMainJSFileName>
......
......@@ -77,14 +77,6 @@
<Exec Condition="$([MSBuild]::IsOSPlatform('windows'))"
Command='powershell -ExecutionPolicy ByPass -NoProfile -command "&amp; $(_DotNetInstallCommand)"' />
<!-- HACK: Remove the now invalid manifest `microsoft.net.workload.mono.toolchain` as a workaround
till the sdk removes it completely. -->
<ItemGroup>
<_ManifestsToRemove Include="$(_SdkWithNoWorkloadPath)\sdk-manifests\8.0.100\microsoft.net.workload.mono.toolchain" />
</ItemGroup>
<Message Text="Removing @(_ManifestsToRemove)" Condition="Exists(%(_ManifestsToRemove.Identity))" Importance="High" />
<RemoveDir Directories="@(_ManifestsToRemove)" Condition="Exists(%(_ManifestsToRemove.Identity))" />
</Target>
<Target Name="_GetDotNetVersion">
......
......@@ -39,10 +39,23 @@
</PropertyGroup>
<PropertyGroup Condition="'$(RuntimeIdentifier)' == 'browser-wasm' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<!-- Keep in sync with WasmApp.Native.targets -->
<_WasmPropertiesDifferFromRuntimePackThusNativeBuildNeeded Condition="
'$(WasmEnableLegacyJsInterop)' == 'false' or
'$(WasmEnableSIMD)' == 'false' or
'$(WasmEnableExceptionHandling)' == 'false' or
'$(InvariantTimezone)' == 'true' or
'$(InvariantGlobalization)' == 'true' or
'$(WasmNativeStrip)' == 'false'">true</_WasmPropertiesDifferFromRuntimePackThusNativeBuildNeeded>
<!-- $(WasmBuildNative)==true is needed to enable workloads, when using native references, without AOT -->
<!-- FIXME: is the blazor condition here correct? -->
<_WasmNativeWorkloadNeeded Condition="'$(RunAOTCompilation)' == 'true' or '$(WasmEnableSIMD)' == 'true' or '$(WasmEnableLegacyJsInterop)' == 'false' or '$(WasmBuildNative)' == 'true' or
'$(WasmGenerateAppBundle)' == 'true' or '$(_UsingBlazorOrWasmSdk)' != 'true'" >true</_WasmNativeWorkloadNeeded>
<_WasmNativeWorkloadNeeded Condition="
'$(_WasmPropertiesDifferFromRuntimePackThusNativeBuildNeeded)' == 'true' or
'$(RunAOTCompilation)' == 'true' or
'$(WasmBuildNative)' == 'true' or
'$(WasmGenerateAppBundle)' == 'true' or
'$(_UsingBlazorOrWasmSdk)' != 'true'" >true</_WasmNativeWorkloadNeeded>
<UsingBrowserRuntimeWorkload Condition="'$(_BrowserWorkloadNotSupportedForTFM)' == 'true'">false</UsingBrowserRuntimeWorkload>
<UsingBrowserRuntimeWorkload Condition="'$(UsingBrowserRuntimeWorkload)' == '' and '$(_WasmNativeWorkloadNeeded)' == 'true'">true</UsingBrowserRuntimeWorkload>
......@@ -185,8 +198,8 @@
Text="WebAssembly workloads, required for native relinking, are only supported for projects targeting net6.0+ . Set %24(WasmBuildNative)=false to disable it." />
</Target>
<Target Name="_ErrorDualWasmThreadProps"
Condition="('$(TargetsCurrent)' == 'true' or '$(TargetsNet7)' == 'true') and '$(RuntimeIdentifier)' == 'browser-wasm' and
<Target Name="_ErrorDualWasmThreadPropsOn7"
Condition="'$(TargetsNet7)' == 'true' and '$(RuntimeIdentifier)' == 'browser-wasm' and
'$(BrowserWorkloadDisabled)' != 'true' and '$(WasmEnableThreads)' == 'true' and '$(WasmEnablePerfTrace)' == 'true'"
BeforeTargets="Build">
<Error Text="WebAssembly workloads can only support one active threading mode at a time. Either set WasmEnableThreads or WasmEnablePerfTracing to true, but not both." />
......
......@@ -13,6 +13,7 @@ public record BlazorBuildOptions
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor,
bool IsPublish = false,
bool WarnAsError = true,
bool ExpectSuccess = true,
bool ExpectRelinkDirWhenPublishing = false,
bool ExpectFingerprintOnDotnetJs = false,
RuntimeVariant RuntimeType = RuntimeVariant.SingleThreaded,
......
......@@ -58,9 +58,10 @@ public string CreateBlazorWasmTemplateProject(string id)
if (options.WarnAsError)
extraArgs = extraArgs.Append("/warnaserror").ToArray();
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, extraArgs);
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);
AssertBundle(res.Output, options with { IsPublish = false });
if (options.ExpectSuccess)
AssertBundle(res.Output, options with { IsPublish = false });
return (res, logPath);
}
......@@ -70,25 +71,29 @@ public string CreateBlazorWasmTemplateProject(string id)
if (options.WarnAsError)
extraArgs = extraArgs.Append("/warnaserror").ToArray();
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: true, setWasmDevel: false, extraArgs);
AssertBundle(res.Output, options with { IsPublish = true });
(CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: true, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs);
if (options.ExpectedFileType == NativeFilesType.AOT)
if (options.ExpectSuccess)
{
// check for this too, so we know the format is correct for the negative
// test for jsinterop.webassembly.dll
Assert.Contains("Microsoft.JSInterop.dll -> Microsoft.JSInterop.dll.bc", res.Output);
AssertBundle(res.Output, options with { IsPublish = true });
// make sure this assembly gets skipped
Assert.DoesNotContain("Microsoft.JSInterop.WebAssembly.dll -> Microsoft.JSInterop.WebAssembly.dll.bc", res.Output);
}
if (options.ExpectedFileType == NativeFilesType.AOT)
{
// check for this too, so we know the format is correct for the negative
// test for jsinterop.webassembly.dll
Assert.Contains("Microsoft.JSInterop.dll -> Microsoft.JSInterop.dll.bc", res.Output);
string objBuildDir = Path.Combine(_projectDir!, "obj", options.Config, options.TargetFramework!, "wasm", "for-build");
// Check that we linked only for publish
if (options.ExpectRelinkDirWhenPublishing)
Assert.True(Directory.Exists(objBuildDir), $"Could not find expected {objBuildDir}, which gets created when relinking during Build. This is likely a test authoring error");
else
Assert.False(File.Exists(Path.Combine(objBuildDir, "emcc-link.rsp")), $"Found unexpected files in {objBuildDir}, which gets created when relinking during Build");
// make sure this assembly gets skipped
Assert.DoesNotContain("Microsoft.JSInterop.WebAssembly.dll -> Microsoft.JSInterop.WebAssembly.dll.bc", res.Output);
}
string objBuildDir = Path.Combine(_projectDir!, "obj", options.Config, options.TargetFramework!, "wasm", "for-build");
// Check that we linked only for publish
if (options.ExpectRelinkDirWhenPublishing)
Assert.True(Directory.Exists(objBuildDir), $"Could not find expected {objBuildDir}, which gets created when relinking during Build. This is likely a test authoring error");
else
Assert.False(File.Exists(Path.Combine(objBuildDir, "emcc-link.rsp")), $"Found unexpected files in {objBuildDir}, which gets created when relinking during Build");
}
return (res, logPath);
}
......@@ -98,6 +103,7 @@ public string CreateBlazorWasmTemplateProject(string id)
string config,
bool publish = false,
bool setWasmDevel = true,
bool expectSuccess = true,
params string[] extraArgs)
{
try
......@@ -105,7 +111,7 @@ public string CreateBlazorWasmTemplateProject(string id)
return BuildProjectWithoutAssert(
id,
config,
new BuildProjectOptions(CreateProject: false, UseCache: false, Publish: publish),
new BuildProjectOptions(CreateProject: false, UseCache: false, Publish: publish, ExpectSuccess: expectSuccess),
extraArgs.Concat(new[]
{
"-p:BlazorEnableCompression=false",
......
// 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.Generic;
using System.IO;
using Xunit;
using Xunit.Abstractions;
#nullable enable
namespace Wasm.Build.Tests.Blazor;
public class WorkloadRequiredTests : BlazorWasmTestBase
{
/* Keep in sync with settings in wasm.proj, and WasmApp.Native.targets .
* The `triggerValue` here is opposite of the default used when building the runtime pack
* (see wasm.proj), and thus requiring a native build
*/
public static (string propertyName, bool triggerValue)[] PropertiesWithTriggerValues = new[]
{
("RunAOTCompilation", true),
("WasmEnableLegacyJsInterop", false),
("WasmEnableSIMD", false),
("WasmEnableExceptionHandling", false),
("InvariantTimezone", true),
("InvariantGlobalization", true),
("WasmNativeStrip", false)
};
public WorkloadRequiredTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}
public static TheoryData<string, string, bool> SettingDifferentFromValuesInRuntimePack(bool forPublish)
{
TheoryData<string, string, bool> data = new();
string[] configs = new[] { "Debug", "Release" };
foreach (var defaultPair in PropertiesWithTriggerValues)
{
foreach (string config in configs)
{
data.Add(config, $"<{defaultPair.propertyName}>{defaultPair.triggerValue}</{defaultPair.propertyName}>", true);
data.Add(config, $"<{defaultPair.propertyName}>{!defaultPair.triggerValue}</{defaultPair.propertyName}>", false);
}
}
return data;
}
[Theory, TestCategory("no-workload")]
[MemberData(nameof(SettingDifferentFromValuesInRuntimePack), parameters: false)]
public void WorkloadRequiredForBuild(string config, string extraProperties, bool workloadNeeded)
=> CheckWorkloadRequired(config, extraProperties, workloadNeeded, publish: false);
[Theory, TestCategory("no-workload")]
[MemberData(nameof(SettingDifferentFromValuesInRuntimePack), parameters: false)]
public void WorkloadRequiredForPublish(string config, string extraProperties, bool workloadNeeded)
=> CheckWorkloadRequired(config, extraProperties, workloadNeeded, publish: true);
private void CheckWorkloadRequired(string config, string extraProperties, bool workloadNeeded, bool publish)
{
string id = $"props_req_workload_{(publish ? "publish" : "build")}_{GetRandomId()}";
string projectFile = CreateWasmTemplateProject(id, "blazorwasm");
AddItemsPropertiesToProject(projectFile, extraProperties,
atTheEnd: @"<Target Name=""StopBuildBeforeCompile"" BeforeTargets=""Compile"">
<Error Text=""Stopping the build"" />
</Target>");
CommandResult result;
if (publish)
(result, _) = BlazorPublish(new BlazorBuildOptions(id, config, ExpectSuccess: false));
else
(result, _) = BlazorBuild(new BlazorBuildOptions(id, config, ExpectSuccess: false));
if (workloadNeeded)
{
Assert.Contains("following workloads must be installed: wasm-tools", result.Output);
Assert.DoesNotContain("error : Stopping the build", result.Output);
}
else
{
Assert.DoesNotContain("following workloads must be installed: wasm-tools", result.Output);
Assert.Contains("error : Stopping the build", result.Output);
}
}
}
......@@ -128,9 +128,6 @@ public BuildEnvironment()
EnvVars["WasmEnableWebCil"] = "false";
}
// helps with debugging
EnvVars["WasmNativeStrip"] = "false";
DotNet = Path.Combine(sdkForWorkloadPath!, "dotnet");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
DotNet += ".exe";
......
// 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.Generic;
using System.IO;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
#nullable enable
......@@ -18,39 +17,157 @@ public WasmNativeDefaultsTests(ITestOutputHelper output, SharedBuildPerTestClass
{
}
public static TheoryData<string, string, bool, bool, bool> SettingDifferentFromValuesInRuntimePack(bool forPublish)
{
List<(string propertyName, bool defaultValueInRuntimePack)> defaults = new()
{
("WasmEnableLegacyJsInterop", true),
("WasmEnableSIMD", true),
("WasmEnableExceptionHandling", true),
("InvariantTimezone", false),
("InvariantGlobalization", false),
// ("WasmNativeStrip", true) -- tested separately because it has special handling in targets
};
TheoryData<string, string, bool, bool, bool> data = new();
string[] configs = new[] { "Debug", "Release" };
foreach (var defaultPair in defaults)
{
foreach (string config in configs)
{
// Config=Release always causes relinking when publishing
bool publishValue = forPublish && config == "Release" ? true : false;
// Setting the default value from the runtime pack shouldn't trigger relinking
data.Add(config, $"<{defaultPair.propertyName}>{defaultPair.defaultValueInRuntimePack}</{defaultPair.propertyName}>",
/*aot*/ false, /*build*/ false, /*publish*/ publishValue);
// Leaving the property unset, so checking the default
data.Add(config, "", /*aot*/ false, /*build*/ false, /*publish*/ publishValue);
// Setting the !default value should trigger relinking
data.Add(config, $"<{defaultPair.propertyName}>{!defaultPair.defaultValueInRuntimePack}</{defaultPair.propertyName}>",
/*aot*/ false, /*build*/ true, /*publish*/ true);
}
}
return data;
}
public static TheoryData<string, string, bool, bool, bool> DefaultsTestData(bool forPublish)
{
TheoryData<string, string, bool, bool, bool> data = new()
{
/* relink by default for publish+Release */
{ "Release", "", /*aot*/ false, /*build*/ false, /*publish*/ true },
/* NO relink by default for publish+Release, when not trimming */
{ "Release", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ false, /*build*/ false, /*publish*/ false },
/* When not trimming, and no-aot, we don't relink. But WasmNativeStrip=false should still trigger it*/
// { "Release", "<WasmNativeStrip>false</WasmNativeStrip><PublishTrimmed>false</PublishTrimmed>",
// /*aot*/ false, /*build*/ true, /*publish*/ true }
};
if (!forPublish)
{
/* Debug config, when building does trigger relinking */
data.Add("Debug", "", /*aot*/ false, /*build*/ false, /*publish*/ true);
}
if (forPublish)
{
/* NO relink by default for publish+Debug */
data.Add("Debug", "", /*aot*/ false, /*build*/ false, /*publish*/ false);
/* AOT */
data.Add("Release", "", /*aot*/ true, /*build*/ false, /*publish*/ true);
data.Add("Debug", "", /*aot*/ true, /*build*/ false, /*publish*/ true);
// FIXME: separate test
// { "Release", "<RunAOTCompilationAfterBuild>true</RunAOTCompilationAfterBuild>",
// /*aot*/ true, /*build*/ true, /*publish*/ true },
/* AOT not affected by trimming */
data.Add("Release", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ true, /*build*/ false, /*publish*/ true);
data.Add("Debug", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ true, /*build*/ false, /*publish*/ true);
}
return data;
}
[Theory]
/* relink by default for publish+Release */
[InlineData("Release", "", /*aot*/ false, /*build*/ false, /*publish*/ true)]
/* NO relink by default for publish+Release, even when not trimming */
[InlineData("Release", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ false, /*build*/ false, /*publish*/ false)]
[InlineData("Debug", "", /*aot*/ false, /*build*/ false, /*publish*/ false)]
/* AOT */
[InlineData("Release", "", /*aot*/ true, /*build*/ false, /*publish*/ true)]
[InlineData("Debug", "", /*aot*/ true, /*build*/ false, /*publish*/ true)]
// FIXME: separate test
// [InlineData("Release", "<RunAOTCompilationAfterBuild>true</RunAOTCompilationAfterBuild>",
// /*aot*/ true, /*build*/ true, /*publish*/ true)]
/* AOT not affected by trimming */
[InlineData("Release", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ true, /*build*/ false, /*publish*/ true)]
[InlineData("Debug", "<PublishTrimmed>false</PublishTrimmed>", /*aot*/ true, /*build*/ false, /*publish*/ true)]
public void Defaults(string config, string extraProperties, bool aot, bool buildValue, bool publishValue)
[MemberData(nameof(DefaultsTestData), parameters: false)]
[MemberData(nameof(SettingDifferentFromValuesInRuntimePack), parameters: false)]
public void DefaultsWithBuild(string config, string extraProperties, bool aot, bool expectWasmBuildNativeForBuild, bool expectWasmBuildNativeForPublish)
{
string output = CheckWasmNativeDefaultValue("native_defaults_publish", config, extraProperties, aot, dotnetWasmFromRuntimePack: !publishValue);
string output = CheckWasmNativeDefaultValue("native_defaults_build", config, extraProperties, aot, dotnetWasmFromRuntimePack: !expectWasmBuildNativeForPublish, publish: false);
bool expectedWasmNativeStripValue = true;
if (/*isBuild && */ expectWasmBuildNativeForBuild && config == "Debug")
expectedWasmNativeStripValue = false;
// bool expectedWasmNativeStripValue = !(wasmBuildNativeForBuild && config == "Debug");
// for build
Assert.DoesNotContain($"** WasmBuildNative: '{buildValue.ToString().ToLower()}', WasmBuildingForNestedPublish: ''", output);
Assert.Contains($"** WasmBuildNative: '{expectWasmBuildNativeForBuild.ToString().ToLower()}', WasmNativeStrip: '{expectedWasmNativeStripValue.ToString().ToLower()}', WasmBuildingForNestedPublish: ''", output);
Assert.Contains("Stopping the build", output);
}
#pragma warning disable xUnit1026 // For unused *buildValue* parameter
[Theory]
[MemberData(nameof(DefaultsTestData), parameters: true)]
[MemberData(nameof(SettingDifferentFromValuesInRuntimePack), parameters: true)]
public void DefaultsWithPublish(string config, string extraProperties, bool aot, bool expectWasmBuildNativeForBuild, bool expectWasmBuildNativeForPublish)
{
string output = CheckWasmNativeDefaultValue("native_defaults_publish", config, extraProperties, aot, dotnetWasmFromRuntimePack: !expectWasmBuildNativeForPublish, publish: true);
// for build
// Assert.DoesNotContain($"** WasmBuildNative: '{buildValue.ToString().ToLower()}', WasmNativeStrip: 'true', WasmBuildingForNestedPublish: ''", output);
// for publish
Assert.Contains($"** WasmBuildNative: '{publishValue.ToString().ToLower()}', WasmBuildingForNestedPublish: 'true'", output);
Assert.Contains($"** WasmBuildNative: '{expectWasmBuildNativeForPublish.ToString().ToLower()}', WasmNativeStrip: 'true', WasmBuildingForNestedPublish: 'true'", output);
Assert.Contains("Stopping the build", output);
}
#pragma warning restore xunit1026
public static TheoryData<string, string, bool, bool> SetWasmNativeStripExplicitlyTestData(bool publish) => new()
{
{"Debug", "<WasmNativeStrip>true</WasmNativeStrip>", false, true },
{"Release", "<WasmNativeStrip>true</WasmNativeStrip>", publish, true },
{"Debug", "<WasmNativeStrip>false</WasmNativeStrip>", true, false },
{"Release", "<WasmNativeStrip>false</WasmNativeStrip>", true, false }
};
public static TheoryData<string, string, bool, bool> SetWasmNativeStripExplicitlyWithWasmBuildNativeTestData() => new()
{
{ "Debug", "<WasmNativeStrip>false</WasmNativeStrip><WasmEnableLegacyJsInterop>false</WasmEnableLegacyJsInterop>", true, false },
{ "Release", "<WasmNativeStrip>false</WasmNativeStrip><WasmEnableLegacyJsInterop>false</WasmEnableLegacyJsInterop>", true, false },
{ "Debug", "<WasmNativeStrip>true</WasmNativeStrip><WasmEnableLegacyJsInterop>false</WasmEnableLegacyJsInterop>", true, true },
{ "Release", "<WasmNativeStrip>true</WasmNativeStrip><WasmEnableLegacyJsInterop>false</WasmEnableLegacyJsInterop>", true, true }
};
[Theory]
[MemberData(nameof(SetWasmNativeStripExplicitlyTestData), parameters: /*publish*/ false)]
[MemberData(nameof(SetWasmNativeStripExplicitlyWithWasmBuildNativeTestData))]
public void WasmNativeStripDefaultWithBuild(string config, string extraProperties, bool expectedWasmBuildNativeValue, bool expectedWasmNativeStripValue)
{
string output = CheckWasmNativeDefaultValue("native_strip_defaults", config, extraProperties, aot: false, dotnetWasmFromRuntimePack: !expectedWasmBuildNativeValue, publish: false);
Assert.Contains($"** WasmBuildNative: '{expectedWasmBuildNativeValue.ToString().ToLower()}', WasmNativeStrip: '{expectedWasmNativeStripValue.ToString().ToLower()}', WasmBuildingForNestedPublish: ''", output);
Assert.Contains("Stopping the build", output);
}
[Theory]
[MemberData(nameof(SetWasmNativeStripExplicitlyTestData), parameters: /*publish*/ true)]
[MemberData(nameof(SetWasmNativeStripExplicitlyWithWasmBuildNativeTestData))]
public void WasmNativeStripDefaultWithPublish(string config, string extraProperties, bool expectedWasmBuildNativeValue, bool expectedWasmNativeStripValue)
{
string output = CheckWasmNativeDefaultValue("native_strip_defaults", config, extraProperties, aot: false, dotnetWasmFromRuntimePack: !expectedWasmBuildNativeValue, publish: true);
Assert.Contains($"** WasmBuildNative: '{expectedWasmBuildNativeValue.ToString().ToLower()}', WasmNativeStrip: '{expectedWasmNativeStripValue.ToString().ToLower()}', WasmBuildingForNestedPublish: 'true'", output);
Assert.Contains("Stopping the build", output);
}
[Theory]
/* always relink */
[InlineData("Release", "", /*build*/ true, /*publish*/ true)]
[InlineData("Debug", "", /*build*/ true, /*publish*/ true)]
[InlineData("Release", "", /*build*/ true, /*publish*/ true)]
[InlineData("Release", "<PublishTrimmed>false</PublishTrimmed>", /*build*/ true, /*publish*/ true)]
public void WithNativeReference(string config, string extraProperties, bool buildValue, bool publishValue)
{
......@@ -61,12 +178,13 @@ public void WithNativeReference(string config, string extraProperties, bool buil
extraProperties,
aot: false,
dotnetWasmFromRuntimePack: !publishValue,
publish: true,
extraItems: nativeRefItem);
// for build
Assert.DoesNotContain($"** WasmBuildNative: '{buildValue.ToString().ToLower()}', WasmBuildingForNestedPublish: ''", output);
// for build - FIXME:
Assert.DoesNotContain($"** WasmBuildNative: '{buildValue.ToString().ToLower()}', WasmBuildingForNestedPublish: ''", output);
// for publish
Assert.Contains($"** WasmBuildNative: '{publishValue.ToString().ToLower()}', WasmBuildingForNestedPublish: 'true'", output);
Assert.Contains($"** WasmBuildNative: '{publishValue.ToString().ToLower()}', WasmNativeStrip: 'true', WasmBuildingForNestedPublish: 'true'", output);
Assert.Contains("Stopping the build", output);
}
......@@ -75,16 +193,19 @@ public void WithNativeReference(string config, string extraProperties, bool buil
string extraProperties,
bool aot,
bool dotnetWasmFromRuntimePack,
bool publish,
string extraItems = "")
{
// builds with -O0
extraProperties += "<_WasmDevel>true</_WasmDevel>";
string printValueTarget = @"
<Target Name=""PrintWasmBuildNative"" AfterTargets=""_SetWasmBuildNativeDefaults"">
<Message Text=""** WasmBuildNative: '$(WasmBuildNative)', WasmBuildingForNestedPublish: '$(WasmBuildingForNestedPublish)'"" Importance=""High"" />
<Error Text=""Stopping the build"" Condition=""$(WasmBuildingForNestedPublish) == 'true'"" />
</Target>";
<Target Name=""PrintWasmBuildNative"" AfterTargets=""_BeforeWasmBuildApp"">
<Message Text=""** WasmBuildNative: '$(WasmBuildNative)', WasmNativeStrip: '$(WasmNativeStrip)', WasmBuildingForNestedPublish: '$(WasmBuildingForNestedPublish)'"" Importance=""High"" />
" + (publish
? @"<Error Text=""Stopping the build"" Condition=""$(WasmBuildingForNestedPublish) == 'true'"" />"
: @"<Error Text=""Stopping the build"" />")
+ "</Target>";
BuildArgs buildArgs = new(ProjectName: projectName, Config: config, AOT: aot, string.Empty, null);
buildArgs = ExpandBuildArgs(buildArgs,
......@@ -99,7 +220,8 @@ public void WithNativeReference(string config, string extraProperties, bool buil
DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack,
ExpectSuccess: false,
UseCache: false,
BuildOnlyAfterPublish: false));
BuildOnlyAfterPublish: false,
Publish: publish));
return output;
}
......
......@@ -98,42 +98,6 @@ public void PublishWithoutSIMD_AOT(BuildArgs buildArgs, RunHost host, string id)
}, host: host, id: id);
}
[Theory, TestCategory("no-workload")]
[InlineData("Debug", /*aot*/true, /*publish*/true)]
[InlineData("Debug", /*aot*/false, /*publish*/false)]
[InlineData("Debug", /*aot*/false, /*publish*/true)]
[InlineData("Release", /*aot*/true, /*publish*/true)]
[InlineData("Release", /*aot*/false, /*publish*/false)]
[InlineData("Release", /*aot*/false, /*publish*/true)]
public void BuildWithSIMDNeedsWorkload(string config, bool aot, bool publish)
{
string id = GetRandomId();
string projectName = $"simd_no_workload_{config}_aot_{aot}";
BuildArgs buildArgs = new
(
ProjectName: projectName,
Config: config,
AOT: aot,
ProjectFileContents: "placeholder",
ExtraBuildArgs: string.Empty
);
string extraProperties = """
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<WasmEnableSIMD>true</WasmEnableSIMD>
""";
buildArgs = ExpandBuildArgs(buildArgs, extraProperties);
(_, string output) = BuildProject(buildArgs,
id: id,
new BuildProjectOptions(
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_simdProgramText),
Publish: publish,
ExpectSuccess: false,
UseCache: false));
Assert.Contains("following workloads must be installed: wasm-tools", output);
}
private static string s_simdProgramText = @"
using System;
using System.Runtime.Intrinsics;
......
......@@ -21,7 +21,8 @@
<_BeforeWasmBuildAppDependsOn>
$(_BeforeWasmBuildAppDependsOn);
_SetupEmscripten;
_SetWasmBuildNativeDefaults
_SetWasmBuildNativeDefaults;
_SetWasmNativeStripDefault
</_BeforeWasmBuildAppDependsOn>
<_EmccDefaultFlags Condition="'$(WasmEnableSIMD)' == 'true'">-msimd128</_EmccDefaultFlags>
......@@ -108,26 +109,27 @@
<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(_IsEMSDKMissing)' == 'true'"
Text="$(_EMSDKMissingErrorMessage) Emscripten SDK is required for AOT'ing assemblies." />
<ItemGroup>
<_BoolPropertiesThatTriggerRelinking Include="WasmEnableLegacyJsInterop" DefaultValueInRuntimePack="true" />
<_BoolPropertiesThatTriggerRelinking Include="WasmEnableSIMD" DefaultValueInRuntimePack="true" />
<_BoolPropertiesThatTriggerRelinking Include="WasmEnableExceptionHandling" DefaultValueInRuntimePack="true" />
<_BoolPropertiesThatTriggerRelinking Include="InvariantTimezone" DefaultValueInRuntimePack="false" />
<_BoolPropertiesThatTriggerRelinking Include="InvariantGlobalization" DefaultValueInRuntimePack="false" />
<_BoolPropertiesThatTriggerRelinking Include="WasmNativeStrip" DefaultValueInRuntimePack="true" />
</ItemGroup>
<PropertyGroup>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and
'$(%(_BoolPropertiesThatTriggerRelinking.Identity))' != '' and
'$(%(_BoolPropertiesThatTriggerRelinking.Identity))' != '%(_BoolPropertiesThatTriggerRelinking.DefaultValueInRuntimePack)'">true</WasmBuildNative>
</PropertyGroup>
<!-- When Building -->
<PropertyGroup Condition="'$(WasmBuildingForNestedPublish)' != 'true'">
<!-- build AOT, only if explicitly requested -->
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true' and '$(RunAOTCompilationAfterBuild)' == 'true'">true</WasmBuildNative>
<!-- removing legacy interop needs relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableLegacyJsInterop)' == 'false'" >true</WasmBuildNative>
<!-- disabling SIMD needs relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableSIMD)' == 'false'" >true</WasmBuildNative>
<!-- disabling EH needs relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableExceptionHandling)' == 'false'" >true</WasmBuildNative>
<!-- InvariantTimezone and InvariantGlobalization need rebuild -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(InvariantTimezone)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(InvariantGlobalization)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == ''">false</WasmBuildNative>
</PropertyGroup>
......@@ -137,13 +139,6 @@
<WasmBuildNative Condition="'$(RunAOTCompilation)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and @(NativeFileReference->Count()) > 0" >true</WasmBuildNative>
<!-- removing legacy interop needs relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(WasmEnableLegacyJsInterop)' == 'false'" >true</WasmBuildNative>
<!-- InvariantTimezone and InvariantGlobalization need rebuild -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(InvariantTimezone)' == 'true'">true</WasmBuildNative>
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(InvariantGlobalization)' == 'true'">true</WasmBuildNative>
<!-- not aot, not trimmed app, no reason to relink -->
<WasmBuildNative Condition="'$(WasmBuildNative)' == '' and '$(PublishTrimmed)' != 'true'">false</WasmBuildNative>
......@@ -162,6 +157,14 @@
</PropertyGroup>
</Target>
<Target Name="_SetWasmNativeStripDefault" Condition="'$(WasmNativeStrip)' == ''">
<PropertyGroup>
<!-- Build+relink+config=debug -->
<WasmNativeStrip Condition="'$(WasmBuildingForNestedPublish)' != 'true' and '$(WasmBuildNative)' == 'true' and '$(Configuration)' == 'Debug'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
</PropertyGroup>
</Target>
<Target Name="_WasmBuildNativeCore" DependsOnTargets="$(_WasmBuildNativeCoreDependsOn)" Condition="'$(WasmBuildNative)' == 'true'" />
<Target Name="_PrepareForWasmBuildNative">
......@@ -172,8 +175,6 @@
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
<_EmccDefaultFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-default.rsp'))</_EmccDefaultFlagsRsp>
<_EmccDefaultLinkFlagsRsp>$([MSBuild]::NormalizePath($(_WasmRuntimePackSrcDir), 'emcc-link.rsp'))</_EmccDefaultLinkFlagsRsp>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == '' and '$(Configuration)' == 'Debug' and '$(WasmBuildingForNestedPublish)' != 'true'">false</WasmNativeStrip>
<WasmNativeStrip Condition="'$(WasmNativeStrip)' == ''">true</WasmNativeStrip>
<WasmNativeDebugSymbols Condition="'$(WasmNativeDebugSymbols)' == ''">true</WasmNativeDebugSymbols>
<WasmLinkIcalls Condition="'$(WasmLinkIcalls)' == ''">$(WasmBuildNative)</WasmLinkIcalls>
......@@ -216,7 +217,7 @@
<_EmccCommonFlags Include="$(_DefaultEmccFlags)" />
<_EmccCommonFlags Include="$(EmccFlags)" />
<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeStrip)' == 'false'" />
<_EmccCommonFlags Include="-g" Condition="'$(WasmNativeDebugSymbols)' == 'true'" />
<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' != 'false'" />
<_EmccCommonFlags Include="-s DISABLE_EXCEPTION_CATCHING=0" Condition="'$(WasmEnableExceptionHandling)' == 'false'" />
<_EmccCommonFlags Include="-fwasm-exceptions" Condition="'$(WasmEnableExceptionHandling)' == 'true'" />
......@@ -243,7 +244,6 @@
<_EmccCFlags Include="-emit-llvm" />
<_EmccCFlags Include="&quot;-I%(_EmccIncludePaths.Identity)&quot;" />
<_EmccCFlags Include="-g" Condition="'$(WasmNativeDebugSymbols)' == 'true'" />
<!-- Adding optimization flag at the top, so it gets precedence -->
<_EmccLDFlags Include="$(EmccLinkOptimizationFlag)" />
......@@ -397,7 +397,7 @@
</ItemGroup>
</Target>
<Target Name="_WasmCalculateInitialHeapSize"
<Target Name="_WasmCalculateInitialHeapSize"
Condition="'$(EmccInitialHeapSize)' == ''"
DependsOnTargets="_CheckEmccIsExpectedVersion">
<ItemGroup>
......@@ -718,7 +718,7 @@
<ItemGroup>
<_AssembliesToScan Include="@(_WasmAssembliesInternal)" />
</ItemGroup>
<MarshalingPInvokeScanner Assemblies ="@(_AssembliesToScan)">
<Output TaskParameter="IncompatibleAssemblies" ItemName="MonoLightweightMarshallerIncompatibleAssemblies" />
</MarshalingPInvokeScanner>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册