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] Wasm.Build.Tests - use the new sdk with templates #85498

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion eng/testing/tests.browser.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project TreatAsLocalProperty="ArchiveTests">
<PropertyGroup>
<_UseWasmSymbolicator Condition="'$(TestTrimming)' != 'true'">true</_UseWasmSymbolicator>
<WorkloadsTestPreviousVersions>true</WorkloadsTestPreviousVersions>
</PropertyGroup>

<Import Project="tests.wasm.targets" />
Expand Down Expand Up @@ -265,7 +266,7 @@
Condition="'$(WorkloadsTestPreviousVersions)' == 'true'" />

<WorkloadCombinationsToInstall Include="latest" Variants="latest" />
<WorkloadCombinationsToInstall Include="net7" Variants="net7" Condition="'$(WorkloadsTestPreviousVersions)' == 'true'" />
<!--<WorkloadCombinationsToInstall Include="net7" Variants="net7" Condition="'$(WorkloadsTestPreviousVersions)' == 'true'" />-->
<WorkloadCombinationsToInstall Include="net7+latest" Variants="net7;latest" Condition="'$(WorkloadsTestPreviousVersions)' == 'true'" />
<!--<WorkloadCombinationsToInstall Include="net6" Variants="net6" />-->
<!--<WorkloadCombinationsToInstall Include="net6+7" Variants="net6;net7" />-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<ItemGroup>
<ProjectReference Include="$(RepoTasksDir)Microsoft.NET.Sdk.WebAssembly.Pack.Tasks\Microsoft.NET.Sdk.WebAssembly.Pack.Tasks.csproj" />
<PackageFile Include="build\*.props;build\*.targets;build\*.web.config" TargetPath="build" />
<PackageFile Include="Sdk\*.props;Sdk\*.targets;Sdk\*.web.config" TargetPath="Sdk" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't worked for me. How is it that it works now? Will it still work in blazor without workload?

</ItemGroup>

<Import Project="$([MSBuild]::GetPathOfFileAbove(Directory.Build.targets))" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,11 @@ Copyright (c) .NET Foundation. All rights reserved.

</ItemGroup>

<PropertyGroup>
<_WasmLinkerEnabled>$(PublishTrimmed)</_WasmLinkerEnabled>
<_WasmLinkerEnabled Condition="'$(_WasmLinkerEnabled)' == ''">false</_WasmLinkerEnabled>
</PropertyGroup>

<ComputeStaticWebAssetsTargetPaths
Assets="@(_WasmJsModuleCandidatesForPublish);@(_BlazorExtensionsCandidatesForPublish)"
PathPrefix=""
Expand All @@ -504,7 +509,7 @@ Copyright (c) .NET Foundation. All rights reserved.
AssemblyPath="@(IntermediateAssembly)"
Resources="@(_WasmPublishBootResourceWithHash)"
DebugBuild="false"
LinkerEnabled="$(PublishTrimmed)"
LinkerEnabled="$(_WasmLinkerEnabled)"
CacheBootResources="$(BlazorCacheBootResources)"
OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json"
ConfigurationFiles="@(_WasmPublishConfigFile)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"description": ".NET WebAssembly build tools",
"packs": [
"Microsoft.NET.Runtime.WebAssembly.Sdk",
"Microsoft.NET.Sdk.WebAssembly.Pack",
"Microsoft.NETCore.App.Runtime.Mono.browser-wasm",
"Microsoft.NETCore.App.Runtime.AOT.Cross.browser-wasm"
],
Expand Down Expand Up @@ -178,6 +179,10 @@
"kind": "Sdk",
"version": "${PackageVersion}"
},
"Microsoft.NET.Sdk.WebAssembly.Pack": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the consequence of this change? Will it still work in blazor without workload?

