Skip to content

Commit

Permalink
[wasm] Update Wasm.Build.Tests to build with tfm=net9.0 (dotnet#93693)
Browse files Browse the repository at this point in the history
* workload-testing.targets: Make dotnet script paths available outside

.. targets. This is useful when `dotnet-none` is already installed and
thus the installation target does not run.

* WorkloadManifest.targets: Disable workaround to use net9.0 artifacts

.. with `tfm=net8.0` . But don't disable this for Blazor projects which
are still using `tfm=net8.0`.

* [wasm] Improve parsing runtime pack versions from environment variables

* [wasm] Allow WBTOverridePack targets use to be set per test

This allows having it enabled only for the blazor projects right now,
which are still on tfm=net8.0 .

* [wasm] WBT: Update tests to run with net9.0

* [wasm] WBT: Remove --experiment-wasm-simd for v8

* [wasm] WBT: differentiate version used for tasks from the tfm

* [wasm] Fix wasmbrowser template so it correctly updates the tfm in csproj

* [wasm] WBT: Add runtime pack version for 9 in wasi

* [wasm] WBT: Share nuget config files between wasm and wasi

* [wasm] WBT: Fix blazor tests

* [wasm] WBT: Don't test 8.0 templates yet. this will need more changes

* [wasm] Don't default ForceNet8Current=false yet

Instead set this only for WBT.

* perf: add dummy change to trigger runtime-wasm-perf
  • Loading branch information
radical authored and liveans committed Nov 9, 2023
1 parent ec5716b commit 70134a8
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 67 deletions.
2 changes: 1 addition & 1 deletion eng/pipelines/runtime-wasm-perf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extends:
runProfile: 'v8'
collectHelixLogsScript: ${{ variables._wasmCollectHelixLogsScript }}
onlySanityCheck: true
#perfForkToUse:
#perfForkToUse: - dummy change
#url: https://github.com/radical/performance
#branch: fix-build
#downloadSpecificBuild:
Expand Down
42 changes: 21 additions & 21 deletions eng/testing/workloads-testing.targets
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,27 @@
</InstallWorkloadUsingArtifactsDependsOn>
</PropertyGroup>

<PropertyGroup>
<_DotNetInstallScriptName Condition="!$([MSBuild]::IsOSPlatform('windows'))">dotnet-install.sh</_DotNetInstallScriptName>
<_DotNetInstallScriptName Condition=" $([MSBuild]::IsOSPlatform('windows'))">dotnet-install.ps1</_DotNetInstallScriptName>

<_DotNetInstallScriptPath>$(ArtifactsObjDir)$(_DotNetInstallScriptName)</_DotNetInstallScriptPath>
</PropertyGroup>

<PropertyGroup Condition="'$(SdkVersionForWorkloadTesting)' != ''">
<_DotNetInstallCommand Condition="!$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -i $(_SdkWithNoWorkloadPath) -v $(SdkVersionForWorkloadTesting)</_DotNetInstallCommand>
<_DotNetInstallCommand Condition="$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -InstallDir $(_SdkWithNoWorkloadPath) -Version $(SdkVersionForWorkloadTesting)</_DotNetInstallCommand>
</PropertyGroup>

<PropertyGroup Condition="'$(SdkVersionForWorkloadTesting)' == ''">
<_DotNetInstallCommand Condition="!$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -i $(_SdkWithNoWorkloadPath) -v latest -q daily --channel 9.0</_DotNetInstallCommand>
<_DotNetInstallCommand Condition="$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -InstallDir $(_SdkWithNoWorkloadPath) -Quality daily -Channel 9.0</_DotNetInstallCommand>
</PropertyGroup>

<ItemGroup>
<!--<AdditionalSharedFrameworkToInstallArguments Include="-Version 8.0.0-rc.2.23457.7" />-->
<!-- Required for running apps built with 9.0 sdk, but the sdk does
Expand Down Expand Up @@ -57,27 +78,6 @@
<RemoveDir Directories="$(_SdkWithNoWorkloadPath)" />
<MakeDir Directories="$(_SdkWithNoWorkloadPath)" />

<PropertyGroup>
<_DotNetInstallScriptName Condition="!$([MSBuild]::IsOSPlatform('windows'))">dotnet-install.sh</_DotNetInstallScriptName>
<_DotNetInstallScriptName Condition=" $([MSBuild]::IsOSPlatform('windows'))">dotnet-install.ps1</_DotNetInstallScriptName>

<_DotNetInstallScriptPath>$(ArtifactsObjDir)$(_DotNetInstallScriptName)</_DotNetInstallScriptPath>
</PropertyGroup>

<PropertyGroup Condition="'$(SdkVersionForWorkloadTesting)' != ''">
<_DotNetInstallCommand Condition="!$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -i $(_SdkWithNoWorkloadPath) -v $(SdkVersionForWorkloadTesting)</_DotNetInstallCommand>
<_DotNetInstallCommand Condition="$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -InstallDir $(_SdkWithNoWorkloadPath) -Version $(SdkVersionForWorkloadTesting)</_DotNetInstallCommand>
</PropertyGroup>

<PropertyGroup Condition="'$(SdkVersionForWorkloadTesting)' == ''">
<_DotNetInstallCommand Condition="!$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -i $(_SdkWithNoWorkloadPath) -v latest -q daily --channel 9.0</_DotNetInstallCommand>
<_DotNetInstallCommand Condition="$([MSBuild]::IsOSPlatform('windows'))"
>$(_DotNetInstallScriptPath) -InstallDir $(_SdkWithNoWorkloadPath) -Quality daily -Channel 9.0</_DotNetInstallCommand>
</PropertyGroup>

<DownloadFile SourceUrl="https://dot.net/v1/$(_DotNetInstallScriptName)"
DestinationFolder="$(ArtifactsObjDir)"
Retries="3"
Expand Down
15 changes: 12 additions & 3 deletions src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace Wasm.Build.Tests
{
public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixture>, IDisposable
{
public const string DefaultTargetFramework = "net8.0";
public const string DefaultTargetFramework = "net9.0";
protected static readonly bool s_skipProjectCleanup;
protected static readonly string s_xharnessRunnerCommand;
protected string? _projectDir;
Expand All @@ -36,6 +36,13 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
protected SharedBuildPerTestClassFixture _buildContext;
protected string _nugetPackagesDir = string.Empty;

/* This will trigger importing WasmOverridePacks.targets for the tests,
* which will override the runtime pack with with the locally built one.
* But note that this only partially helps with "switching workloads" because
* the tasks/targets, aot compiler, etc would still be from the old version
*/
public bool UseWBTOverridePackTargets = false;

// FIXME: use an envvar to override this
protected static int s_defaultPerTestTimeoutMs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 30*60*1000 : 15*60*1000;
protected static BuildEnvironment s_buildEnv;
Expand All @@ -48,7 +55,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
public static bool IsUsingWorkloads => s_buildEnv.IsWorkload;
public static bool IsNotUsingWorkloads => !s_buildEnv.IsWorkload;
public static string GetNuGetConfigPathFor(string targetFramework) =>
Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with
Path.Combine(BuildEnvironment.TestDataPath, "nuget9.config");
// targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");

static BuildTestBase()
Expand Down Expand Up @@ -205,7 +212,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp

File.WriteAllText(Path.Combine(_projectDir, $"{buildArgs.ProjectName}.csproj"), buildArgs.ProjectFileContents);
File.Copy(Path.Combine(AppContext.BaseDirectory,
options.TargetFramework == "net8.0" ? "test-main.js" : "data/test-main-7.0.js"),
options.TargetFramework == "net7.0" ? "data/test-main-7.0.js" : "test-main.js"),
Path.Combine(_projectDir, "test-main.js"));
}
else if (_projectDir is null)
Expand Down Expand Up @@ -243,6 +250,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
envVars[kvp.Key] = kvp.Value;
}
envVars["NUGET_PACKAGES"] = _nugetPackagesDir;
if (UseWBTOverridePackTargets && s_buildEnv.IsWorkload)
envVars["WBTOverrideRuntimePack"] = "true";
result = AssertBuild(sb.ToString(), id, expectSuccess: options.ExpectSuccess, envVars: envVars);

