-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm] Introduce <InvariantTimezone> build flag (#87284)
- Loading branch information
1 parent
e80ef86
commit d388585
Showing
19 changed files
with
220 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Timezone Invariant Mode | ||
|
||
Author: [Pavel Savara](https://github.com/pavelsavara) | ||
|
||
It's currently only available for Browser OS. | ||
The timezone database is not part of the browser environment (as opposed to other operating systems). | ||
Therefore dotnet bundles the timezone database as binary as part of the runtime. | ||
That makes download size larger and application startup slower. | ||
If your application doesn't need to work with time zone information, you could use this feature to make the runtime about 200KB smaller. | ||
|
||
You enable it in project file: | ||
```xml | ||
<PropertyGroup> | ||
<InvariantTimezone>true</InvariantTimezone> | ||
</PropertyGroup> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
#nullable enable | ||
|
||
namespace Wasm.Build.Tests | ||
{ | ||
public class InvariantTimezoneTests : BuildTestBase | ||
{ | ||
public InvariantTimezoneTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) | ||
: base(output, buildContext) | ||
{ | ||
} | ||
|
||
public static IEnumerable<object?[]> InvariantTimezoneTestData(bool aot, RunHost host) | ||
=> ConfigWithAOTData(aot) | ||
.Multiply( | ||
new object?[] { null }, | ||
new object?[] { false }, | ||
new object?[] { true }) | ||
.WithRunHosts(host) | ||
.UnwrapItemsAsArrays(); | ||
|
||
[Theory] | ||
[MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ false, RunHost.All })] | ||
[MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ true, RunHost.All })] | ||
public void AOT_InvariantTimezone(BuildArgs buildArgs, bool? invariantTimezone, RunHost host, string id) | ||
=> TestInvariantTimezone(buildArgs, invariantTimezone, host, id); | ||
|
||
[Theory] | ||
[MemberData(nameof(InvariantTimezoneTestData), parameters: new object[] { /*aot*/ false, RunHost.All })] | ||
public void RelinkingWithoutAOT(BuildArgs buildArgs, bool? invariantTimezone, RunHost host, string id) | ||
=> TestInvariantTimezone(buildArgs, invariantTimezone, host, id, | ||
extraProperties: "<WasmBuildNative>true</WasmBuildNative>", | ||
dotnetWasmFromRuntimePack: false); | ||
|
||
private void TestInvariantTimezone(BuildArgs buildArgs, bool? invariantTimezone, | ||
RunHost host, string id, string extraProperties="", bool? dotnetWasmFromRuntimePack=null) | ||
{ | ||
string projectName = $"invariant_{invariantTimezone?.ToString() ?? "unset"}"; | ||
if (invariantTimezone != null) | ||
extraProperties = $"{extraProperties}<InvariantTimezone>{invariantTimezone}</InvariantTimezone>"; | ||
|
||
buildArgs = buildArgs with { ProjectName = projectName }; | ||
buildArgs = ExpandBuildArgs(buildArgs, extraProperties); | ||
|
||
if (dotnetWasmFromRuntimePack == null) | ||
dotnetWasmFromRuntimePack = !(buildArgs.AOT || buildArgs.Config == "Release"); | ||
|
||
BuildProject(buildArgs, | ||
id: id, | ||
new BuildProjectOptions( | ||
InitProject: () => File.Copy(Path.Combine(BuildEnvironment.TestAssetsPath, "Wasm.Buid.Tests.Programs", "InvariantTimezone.cs"), Path.Combine(_projectDir!, "Program.cs")), | ||
DotnetWasmFromRuntimePack: dotnetWasmFromRuntimePack)); | ||
|
||
string output = RunAndTestWasmApp(buildArgs, expectedExitCode: 42, host: host, id: id); | ||
Assert.Contains("UTC BaseUtcOffset is 0", output); | ||
if (invariantTimezone == true) | ||
{ | ||
Assert.Contains("Could not find Asia/Tokyo", output); | ||
} | ||
else | ||
{ | ||
Assert.Contains("Asia/Tokyo BaseUtcOffset is 09:00:00", output); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.