"kind": "Sdk",
"version": "${PackageVersion}"
},
"Microsoft.NET.Runtime.WebAssembly.Wasi.Sdk": {
"kind": "Sdk",
"version": "${PackageVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Runtime.WebAssembly.Sdk" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.WebAssembly.Sdk" />
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk.WebAssembly.Pack" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk.WebAssembly.Pack" />
<Import Project="Sdk.props" Sdk="Microsoft.NETCore.App.Runtime.AOT.Cross.browser-wasm" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Runtime.MonoTargets.Sdk" />
</ImportGroup>
Expand All @@ -149,6 +151,7 @@
<RuntimePackNamePatterns Condition="'$(RuntimeIdentifier)' == 'browser-wasm' and '$(WasmEnableThreads)' == 'true'">Microsoft.NETCore.App.Runtime.Mono.multithread.**RID**</RuntimePackNamePatterns>
<RuntimePackNamePatterns Condition="'$(RuntimeIdentifier)' == 'browser-wasm' and '$(WasmEnablePerfTracing)' == 'true'">Microsoft.NETCore.App.Runtime.Mono.perftrace.**RID**</RuntimePackNamePatterns>
</KnownRuntimePack>
<KnownWebAssemblySdkPack Remove="@(KnownWebAssemblySdkPack)" />
</ItemGroup>

<!-- we can't condition sdk imports on the item @(NativeFileReference). Instead, explicitly check before the build
Expand Down
12 changes: 10 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,16 @@ public async Task<IPage> RunAsync(ToolCommand cmd, string args, bool headless =
});

IPage page = await Browser.NewPageAsync();
if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(msg);
page.Console += (_, msg) =>
{
if (onConsoleMessage is not null)
onConsoleMessage(msg);

// when not forwarding console messages, they show up as
// Console log messages here. That should be checked with
// the various regexes
outputHandler(msg.Text);
};
await page.GotoAsync(urlAvailable.Task.Result);
RunTask = runTask;
return page;
Expand Down
169 changes: 103 additions & 66 deletions src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
{
AssertRuntimePackPath(result.buildOutput, options.TargetFramework ?? DefaultTargetFramework);

string bundleDir = Path.Combine(GetBinDir(config: buildArgs.Config, targetFramework: options.TargetFramework ?? DefaultTargetFramework), "AppBundle");
string bundleDir = Path.Combine(GetBinDir(config: buildArgs.Config, targetFramework: options.TargetFramework ?? DefaultTargetFramework, isPublish: options.Publish),
options.IsBrowserTemplateProject ? "wwwroot" : "AppBundle");
AssertBasicAppBundle(bundleDir,
buildArgs.ProjectName,
buildArgs.Config,
Expand All @@ -439,7 +440,8 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
options.PredefinedIcudt ?? "",
options.DotnetWasmFromRuntimePack ?? !buildArgs.AOT,
UseWebcil,
options.IsBrowserProject);
options.FromTemplate,
options.Publish);
}

if (options.UseCache)
Expand Down Expand Up @@ -508,14 +510,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
if (UseWebcil)
extraProperties += "<WasmEnableWebcil>true</WasmEnableWebcil>";

// TODO: Can be removed after updated templates propagate in.
string extraItems = string.Empty;
if (template == "wasmbrowser")
extraItems += "<WasmExtraFilesToDeploy Include=\"main.js\" />";
else
extraItems += "<WasmExtraFilesToDeploy Include=\"main.mjs\" />";

AddItemsPropertiesToProject(projectfile, extraProperties, extraItems);
AddItemsPropertiesToProject(projectfile, extraProperties);

