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

[dotnet] Add ICU support for iOS builds #11163

Merged
merged 5 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions dotnet/targets/Xamarin.Shared.Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@
<EnableUnsafeUTF7Encoding Condition="'$(EnableUnsafeUTF7Encoding)' == ''">false</EnableUnsafeUTF7Encoding>
<EventSourceSupport Condition="'$(EventSourceSupport)' == ''">false</EventSourceSupport>
<HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport>
<!-- .NET only supports invariant globalization for Apple platforms for now: https://github.com/xamarin/xamarin-macios/issues/8906 -->
<InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">true</InvariantGlobalization>
<!-- tvOS support blocked by https://github.com/dotnet/runtime/issues/48508 (see xamarin_bridge_vm_initialize in monovm-bridge.m) -->
<InvariantGlobalization Condition="'$(_PlatformName)' == 'tvOS' And '$(InvariantGlobalization)' == ''">true</InvariantGlobalization>
<StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport>
<UseSystemResourceKeys Condition="'$(UseSystemResourceKeys)' == ''">true</UseSystemResourceKeys>
<UseNativeHttpHandler Condition="'$(_PlatformName)' != 'macOS' And '$(UseNativeHttpHandler)' == ''">true</UseNativeHttpHandler>
Expand Down Expand Up @@ -245,6 +245,7 @@
@(_XamarinFrameworkAssemblies -> 'FrameworkAssembly=%(Filename)')
Interpreter=$(MtouchInterpreter)
IntermediateLinkDir=$(IntermediateLinkDir)
InvariantGlobalization=$(InvariantGlobalization)
ItemsDirectory=$(_LinkerItemsDirectory)
IsSimulatorBuild=$(_SdkIsSimulator)
LinkMode=$(_LinkMode)
Expand Down Expand Up @@ -696,6 +697,10 @@
Update="@(ResolvedFileToPublish)"
RelativePath="$([MSBuild]::MakeRelative($(MSBuildProjectDirectory)$(PublishDir),$(_DylibPublishDir)))%(Filename)%(Extension)"
Condition="'%(Extension)' == '.dylib'" />
<ResolvedFileToPublish
Update="@(ResolvedFileToPublish)"
RelativePath="$([MSBuild]::MakeRelative($(MSBuildProjectDirectory)$(PublishDir),$(_AssemblyPublishDir)))%(Filename)%(Extension)"
Condition="'$(_PlatformName)' != 'macOS' And '$(InvariantGlobalization)' != 'true' And '%(Filename)%(Extension)' == 'icudt.dat'" />
</ItemGroup>
</Target>

Expand Down
2 changes: 2 additions & 0 deletions runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -2437,10 +2437,12 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;
const char *propertyKeys[] = {
"APP_PATHS",
"PINVOKE_OVERRIDE",
"ICU_DAT_FILE_PATH",
};
const char *propertyValues[] = {
xamarin_get_bundle_path (),
pinvokeOverride,
"icudt.dat",
};
static_assert (sizeof (propertyKeys) == sizeof (propertyValues), "The number of keys and values must be the same.");

Expand Down
4 changes: 0 additions & 4 deletions tests/EmbeddedResources/ResourcesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,10 @@ public void Embedded ()
Assert.AreEqual ("Welcome", manager.GetString ("String1", new CultureInfo ("en")), "en");
Assert.AreEqual ("G'day", manager.GetString ("String1", new CultureInfo ("en-AU")), "en-AU");
Assert.AreEqual ("Willkommen", manager.GetString ("String1", new CultureInfo ("de")), "de");
#if !NET // https://github.com/xamarin/xamarin-macios/issues/8906
Assert.AreEqual ("Willkommen", manager.GetString ("String1", new CultureInfo ("de-DE")), "de-DE");
#endif
Assert.AreEqual ("Bienvenido", manager.GetString ("String1", new CultureInfo ("es")), "es");
#if !NET // https://github.com/xamarin/xamarin-macios/issues/8906
Assert.AreEqual ("Bienvenido", manager.GetString ("String1", new CultureInfo ("es-AR")), "es-AR");
Assert.AreEqual ("Bienvenido", manager.GetString ("String1", new CultureInfo ("es-ES")), "es-ES");
#endif
}
}
}
2 changes: 2 additions & 0 deletions tests/common/DotNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public static void CompareApps (string old_app, string new_app)

var filename = Path.GetFileName (v);
switch (filename) {
case "icudt.dat":
return false; // ICU data file only present on .NET
case "runtime-options.plist":
return false; // the .NET runtime will deal with selecting the http handler, no need for us to do anything
}
Expand Down
3 changes: 0 additions & 3 deletions tests/monotouch-test/Foundation/LocaleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public void FromLocaleIdentifier ()
Assert.That (NSLocale.FromLocaleIdentifier (ident).Identifier, Is.EqualTo (ident), "FromLocaleIdentifier");
}

#if NET
[Ignore ("No globalization data yet - https://github.com/xamarin/xamarin-macios/issues/8906")]
#endif
[Test]
public void InitRegionInfo ()
{
Expand Down
4 changes: 4 additions & 0 deletions tools/dotnet-linker/LinkerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class LinkerConfiguration {
public Version DeploymentTarget { get; private set; }
public HashSet<string> FrameworkAssemblies { get; private set; } = new HashSet<string> ();
public string IntermediateLinkDir { get; private set; }
public bool InvariantGlobalization { get; private set; }
public string ItemsDirectory { get; private set; }
public bool IsSimulatorBuild { get; private set; }
public LinkMode LinkMode => Application.LinkMode;
Expand Down Expand Up @@ -228,6 +229,9 @@ public static LinkerConfiguration GetInstance (LinkContext context, bool createI
throw new InvalidOperationException ($"Invalid XamarinRuntime '{value}' in {linker_file}");
Application.XamarinRuntime = rv;
break;
case "InvariantGlobalization":
InvariantGlobalization = string.Equals ("true", value, StringComparison.OrdinalIgnoreCase);
break;
default:
throw new InvalidOperationException ($"Unknown key '{key}' in {linker_file}");
}
Expand Down
4 changes: 3 additions & 1 deletion tools/dotnet-linker/Steps/GenerateMainStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ protected override void TryEndProcess ()
contents.AppendLine ("#include <stdlib.h>");
contents.AppendLine ("static void xamarin_initialize_dotnet ()");
contents.AppendLine ("{");
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1); // https://github.com/xamarin/xamarin-macios/issues/8906");
if (Configuration.InvariantGlobalization) {
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1);");
}
contents.AppendLine ("}");
contents.AppendLine ();

Expand Down