Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasm] Update Wasm.Build.Tests to build with net6.0 #54936

Merged
merged 12 commits into from
Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions eng/testing/tests.targets
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<Project>
<PropertyGroup>
<PropertyGroup Condition="'$(RunScriptInputName)' == ''">
<RunScriptInputName Condition="'$(TargetOS)' == 'windows'">RunnerTemplate.cmd</RunScriptInputName>
<RunScriptInputName Condition="'$(TargetOS)' != 'windows'">RunnerTemplate.sh</RunScriptInputName>
<RunScriptInputName Condition="'$(TargetOS)' == 'MacCatalyst' or '$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'iOSSimulator' or '$(TargetOS)' == 'tvOS' or '$(TargetOS)' == 'tvOSSimulator'">AppleRunnerTemplate.sh</RunScriptInputName>
<RunScriptInputName Condition="'$(TargetOS)' == 'Android'">AndroidRunnerTemplate.sh</RunScriptInputName>
<RunScriptInputName Condition="'$(TargetOS)' == 'Browser' and '$(OS)' != 'Windows_NT'">WasmRunnerTemplate.sh</RunScriptInputName>
<RunScriptInputName Condition="'$(TargetOS)' == 'Browser' and '$(OS)' == 'Windows_NT'">WasmRunnerTemplate.cmd</RunScriptInputName>
</PropertyGroup>

<RunScriptInputPath>$(MSBuildThisFileDirectory)$(RunScriptInputName)</RunScriptInputPath>
<PropertyGroup>
<RunScriptInputPath Condition="'$(RunScriptInputPath)' == ''">$(MSBuildThisFileDirectory)$(RunScriptInputName)</RunScriptInputPath>

<RunScriptOutputName Condition="'$(TargetOS)' != 'windows'">RunTests.sh</RunScriptOutputName>
<RunScriptOutputName Condition="'$(TargetOS)' == 'windows' or ('$(TargetOS)' == 'Browser' and '$(OS)' == 'Windows_NT')">RunTests.cmd</RunScriptOutputName>
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/sendtohelixhelp.proj
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@
<HelixCorrelationPayload Include="$(MonoAotCrossDir)" Destination="build/cross" />
</ItemGroup>

<ItemGroup Condition="'$(TargetOS)' == 'Browser'">
<ItemGroup Condition="'$(TargetOS)' == 'Browser' and '$(Scenario)' != 'BuildWasmApps'">
<HelixCorrelationPayload Include="$(TestEchoMiddleware)" Destination="xharness/TestEchoMiddleware" />
<HelixCorrelationPayload Include="$(RemoteLoopMiddleware)" Destination="xharness/RemoteLoopMiddleware" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions src/mono/wasm/build/WasmApp.LocalBuild.props
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
<Import Project="$(MSBuildThisFileDirectory)WasmApp.props" />

<PropertyGroup>
<!-- needed by the sdk, for net6.0, to include the correct runtime packs -->
<UseMonoRuntime>true</UseMonoRuntime>

<_NetCoreAppToolCurrent>net6.0</_NetCoreAppToolCurrent>
</PropertyGroup>

Expand Down
6 changes: 3 additions & 3 deletions src/mono/wasm/build/WasmApp.LocalBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
<DebuggerSupport>false</DebuggerSupport>
</PropertyGroup>

<!-- Redirect 'dotnet publish' to in-tree runtime pack -->
<Target Name="TrickRuntimePackLocation" AfterTargets="ProcessFrameworkReferences" DependsOnTargets="_PrepareAndValidateWasmInputs">
<Target Name="UpdateTargetingAndRuntimePack" AfterTargets="ResolveFrameworkReferences" DependsOnTargets="_PrepareAndValidateWasmInputs">
<ItemGroup>
<RuntimePack>
<PackageDirectory>$(MicrosoftNetCoreAppRuntimePackLocationToUse)</PackageDirectory>
</RuntimePack>
<ResolvedRuntimePack PackageDirectory="$(MicrosoftNetCoreAppRuntimePackLocationToUse)" />
</ItemGroup>
<Message Text="Using Runtime pack from: %(RuntimePack.PackageDirectory)" Importance="high" />
<Message Text="Using Runtime pack from: %(ResolvedRuntimePack.PackageDirectory)" Importance="high" />
</Target>

<!-- the actual properties need to get set in the props, so because UsingTasks depend on those. -->
Expand Down
11 changes: 1 addition & 10 deletions src/mono/wasm/build/WasmApp.Native.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@
<_ExeExt Condition="$([MSBuild]::IsOSPlatform('WINDOWS'))">.exe</_ExeExt>
<WasmUseEMSDK_PATH Condition="'$(WasmUseEMSDK_PATH)' == '' and '$(EMSDK_PATH)' != '' and Exists('$(MSBuildThisFileDirectory)WasmApp.InTree.targets')">true</WasmUseEMSDK_PATH>