return projectfile;
}
Expand Down Expand Up @@ -662,25 +657,45 @@ protected static void AssertBasicAppBundle(string bundleDir,
string predefinedIcudt = "",
bool dotnetWasmFromRuntimePack = true,
bool useWebcil = true,
bool isBrowserProject = true)
WasmTemplate fromTemplate = WasmTemplate.none,
bool isPublish = false)
{
var filesToExist = new List<string>()
{
mainJS,
"dotnet.wasm",
"mono-config.json",
"dotnet.js"
};

if (isBrowserProject)
filesToExist.Add("index.html");
// FIXME: um.. does this apply to all the templates?
if (isPublish)
filesToExist.Add(Path.Combine(bundleDir, mainJS));

string managedDir;
if (fromTemplate == WasmTemplate.wasmbrowser)
{
if (isPublish)
filesToExist.Add(Path.Combine(bundleDir, "index.html"));
bundleDir = Path.Combine(bundleDir, "_framework");
managedDir = bundleDir;

filesToExist.Add("blazor.boot.json");
}
else
{
managedDir = Path.Combine(bundleDir, "managed");

if (fromTemplate == WasmTemplate.wasmbrowser_legacy)
{
filesToExist.Add("mono-config.json");
filesToExist.Add("index.html");
}
}

AssertFilesExist(bundleDir, filesToExist);

AssertFilesExist(bundleDir, new[] { "run-v8.sh" }, expectToExist: hasV8Script);
AssertIcuAssets();
AssertIcuAssets(bundleDir, globalizationMode, predefinedIcudt);

string managedDir = Path.Combine(bundleDir, "managed");
string bundledMainAppAssembly =
useWebcil ? $"{projectName}.webcil" : $"{projectName}.dll";
AssertFilesExist(managedDir, new[] { bundledMainAppAssembly });
Expand All @@ -700,53 +715,61 @@ protected static void AssertBasicAppBundle(string bundleDir,
}

AssertDotNetWasmJs(bundleDir, fromRuntimePack: dotnetWasmFromRuntimePack, targetFramework);
}

void AssertIcuAssets()
protected static void AssertIcuAssets(string bundleDir, GlobalizationMode? globalizationMode, string predefinedIcudt)
{
Console.WriteLine ($"AssertIcuAssets: mode: {globalizationMode}, predef: {predefinedIcudt}");
bool expectEFIGS = false;
bool expectCJK = false;
bool expectNOCJK = false;
bool expectFULL = false;
switch (globalizationMode)
{
bool expectEFIGS = false;
bool expectCJK = false;
bool expectNOCJK = false;
bool expectFULL = false;
switch (globalizationMode)
{
case GlobalizationMode.Invariant:
break;
case GlobalizationMode.FullIcu:
expectFULL = true;
break;
case GlobalizationMode.PredefinedIcu:
if (string.IsNullOrEmpty(predefinedIcudt))
throw new ArgumentException("WasmBuildTest is invalid, value for predefinedIcudt is required when GlobalizationMode=PredefinedIcu.");
AssertFilesExist(bundleDir, new[] { predefinedIcudt }, expectToExist: true);
// predefined ICU name can be identical with the icu files from runtime pack
switch (predefinedIcudt)
{
case "icudt.dat":
expectFULL = true;
break;
case "icudt_EFIGS.dat":
expectEFIGS = true;
break;
case "icudt_CJK.dat":
expectCJK = true;
break;
case "icudt_no_CJK.dat":
expectNOCJK = true;
break;
}
break;
default:
// icu shard chosen based on the locale
expectCJK = true;
expectEFIGS = true;
expectNOCJK = true;
break;
}
AssertFilesExist(bundleDir, new[] { "icudt.dat" }, expectToExist: expectFULL);
AssertFilesExist(bundleDir, new[] { "icudt_EFIGS.dat" }, expectToExist: expectEFIGS);
AssertFilesExist(bundleDir, new[] { "icudt_CJK.dat" }, expectToExist: expectCJK);
AssertFilesExist(bundleDir, new[] { "icudt_no_CJK.dat" }, expectToExist: expectNOCJK);
case GlobalizationMode.Invariant:
break;
case GlobalizationMode.FullIcu:
expectFULL = true;
// Bug: all the files are deployed currently for blazor, and wasmbrowser case
expectCJK = true;
expectEFIGS = true;
expectNOCJK = true;
break;
case GlobalizationMode.PredefinedIcu:
if (string.IsNullOrEmpty(predefinedIcudt))
throw new ArgumentException("WasmBuildTest is invalid, value for predefinedIcudt is required when GlobalizationMode=PredefinedIcu.");
AssertFilesExist(bundleDir, new[] { predefinedIcudt }, expectToExist: true);
// predefined ICU name can be identical with the icu files from runtime pack
switch (predefinedIcudt)
{
case "icudt.dat":
expectFULL = true;
break;
case "icudt_EFIGS.dat":
expectEFIGS = true;
break;
case "icudt_CJK.dat":
expectCJK = true;
break;
case "icudt_no_CJK.dat":
expectNOCJK = true;
break;
}
break;
default:
// icu shard chosen based on the locale
expectCJK = true;
expectEFIGS = true;
expectNOCJK = true;
// Bug: all the files are deployed currently for blazor, and wasmbrowser case
expectFULL = true;
break;
}
// FIXME: AJ: open an issue
AssertFilesExist(bundleDir, new[] { "icudt.dat" }, expectToExist: expectFULL);
AssertFilesExist(bundleDir, new[] { "icudt_EFIGS.dat" }, expectToExist: expectEFIGS);
AssertFilesExist(bundleDir, new[] { "icudt_CJK.dat" }, expectToExist: expectCJK);
AssertFilesExist(bundleDir, new[] { "icudt_no_CJK.dat" }, expectToExist: expectNOCJK);
}