// check that we are using the correct runtime pack!
Expand Down
5 changes: 4 additions & 1 deletion src/mono/wasi/Wasi.Build.Tests/Wasi.Build.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

<None Include="..\testassets\**\*" Link="testassets\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<None Include="data\**\*" Link="data\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(_MonoSrcWasmDir)Wasm.Build.Tests\data\nuget*" Link="data\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
<None Include="$(_MonoSrcWasmDir)Wasm.Build.Tests\data\WasmOverridePacks.targets" Link="data\%(RecursiveDir)%(FileName)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

Expand Down Expand Up @@ -90,7 +91,9 @@
</ItemGroup>

<ItemGroup>
<_RuntimePackVersions Include="$(PackageVersion)" EnvVarName="RUNTIME_PACK_VER8" />
<_RuntimePackVersions Include="$(PackageVersion)" EnvVarName="RUNTIME_PACK_VER9" />
<_RuntimePackVersions Include="$(PackageVersionNet8)" EnvVarName="RUNTIME_PACK_VER8" Condition="'$(PackageVersionNet8)' != ''" />
<_RuntimePackVersions Include="$(PackageVersion)" EnvVarName="RUNTIME_PACK_VER8" Condition="'$(PackageVersionNet8)' == ''" />

<RunScriptCommands Condition="'$(OS)' != 'Windows_NT'" Include="export %(_RuntimePackVersions.EnvVarName)=&quot;%(_RuntimePackVersions.Identity)&quot;" />
<RunScriptCommands Condition="'$(OS)' == 'Windows_NT'" Include="set &quot;%(_RuntimePackVersions.EnvVarName)=%(_RuntimePackVersions.Identity)&quot;" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void InitBlazorWasmProjectDir(string id, string targetFramework = Default

File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "Blazor.Directory.Build.targets"), Path.Combine(_projectDir, "Directory.Build.targets"));
if (BuildEnvironment.UseWBTOverridePackTargets)
if (UseWBTOverridePackTargets)
File.Copy(BuildEnvironment.WasmOverridePacksTargetsPath, Path.Combine(_projectDir, Path.GetFileName(BuildEnvironment.WasmOverridePacksTargetsPath)), overwrite: true);
}

