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

[browser] Use Wasm SDK in browser template #85311

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-advanced/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type='module' src="./main.js"></script>
<script type='module' src="./dotnet.js"></script>
<link rel="preload" href="./mono-config.json" as="fetch" crossorigin="anonymous">
<link rel="preload" href="./blazor.boot.json" as="fetch" crossorigin="anonymous">
<link rel="prefetch" href="./dotnet.wasm" as="fetch" crossorigin="anonymous">
<!-- users should consider if they optimize for the first load or subsequent load from memory snapshot -->
<link rel="prefetch" href="./icudt.dat" as="fetch" crossorigin="anonymous">
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-advanced/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ try {
// here we show how emscripten could be further configured
// It is prefered to use specific 'with***' methods instead in all other cases.
.withModuleConfig({
configSrc: "./mono-config.json",
configSrc: "./_framework/blazor.boot.json",
onConfigLoaded: (config) => {
// This is called during emscripten `dotnet.wasm` instantiation, after we fetched config.
console.log('user code Module.onConfigLoaded');
Expand Down
2 changes: 1 addition & 1 deletion src/mono/sample/wasm/browser-bench/appstart-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="module" src="./frame-main.js"></script>
<script type='module' src="./dotnet.js"></script>
<link rel="preload" href="./mono-config.json" as="fetch" crossorigin="anonymous">
<link rel="preload" href="./_framework/blazor.boot.json" as="fetch" crossorigin="anonymous">
<link rel="prefetch" href="./dotnet.wasm" as="fetch" crossorigin="anonymous">
<!-- users should consider if they optimize for the first load or subsequent load from memory snapshot -->
<link rel="prefetch" href="./managed/System.Private.CoreLib.dll" as="fetch" crossorigin="anonymous">
Expand Down
78 changes: 39 additions & 39 deletions src/mono/wasi/Wasi.Build.Tests/BuildTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
protected string _nugetPackagesDir = string.Empty;

// FIXME: use an envvar to override this
protected static int s_defaultPerTestTimeoutMs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 30*60*1000 : 15*60*1000;
protected static int s_defaultPerTestTimeoutMs = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? 30 * 60 * 1000 : 15 * 60 * 1000;
protected static BuildEnvironment s_buildEnv;
private const string s_runtimePackPathPattern = "\\*\\* MicrosoftNetCoreAppRuntimePackDir : '([^ ']*)'";
private const string s_nugetInsertionTag = "<!-- TEST_RESTORE_SOURCES_INSERTION_LINE -->";
Expand All @@ -49,7 +49,7 @@ public abstract class BuildTestBase : IClassFixture<SharedBuildPerTestClassFixtu
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
// targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");
// targetFramework == "net7.0" ? "nuget7.config" : "nuget8.config");

static BuildTestBase()
{
Expand All @@ -69,15 +69,15 @@ static BuildTestBase()
else
s_xharnessRunnerCommand = EnvironmentVariables.XHarnessCliPath;

Console.WriteLine ("");
Console.WriteLine ($"==============================================================================================");
Console.WriteLine ($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ===============");
Console.WriteLine ($"==============================================================================================");
Console.WriteLine ("");
Console.WriteLine("");
Console.WriteLine($"==============================================================================================");
Console.WriteLine($"=============== Running with {(s_buildEnv.IsWorkload ? "Workloads" : "No workloads")} ===============");
Console.WriteLine($"==============================================================================================");
Console.WriteLine("");
}
catch (Exception ex)
{
Console.WriteLine ($"Exception: {ex}");
Console.WriteLine($"Exception: {ex}");
throw;
}
}
Expand All @@ -90,7 +90,7 @@ public BuildTestBase(ITestOutputHelper output, SharedBuildPerTestClassFixture bu
_logPath = s_buildEnv.LogRootPath; // FIXME:
}

public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config=null)
public static IEnumerable<IEnumerable<object?>> ConfigWithAOTData(bool aot, string? config = null)
{
if (config == null)
{
Expand Down Expand Up @@ -163,7 +163,7 @@ protected void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages =
##INSERT_AT_END##
</Project>";

protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties="", string extraItems="", string insertAtEnd="", string projectTemplate=SimpleProjectTemplate)
protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProperties = "", string extraItems = "", string insertAtEnd = "", string projectTemplate = SimpleProjectTemplate)
{
if (buildArgs.AOT)
{
Expand All @@ -185,7 +185,7 @@ protected static BuildArgs ExpandBuildArgs(BuildArgs buildArgs, string extraProp
string msgPrefix = options.Label != null ? $"[{options.Label}] " : string.Empty;
if (options.UseCache && _buildContext.TryGetBuildFor(buildArgs, out BuildProduct? product))
{
_testOutput.WriteLine ($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}");
_testOutput.WriteLine($"Using existing build found at {product.ProjectDir}, with build log at {product.LogFile}");

if (!product.Result)
throw new XunitException($"Found existing build at {product.ProjectDir}, but it had failed. Check build log at {product.LogFile}");
Expand Down Expand Up @@ -309,7 +309,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
return projectfile;
}

protected (CommandResult, string) BuildInternal(string id, string config, bool publish=false, bool setWasmDevel=true, params string[] extraArgs)
protected (CommandResult, string) BuildInternal(string id, string config, bool publish = false, bool setWasmDevel = true, params string[] extraArgs)
{
string label = publish ? "publish" : "build";
_testOutput.WriteLine($"{Environment.NewLine}** {label} **{Environment.NewLine}");
Expand Down Expand Up @@ -361,7 +361,7 @@ protected static void AssertBasicAppBundle(string bundleDir,
"index.html",
mainJS,
"dotnet.wasm",
"mono-config.json",
"_framework/blazor.boot.json",
"dotnet.js"
});

Expand Down Expand Up @@ -392,7 +392,7 @@ protected static void AssertBasicAppBundle(string bundleDir,
protected static void AssertFilesDontExist(string dir, string[] filenames, string? label = null)
=> AssertFilesExist(dir, filenames, label, expectToExist: false);

protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist=true)
protected static void AssertFilesExist(string dir, string[] filenames, string? label = null, bool expectToExist = true)
{
string prefix = label != null ? $"{label}: " : string.Empty;
if (!Directory.Exists(dir))
Expand All @@ -408,10 +408,10 @@ protected static void AssertFilesExist(string dir, string[] filenames, string? l
}
}

protected static void AssertSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: true);
protected static void AssertNotSameFile(string file0, string file1, string? label=null) => AssertFile(file0, file1, label, same: false);
protected static void AssertSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: true);
protected static void AssertNotSameFile(string file0, string file1, string? label = null) => AssertFile(file0, file1, label, same: false);

protected static void AssertFile(string file0, string file1, string? label=null, bool same=true)
protected static void AssertFile(string file0, string file1, string? label = null, bool same = true)
{
Assert.True(File.Exists(file0), $"{label}: Expected to find {file0}");
Assert.True(File.Exists(file1), $"{label}: Expected to find {file1}");
Expand All @@ -426,7 +426,7 @@ protected static void AssertFile(string file0, string file1, string? label=null,
throw new XunitException($"{label}:{Environment.NewLine} File sizes should not match for {file0} ({finfo0.Length}), and {file1} ({finfo1.Length})");
}

protected (int exitCode, string buildOutput) AssertBuild(string args, string label="build", bool expectSuccess=true, IDictionary<string, string>? envVars=null, int? timeoutMs=null)
protected (int exitCode, string buildOutput) AssertBuild(string args, string label = "build", bool expectSuccess = true, IDictionary<string, string>? envVars = null, int? timeoutMs = null)
{
var result = RunProcess(s_buildEnv.DotNet, _testOutput, args, workingDir: _projectDir, label: label, envVars: envVars, timeoutMs: timeoutMs ?? s_defaultPerTestTimeoutMs);
if (expectSuccess && result.exitCode != 0)
Expand All @@ -450,14 +450,14 @@ 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)
{
var dir = baseDir ?? _projectDir;
Assert.NotNull(dir);
return Path.Combine(dir!, "bin", config, targetFramework, BuildEnvironment.DefaultRuntimeIdentifier);
}

protected string GetObjDir(string config, string targetFramework=DefaultTargetFramework, string? baseDir=null)
protected string GetObjDir(string config, string targetFramework = DefaultTargetFramework, string? baseDir = null)
{
var dir = baseDir ?? _projectDir;
Assert.NotNull(dir);
Expand Down Expand Up @@ -489,7 +489,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path,
{
_testOutput.WriteLine($"Running {path} {args}");
_testOutput.WriteLine($"WorkingDirectory: {workingDir}");
StringBuilder outputBuilder = new ();
StringBuilder outputBuilder = new();
object syncObj = new();

var processStartInfo = new ProcessStartInfo
Expand Down Expand Up @@ -523,7 +523,7 @@ public static (int exitCode, string buildOutput) RunProcess(string path,
processStartInfo.RemoveEnvironmentVariables("MSBuildSDKsPath");
}

Process process = new ();
Process process = new();
process.StartInfo = processStartInfo;
process.EnableRaisingEvents = true;

Expand Down Expand Up @@ -596,7 +596,7 @@ void LogData(string label, string? message)
}
}

public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties=null, string? extraItems=null, string? atTheEnd=null)
public static string AddItemsPropertiesToProject(string projectFile, string? extraProperties = null, string? extraItems = null, string? atTheEnd = null)
{
if (extraProperties == null && extraItems == null && atTheEnd == null)
return projectFile;
Expand Down Expand Up @@ -643,7 +643,7 @@ private static string GetEnvironmentVariableOrDefault(string envVarName, string
return string.IsNullOrEmpty(value) ? defaultValue : value;
}

internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish=true)
internal BuildPaths GetBuildPaths(BuildArgs buildArgs, bool forPublish = true)
{
string objDir = GetObjDir(buildArgs.Config);
string bundleDir = Path.Combine(GetBinDir(baseDir: _projectDir, config: buildArgs.Config), "AppBundle");
Expand Down Expand Up @@ -686,25 +686,25 @@ public record BuildArgs(string ProjectName,
string ProjectFileContents,
string? ExtraBuildArgs);
public record BuildProduct(string ProjectDir, string LogFile, bool Result);
internal record FileStat (bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath);
internal record FileStat(bool Exists, DateTime LastWriteTimeUtc, long Length, string FullPath);
internal record BuildPaths(string ObjWasmDir, string ObjDir, string BinDir, string BundleDir);

public record BuildProjectOptions
(
Action? InitProject = null,
bool? DotnetWasmFromRuntimePack = null,
bool HasIcudt = true,
bool UseCache = true,
bool ExpectSuccess = true,
bool AssertAppBundle = true,
bool CreateProject = true,
bool Publish = true,
bool BuildOnlyAfterPublish = true,
bool HasV8Script = true,
string? Verbosity = null,
string? Label = null,
string? TargetFramework = null,
string? MainJS = null,
Action? InitProject = null,
bool? DotnetWasmFromRuntimePack = null,
bool HasIcudt = true,
bool UseCache = true,
bool ExpectSuccess = true,
bool AssertAppBundle = true,
bool CreateProject = true,
bool Publish = true,
bool BuildOnlyAfterPublish = true,
bool HasV8Script = true,
string? Verbosity = null,
string? Label = null,
string? TargetFramework = null,
string? MainJS = null,
IDictionary<string, string>? ExtraBuildEnvironmentVariables = null
);

Expand Down
Loading