Skip to content

Commit

Permalink
[browser] Make boot json file name configurable (#108281)
Browse files Browse the repository at this point in the history
Co-authored-by: Marek Fišera <[email protected]>
  • Loading branch information
jeromelaban and maraf authored Oct 8, 2024
1 parent 57feb11 commit 445660f
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<_WasmFingerprintAssets Condition="'$(_WasmFingerprintAssets)' == ''">false</_WasmFingerprintAssets>
<_WasmFingerprintDotnetJs>$(WasmFingerprintDotnetJs)</_WasmFingerprintDotnetJs>
<_WasmFingerprintDotnetJs Condition="'$(_WasmFingerprintDotnetJs)' == ''">false</_WasmFingerprintDotnetJs>
<_WasmBootConfigFileName>$(WasmBootConfigFileName)</_WasmBootConfigFileName>
<_WasmBootConfigFileName Condition="'$(_WasmBootConfigFileName)' == ''">blazor.boot.json</_WasmBootConfigFileName>
<_WasmPublishBootConfigFileName>publish.$(_WasmBootConfigFileName)</_WasmPublishBootConfigFileName>

<!-- Workaround for https://github.com/dotnet/sdk/issues/12114-->
<PublishDir Condition="'$(AppendRuntimeIdentifierToOutputPath)' != 'true' AND '$(PublishDir)' == '$(OutputPath)$(RuntimeIdentifier)\$(PublishDirName)\'">$(OutputPath)$(PublishDirName)\</PublishDir>
Expand Down Expand Up @@ -327,7 +330,7 @@ Copyright (c) .NET Foundation. All rights reserved.

<Target Name="_GenerateBuildWasmBootJson" DependsOnTargets="$(GenerateBuildWasmBootJsonDependsOn)">
<PropertyGroup>
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)$(_WasmBootConfigFileName)</_WasmBuildBootJsonPath>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -392,13 +395,13 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>

<PropertyGroup>
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json</_WasmBuildBootJsonPath>
<_WasmBuildBootJsonPath>$(IntermediateOutputPath)$(_WasmBootConfigFileName)</_WasmBuildBootJsonPath>
</PropertyGroup>

<ItemGroup>
<_BuildWasmBootJson
Include="$(_WasmBuildBootJsonPath)"
RelativePath="_framework/blazor.boot.json" />
RelativePath="_framework/$(_WasmBootConfigFileName)" />
</ItemGroup>

<DefineStaticWebAssets
Expand Down Expand Up @@ -589,8 +592,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<Target Name="_AddPublishWasmBootJsonToStaticWebAssets" DependsOnTargets="GeneratePublishWasmBootJson">
<ItemGroup>
<_PublishWasmBootJson
Include="$(IntermediateOutputPath)blazor.publish.boot.json"
RelativePath="_framework/blazor.boot.json" />
Include="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"
RelativePath="_framework/$(_WasmBootConfigFileName)" />
</ItemGroup>

<DefineStaticWebAssets
Expand Down Expand Up @@ -659,7 +662,7 @@ Copyright (c) .NET Foundation. All rights reserved.
DebugLevel="$(WasmDebugLevel)"
LinkerEnabled="$(PublishTrimmed)"
CacheBootResources="$(BlazorCacheBootResources)"
OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json"
OutputPath="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)"
ConfigurationFiles="@(_WasmPublishConfigFile)"
LazyLoadedAssemblies="@(BlazorWebAssemblyLazyLoad)"
InvariantGlobalization="$(InvariantGlobalization)"
Expand All @@ -679,7 +682,7 @@ Copyright (c) .NET Foundation. All rights reserved.
FingerprintAssets="$(_WasmFingerprintAssets)" />

<ItemGroup>
<FileWrites Include="$(IntermediateOutputPath)blazor.publish.boot.json" />
<FileWrites Include="$(IntermediateOutputPath)$(_WasmPublishBootConfigFileName)" />
</ItemGroup>

