-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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] Introduce <InvariantTimezone> build flag #87284
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cda65db
wip
pavelsavara 7544998
fix
pavelsavara 37b89ac
Merge branch 'main' into wasm_invariant_timezone
pavelsavara 75a14d1
WBT
pavelsavara d6aa491
Merge branch 'main' into wasm_invariant_timezone
pavelsavara 670b513
feedback
pavelsavara d0ae247
fix native build
pavelsavara d717645
feedback
pavelsavara 28bdd49
Merge branch 'main' into wasm_invariant_timezone
pavelsavara 30fc179
whitespace
pavelsavara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 @@ | ||
# Timezone Invariant Mode | ||
|
||
Author: [Pavel Savara](https://github.com/pavelsavara) | ||
|
||
It's currently only available for Browser OS | ||
|
||
- 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"}"; | ||
pavelsavara marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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
16 changes: 16 additions & 0 deletions
16
src/mono/wasm/testassets/Wasm.Buid.Tests.Programs/InvariantGlobalization.cs
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 @@ | ||
using System; | ||
using System.Globalization; | ||
|
||
// https://github.com/dotnet/runtime/blob/main/docs/design/features/globalization-invariant-mode.md#cultures-and-culture-data | ||
try | ||
{ | ||
CultureInfo culture = new ("es-ES", false); | ||
Console.WriteLine($"es-ES: Is Invariant LCID: {culture.LCID == CultureInfo.InvariantCulture.LCID}, NativeName: {culture.NativeName}"); | ||
} | ||
catch (CultureNotFoundException cnfe) | ||
{ | ||
Console.WriteLine($"Could not create es-ES culture: {cnfe.Message}"); | ||
} | ||
|
||
Console.WriteLine($"CurrentCulture.NativeName: {CultureInfo.CurrentCulture.NativeName}"); | ||
return 42; |
21 changes: 21 additions & 0 deletions
21
src/mono/wasm/testassets/Wasm.Buid.Tests.Programs/InvariantTimezone.cs
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,21 @@ | ||
using System; | ||
|
||
// https://github.com/dotnet/runtime/blob/main/docs/design/features/timezone-invariant-mode.md | ||
|
||
var timezonesCount = TimeZoneInfo.GetSystemTimeZones().Count; | ||
Console.WriteLine($"Found {timezonesCount} timezones in the TZ database"); | ||
|
||
TimeZoneInfo utc = TimeZoneInfo.FindSystemTimeZoneById("UTC"); | ||
Console.WriteLine($"{utc.DisplayName} BaseUtcOffset is {utc.BaseUtcOffset}"); | ||
|
||
try | ||
{ | ||
TimeZoneInfo tst = TimeZoneInfo.FindSystemTimeZoneById("Asia/Tokyo"); | ||
Console.WriteLine($"{tst.DisplayName} BaseUtcOffset is {tst.BaseUtcOffset}"); | ||
} | ||
catch (TimeZoneNotFoundException tznfe) | ||
{ | ||
Console.WriteLine($"Could not find Asia/Tokyo: {tznfe.Message}"); | ||
} | ||
|
||
return 42; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe specifically call out that it strips the tz data from the binary