<MicrosoftNetCoreAppRuntimePackDir Condition="'$(MicrosoftNetCoreAppRuntimePackDir)' == ''">$([MSBuild]::NormalizeDirectory($(NuGetPackageRoot), 'microsoft.netcore.app.runtime.mono.browser-wasm', '$(BundledNETCoreAppPackageVersion)'))</MicrosoftNetCoreAppRuntimePackDir>
<MicrosoftNetCoreAppRuntimePackRidDir Condition="'$(MicrosoftNetCoreAppRuntimePackRidDir)' == ''">$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackDir), 'runtimes', 'browser-wasm'))</MicrosoftNetCoreAppRuntimePackRidDir>
<MicrosoftNetCoreAppRuntimePackRidDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir)))</MicrosoftNetCoreAppRuntimePackRidDir>
<MicrosoftNetCoreAppRuntimePackRidNativeDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidDir), 'native'))</MicrosoftNetCoreAppRuntimePackRidNativeDir>

<_WasmRuntimePackIncludeDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include'))</_WasmRuntimePackIncludeDir>
<_WasmRuntimePackSrcDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'src'))</_WasmRuntimePackSrcDir>
<_EmccPropsPath>$(_WasmRuntimePackSrcDir)Emcc.props</_EmccPropsPath>
Expand Down Expand Up @@ -177,11 +172,6 @@
<_EmccCommonFlags Include="-v" Condition="'$(EmccVerbose)' != 'false'" />
</ItemGroup>

<PropertyGroup>
<_WasmRuntimePackIncludeDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'include'))</_WasmRuntimePackIncludeDir>
<_WasmRuntimePackSrcDir>$([MSBuild]::NormalizeDirectory($(MicrosoftNetCoreAppRuntimePackRidNativeDir), 'src'))</_WasmRuntimePackSrcDir>
</PropertyGroup>