Expand Down
26 changes: 18 additions & 8 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ namespace Wasm.Build.Tests
{
public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixture>, IDisposable
{
public const string DefaultTargetFramework = "net8.0";
public const string DefaultTargetFramework = "net9.0";
public const string DefaultTargetFrameworkForBlazor = "net8.0";
public const string TargetFrameworkForTasks = "net8.0";
private const string DefaultEnvironmentLocale = "en-US";
protected static readonly char s_unicodeChar = '\u7149';
protected static readonly bool s_skipProjectCleanup;
Expand All @@ -38,6 +39,13 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
protected string _nugetPackagesDir = string.Empty;
private ProjectProviderBase _providerOfBaseType;

/* This will trigger importing WasmOverridePacks.targets for the tests,
* which will override the runtime pack with with the locally built one.
* But note that this only partially helps with "switching workloads" because
* the tasks/targets, aot compiler, etc would still be from the old version
*/
public bool UseWBTOverridePackTargets = false;

private static readonly char[] s_charsToReplace = new[] { '.', '-', '+' };
private static bool s_isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
// changing Windows's language programistically is complicated and Node is using OS's language to determine
Expand All @@ -53,9 +61,8 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
public static bool IsNotUsingWorkloads => !s_buildEnv.IsWorkload;
public static bool IsWorkloadWithMultiThreadingForDefaultFramework => s_buildEnv.IsWorkloadWithMultiThreadingForDefaultFramework;
public static bool UseWebcil => s_buildEnv.UseWebcil;
public static string GetNuGetConfigPathFor(string targetFramework) =>
Path.Combine(BuildEnvironment.TestDataPath, "nuget8.config"); // for now - we are still using net7, but with
// targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
public static string GetNuGetConfigPathFor(string targetFramework)
=> Path.Combine(BuildEnvironment.TestDataPath, targetFramework == "net9.0" ? "nuget9.config" : "nuget8.config");

public TProvider GetProvider<TProvider>() where TProvider : ProjectProviderBase
=> (TProvider)_providerOfBaseType;
Expand Down Expand Up @@ -156,11 +163,14 @@ public BuildTestBase(ProjectProviderBase providerBase, ITestOutputHelper output,
if (buildProjectOptions.Publish && buildProjectOptions.BuildOnlyAfterPublish)
commandLineArgs.Append("-p:WasmBuildOnlyAfterPublish=true");

CommandResult res = new DotNetCommand(s_buildEnv, _testOutput)
var cmd = new DotNetCommand(s_buildEnv, _testOutput)
.WithWorkingDirectory(_projectDir!)
.WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir)
.WithEnvironmentVariables(buildProjectOptions.ExtraBuildEnvironmentVariables)
.ExecuteWithCapturedOutput(commandLineArgs.ToArray());
.WithEnvironmentVariables(buildProjectOptions.ExtraBuildEnvironmentVariables);
if (UseWBTOverridePackTargets && s_buildEnv.IsWorkload)
cmd.WithEnvironmentVariable("WBTOverrideRuntimePack", "true");

CommandResult res = cmd.ExecuteWithCapturedOutput(commandLineArgs.ToArray());
if (buildProjectOptions.ExpectSuccess)
res.EnsureSuccessful();
else if (res.ExitCode == 0)
Expand Down Expand Up @@ -339,7 +349,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages =
Directory.CreateDirectory(dir);
File.WriteAllText(Path.Combine(dir, "Directory.Build.props"), s_buildEnv.DirectoryBuildPropsContents);
File.WriteAllText(Path.Combine(dir, "Directory.Build.targets"), s_buildEnv.DirectoryBuildTargetsContents);
if (BuildEnvironment.UseWBTOverridePackTargets)
if (UseWBTOverridePackTargets)
File.Copy(BuildEnvironment.WasmOverridePacksTargetsPath, Path.Combine(dir, Path.GetFileName(BuildEnvironment.WasmOverridePacksTargetsPath)), overwrite: true);

string targetNuGetConfigPath = Path.Combine(dir, "nuget.config");
Expand Down
30 changes: 15 additions & 15 deletions src/mono/wasm/Wasm.Build.Tests/Common/BuildEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

#nullable enable

Expand All @@ -27,13 +29,6 @@ public class BuildEnvironment
public bool IsWorkloadWithMultiThreadingForDefaultFramework { get; init; }
public bool IsRunningOnCI => EnvironmentVariables.IsRunningOnCI;

/* This will trigger importing WasmOverridePacks.targets for the tests,
* which will override the runtime pack with with the locally built one.
* But note that this only partially helps with "switching workloads" because
* the tasks/targets, aot compiler, etc would still be from the old version
*/
public static readonly bool UseWBTOverridePackTargets = false;

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");
Expand Down Expand Up @@ -81,11 +76,15 @@ public BuildEnvironment()

sdkForWorkloadPath = Path.GetFullPath(sdkForWorkloadPath);

// FIXME:
foreach (string verStr in new[] { "8", "7", "6" })
Regex runtimePackRegex = new(@"^RUNTIME_PACK_VER(\d+)$");
foreach (DictionaryEntry de in Environment.GetEnvironmentVariables())
{
string versionValue = Environment.GetEnvironmentVariable($"RUNTIME_PACK_VER{verStr}") ?? string.Empty;
s_runtimePackVersions[$"net{verStr}.0"] = versionValue;
Match m = runtimePackRegex.Match((string)de.Key);
if (!m.Success)
continue;

int major = int.Parse(m.Groups[1].Value);
s_runtimePackVersions[$"net{major}.0"] = (string)(de.Value ?? string.Empty);
}

DefaultBuildArgs = string.Empty;
Expand Down Expand Up @@ -128,8 +127,6 @@ public BuildEnvironment()
EnvVars["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1";
EnvVars["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}";
EnvVars["EM_WORKAROUND_PYTHON_BUG_34780"] = "1";
if (UseWBTOverridePackTargets && IsWorkload)
EnvVars["WBTOverrideRuntimePack"] = "true";

if (!UseWebcil)
{
Expand Down Expand Up @@ -159,8 +156,11 @@ public BuildEnvironment()
Directory.CreateDirectory(TmpPath);
}

// FIXME: error checks
public string GetRuntimePackVersion(string tfm = BuildTestBase.DefaultTargetFramework) => s_runtimePackVersions[tfm];
public string GetRuntimePackVersion(string tfm = BuildTestBase.DefaultTargetFramework)
=> s_runtimePackVersions.TryGetValue(tfm, out string? version)
? version
: throw new ArgumentException($"No runtime pack version found for tfm={tfm} .");

public string GetRuntimePackDir(string tfm = BuildTestBase.DefaultTargetFramework, RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded)
=> Path.Combine(WorkloadPacksDir,
runtimeType is RuntimeVariant.SingleThreaded
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/HostRunner/V8HostRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private static string BinaryPathArg
}
}

private string GetXharnessArgs(string jsRelativePath) => $"--js-file={jsRelativePath} --engine=V8 -v trace --engine-arg=--experimental-wasm-simd --engine-arg=--module {BinaryPathArg}";
private string GetXharnessArgs(string jsRelativePath) => $"--js-file={jsRelativePath} --engine=V8 -v trace --engine-arg=--module {BinaryPathArg}";

public string GetTestCommand() => "wasm test";
public string GetXharnessArgsWindowsOS(XHarnessArgsOptions options) => GetXharnessArgs(options.jsRelativePath);
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/NonWasmTemplateBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public NonWasmTemplateBuildTests(ITestOutputHelper output, SharedBuildPerTestCla
//
// This is useful for the case when we are on tfm=net7.0, but sdk, and packages
// are really 8.0 .
private const string s_latestTargetFramework = "net8.0";
private const string s_previousTargetFramework = "net7.0";
private const string s_latestTargetFramework = "net9.0";
private const string s_previousTargetFramework = "net8.0";
private static string s_directoryBuildTargetsForPreviousTFM =
$$"""
<Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ public static void Main()
"Microsoft.NET.Runtime.WebAssembly.Sdk",
s_buildEnv.GetRuntimePackVersion(DefaultTargetFramework),
"tasks",
BuildTestBase.DefaultTargetFramework); // not net472!
BuildTestBase.TargetFrameworkForTasks); // not net472!
if (!Directory.Exists(tasksDir)) {
string? tasksDirParent = Path.GetDirectoryName (tasksDir);
if (!string.IsNullOrEmpty (tasksDirParent)) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/wasm/Wasm.Build.Tests/SatelliteAssembliesTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void ResourcesFromProjectReference(BuildArgs buildArgs,
// affect the non-wasm library project
File.Move(Path.Combine(rootDir, "Directory.Build.props"), Path.Combine(_projectDir, "Directory.Build.props"));
File.Move(Path.Combine(rootDir, "Directory.Build.targets"), Path.Combine(_projectDir, "Directory.Build.targets"));
if (BuildEnvironment.UseWBTOverridePackTargets)
if (UseWBTOverridePackTargets)
File.Move(Path.Combine(rootDir, "WasmOverridePacks.targets"), Path.Combine(_projectDir, "WasmOverridePacks.targets"));

CreateProgramForCultureTest(_projectDir, "LibraryWithResources.resx.words", "LibraryWithResources.Class1");
Expand Down
Loading

0 comments on commit 70134a8

Please sign in to comment.