</Target>
Expand Down
4 changes: 2 additions & 2 deletions src/mono/wasm/Wasm.Build.Tests/AssertWasmSdkBundleOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public record AssertWasmSdkBundleOptions(
string BinFrameworkDir,
string? CustomIcuFile,
GlobalizationMode GlobalizationMode = GlobalizationMode.Sharded,
string BootJsonFileName = "blazor.boot.json",
string BootConfigFileName = "blazor.boot.json",
NativeFilesType ExpectedFileType = NativeFilesType.FromRuntimePack,
RuntimeVariant RuntimeType = RuntimeVariant.SingleThreaded,
bool ExpectFingerprintOnDotnetJs = false,
Expand All @@ -29,7 +29,7 @@ public record AssertWasmSdkBundleOptions(
GlobalizationMode: GlobalizationMode,
ExpectedFileType: ExpectedFileType,
RuntimeType: RuntimeType,
BootJsonFileName: BootJsonFileName,
BootJsonFileName: BootConfigFileName,
ExpectFingerprintOnDotnetJs: ExpectFingerprintOnDotnetJs,
ExpectSymbolsFile: ExpectSymbolsFile,
AssertIcuAssets: AssertIcuAssets,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record BlazorBuildOptions
string Config,
NativeFilesType ExpectedFileType = NativeFilesType.FromRuntimePack,
string TargetFramework = BuildTestBase.DefaultTargetFrameworkForBlazor,
string BootConfigFileName = "blazor.boot.json",
bool IsPublish = false,
bool WarnAsError = true,
bool ExpectSuccess = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public BlazorWasmProjectProvider(ITestOutputHelper _testOutput, string? _project
public void AssertBundle(BlazorBuildOptions options)
=> AssertBundle(new AssertWasmSdkBundleOptions(
Config: options.Config,
BootConfigFileName: options.BootConfigFileName,
IsPublish: options.IsPublish,
TargetFramework: options.TargetFramework,
BinFrameworkDir: options.BinFrameworkDir ?? FindBinFrameworkDir(options.Config, options.IsPublish, options.TargetFramework),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected void BuildProject(
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
bool assertAppBundle = true,
bool expectSuccess = true,
string bootConfigFileName = "blazor.boot.json",
params string[] extraArgs)
{
(CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(
Expand All @@ -68,6 +69,7 @@ protected void BuildProject(
BinFrameworkDir: binFrameworkDir,
RuntimeType: runtimeType,
AssertAppBundle: assertAppBundle,
BootConfigFileName: bootConfigFileName,
ExpectSuccess: expectSuccess), extraArgs);
if (expectSuccess)
{
Expand All @@ -83,12 +85,14 @@ protected void PublishProject(
string configuration,
RuntimeVariant runtimeType = RuntimeVariant.SingleThreaded,
bool assertAppBundle = true,
string bootConfigFileName = "blazor.boot.json",
params string[] extraArgs)
{
(CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(
Id: Id,
Config: configuration,
RuntimeType: runtimeType,
BootConfigFileName: bootConfigFileName,
AssertAppBundle: assertAppBundle), extraArgs);
result.EnsureSuccessful();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,33 @@ public async Task OutErrOverrideWorks()
"Emscripten err override doesn't work"
);
}

[Theory]
[InlineData("Release", true)]
[InlineData("Release", false)]
public async Task OverrideBootConfigName(string config, bool isPublish)
{
CopyTestAsset("WasmBasicTestApp", $"OverrideBootConfigName", "App");

string[] extraArgs = ["-p:WasmBootConfigFileName=boot.json"];
if (isPublish)
PublishProject(config, bootConfigFileName: "boot.json", extraArgs: extraArgs);
else
BuildProject(config, bootConfigFileName: "boot.json", extraArgs: extraArgs);

var runOptions = new RunOptions(
Configuration: config,
TestScenario: "OverrideBootConfigName"
);
var result = await (isPublish
? RunSdkStyleAppForPublish(runOptions)
: RunSdkStyleAppForBuild(runOptions)
);

Assert.Collection(
result.TestOutput,
m => Assert.Equal("ConfigSrc: boot.json", m),
m => Assert.Equal("Managed code has run", m)
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Runtime.InteropServices.JavaScript;

public partial class OverrideBootConfigNameTest
{
[JSExport]
public static void Run()
{
TestOutput.WriteLine("Managed code has run");
}
}
8 changes: 8 additions & 0 deletions src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ switch (testCase) {
}
})
break;
case "OverrideBootConfigName":
dotnet.withConfigSrc("boot.json");
break;
}

const { setModuleImports, Module, getAssemblyExports, getConfig, INTERNAL } = await dotnet.create();
Expand Down Expand Up @@ -234,6 +237,11 @@ try {
let exit_code = ret == 42 ? 0 : 1;
exit(exit_code);
break;
case "OverrideBootConfigName":
testOutput("ConfigSrc: " + Module.configSrc);
exports.OverrideBootConfigNameTest.Run();
exit(0);
break;
default:
console.error(`Unknown test case: ${testCase}`);
exit(3);
Expand Down

0 comments on commit 445660f

Please sign in to comment.