protected static void AssertDotNetWasmJs(string bundleDir, bool fromRuntimePack, string targetFramework)
Expand Down Expand Up @@ -777,7 +800,7 @@ protected static void AssertFilesExist(string dir, IEnumerable<string> filenames
throw new XunitException($"[{label}] {dir} not found");
foreach (string filename in filenames)
{
string path = Path.Combine(dir, filename);
string path = Path.IsPathRooted(filename) ? filename : Path.Combine(dir, filename);
if (expectToExist && !File.Exists(path))
throw new XunitException($"{prefix}Expected the file to exist: {path}");

Expand Down Expand Up @@ -832,6 +855,8 @@ protected void AssertBlazorBundle(string config, bool isPublish, bool dotnetWasm
dotnetJsPath!,
"Expected dotnet.js to be same as the runtime pack",
same: dotnetWasmFromRuntimePack);

AssertIcuAssets(binFrameworkDir, GlobalizationMode.FullIcu, "");
}

protected void AssertBlazorBootJson(string config, bool isPublish, string targetFramework = DefaultTargetFrameworkForBlazor, string? binFrameworkDir=null)
Expand Down Expand Up @@ -875,11 +900,11 @@ private string FindSubDirIgnoringCase(string parentDir, string dirName)
return first ?? Path.Combine(parentDir, dirName);
}

protected string GetBinDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null)
protected string GetBinDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null, bool isPublish=false)
{
var dir = baseDir ?? _projectDir;
Assert.NotNull(dir);
return Path.Combine(dir!, "bin", config, targetFramework, "browser-wasm");
return Path.Combine(dir!, "bin", config, targetFramework, "browser-wasm", isPublish ? "publish" : string.Empty);
}

protected string GetObjDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null)
Expand Down Expand Up @@ -1232,9 +1257,12 @@ public record BuildProjectOptions
string? Label = null,
string? TargetFramework = null,
string? MainJS = null,
bool IsBrowserProject = true,
WasmTemplate FromTemplate = WasmTemplate.none,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
);
)
{
public bool IsBrowserTemplateProject => FromTemplate == WasmTemplate.wasmbrowser;
}

public record BlazorBuildOptions
(
Expand All @@ -1253,5 +1281,14 @@ public enum GlobalizationMode
PredefinedIcu // user set WasmIcuDataFileName value and we are loading that file
};

public enum WasmTemplate
{
none,
wasmconsole,
wasmbrowser,
wasmbrowser_legacy,
wasiconsole
};

public enum NativeFilesType { FromRuntimePack, Relinked, AOT };
}
3 changes: 2 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/Common/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public static void DirectoryCopy(string sourceDirName, string destDirName, Func<
DirectoryInfo[] dirs = dir.GetDirectories();

// If the destination directory doesn't exist, create it.
Directory.CreateDirectory(destDirName);
if (!Directory.Exists(destDirName))
Directory.CreateDirectory(destDirName);

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
Expand Down
Loading