<ItemGroup>
<_DotnetJSSrcFile Include="$(_WasmRuntimePackSrcDir)\*.js" />
</ItemGroup>
Expand Down Expand Up @@ -360,6 +350,7 @@ EMSCRIPTEN_KEEPALIVE void mono_wasm_load_profiler_aot (const char *desc) { mono_

<Target Name="_WasmAotCompileApp" Condition="'$(RunAOTCompilation)' == 'true'">
<PropertyGroup>
<!-- FIXME: do it once -->
<_MonoAotCrossCompilerPath>@(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
</PropertyGroup>

Expand Down
49 changes: 49 additions & 0 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BlazorWasmTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.IO;
using Xunit;
using Xunit.Abstractions;
// using FluentAssertions;

#nullable enable

namespace Wasm.Build.Tests
{
public class BlazorWasmTests : BuildTestBase
{
public BlazorWasmTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext)
: base(output, buildContext)
{
}

[ConditionalFact(typeof(BuildTestBase), nameof(IsUsingWorkloads))]
public void PublishTemplateProject()
{
InitPaths("id");
if (Directory.Exists(_projectDir))
Directory.Delete(_projectDir, recursive: true);
Directory.CreateDirectory(_projectDir);
Directory.CreateDirectory(Path.Combine(_projectDir, ".nuget"));

File.Copy(Path.Combine(BuildEnvironment.TestDataPath, "nuget6.config"), Path.Combine(_projectDir, "nuget.config"));
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"));

new DotNetCommand(s_buildEnv)
.WithWorkingDirectory(_projectDir)
.ExecuteWithCapturedOutput("new blazorwasm")
.EnsureSuccessful();

new DotNetCommand(s_buildEnv)
.WithWorkingDirectory(_projectDir)
.ExecuteWithCapturedOutput("publish -bl -p:RunAOTCompilation=true")
.EnsureSuccessful();

//TODO: validate the build somehow?
// compare dotnet.wasm?
// playwright?
}
}
}
136 changes: 136 additions & 0 deletions src/tests/BuildWasmApps/Wasm.Build.Tests/BuildEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
// 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;

namespace Wasm.Build.Tests
{
public class BuildEnvironment
{
public string DotNet { get; init; }
public string RuntimePackDir { get; init; }
public bool IsWorkload { get; init; }
public string DefaultBuildArgs { get; init; }
public IDictionary<string, string> EnvVars { get; init; }
public string DirectoryBuildPropsContents { get; init; }
public string DirectoryBuildTargetsContents { get; init; }
public string RuntimeNativeDir { get; init; }
public string LogRootPath { get; init; }

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");

private static string s_runtimeConfig = "Release";
private const string s_testLogPathEnvVar = "TEST_LOG_PATH";

public BuildEnvironment()
{
DirectoryInfo? solutionRoot = new (AppContext.BaseDirectory);
while (solutionRoot != null)
{
if (File.Exists(Path.Combine(solutionRoot.FullName, "NuGet.config")))
{
break;
}

solutionRoot = solutionRoot.Parent;
}

string? sdkForWorkloadPath = Environment.GetEnvironmentVariable("SDK_FOR_WORKLOAD_TESTING_PATH");
if (!string.IsNullOrEmpty(sdkForWorkloadPath))
{

DotNet = Path.Combine(sdkForWorkloadPath, "dotnet");
var workloadPacksVersion = Environment.GetEnvironmentVariable("WORKLOAD_PACKS_VER");
if (string.IsNullOrEmpty(workloadPacksVersion))
throw new Exception($"Cannot test with workloads without WORKLOAD_PACKS_VER environment variable being set");

RuntimePackDir = Path.Combine(sdkForWorkloadPath, "packs", "Microsoft.NETCore.App.Runtime.Mono.browser-wasm", workloadPacksVersion);
DirectoryBuildPropsContents = s_directoryBuildPropsForWorkloads;
DirectoryBuildTargetsContents = s_directoryBuildTargetsForWorkloads;
EnvVars = new Dictionary<string, string>()
{
// `runtime` repo's build environment sets these, and they
// mess up the build for the test project, which is using a different
// dotnet
["DOTNET_INSTALL_DIR"] = sdkForWorkloadPath,
["DOTNET_MULTILEVEL_LOOKUP"] = "0",
["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "1",
["MSBuildSDKsPath"] = string.Empty,
["PATH"] = $"{sdkForWorkloadPath}{Path.PathSeparator}{Environment.GetEnvironmentVariable("PATH")}"
};

var appRefDir = Environment.GetEnvironmentVariable("AppRefDir");
if (string.IsNullOrEmpty(appRefDir))
throw new Exception($"Cannot test with workloads without AppRefDir environment variable being set");

DefaultBuildArgs = $" /p:AppRefDir={appRefDir}";
IsWorkload = true;
}
else
{
string emsdkPath;
if (solutionRoot == null)
{
string? buildDir = Environment.GetEnvironmentVariable("WasmBuildSupportDir");

if (buildDir == null || !Directory.Exists(buildDir))
throw new Exception($"Could not find the solution root, or a build dir: {buildDir}");

emsdkPath = Path.Combine(buildDir, "emsdk");
RuntimePackDir = Path.Combine(buildDir, "microsoft.netcore.app.runtime.browser-wasm");
DefaultBuildArgs = $" /p:WasmBuildSupportDir={buildDir} /p:EMSDK_PATH={emsdkPath} ";
}
else
{
string artifactsBinDir = Path.Combine(solutionRoot.FullName, "artifacts", "bin");
RuntimePackDir = Path.Combine(artifactsBinDir, "microsoft.netcore.app.runtime.browser-wasm", s_runtimeConfig);

string? emsdkEnvValue = Environment.GetEnvironmentVariable("EMSDK_PATH");
if (string.IsNullOrEmpty(emsdkEnvValue))
emsdkPath = Path.Combine(solutionRoot.FullName, "src", "mono", "wasm", "emsdk");
else
emsdkPath = emsdkEnvValue;

DefaultBuildArgs = $" /p:RuntimeSrcDir={solutionRoot.FullName} /p:RuntimeConfig={s_runtimeConfig} /p:EMSDK_PATH={emsdkPath} ";
}

IsWorkload = false;
DotNet = "dotnet";
EnvVars = new Dictionary<string, string>()
{
["EMSDK_PATH"] = emsdkPath
};

DirectoryBuildPropsContents = s_directoryBuildPropsForLocal;
DirectoryBuildTargetsContents = s_directoryBuildTargetsForLocal;
}

RuntimeNativeDir = Path.Combine(RuntimePackDir, "runtimes", "browser-wasm", "native");

string? logPathEnvVar = Environment.GetEnvironmentVariable(s_testLogPathEnvVar);
if (!string.IsNullOrEmpty(logPathEnvVar))
{
LogRootPath = logPathEnvVar;
if (!Directory.Exists(LogRootPath))
{
Directory.CreateDirectory(LogRootPath);
}
}
else
{
LogRootPath = Environment.CurrentDirectory;
}
}

// FIXME: update these to use Workload variants of the file, with the workload support
protected static string s_directoryBuildPropsForWorkloads = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.props"));
protected static string s_directoryBuildTargetsForWorkloads = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.targets"));

protected static string s_directoryBuildPropsForLocal = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.props"));
protected static string s_directoryBuildTargetsForLocal = File.ReadAllText(Path.Combine(TestDataPath, "Local.Directory.Build.targets"));
}
}
Loading