Skip to content

Commit

Permalink
[HybridGlobalization] Include all globalization symbols (dotnet#96684)
Browse files Browse the repository at this point in the history
* Include all symbols for Globalization
Co-authored-by: Steve Pfister <[email protected]>
  • Loading branch information
mkhamoyan authored Jan 10, 2024
1 parent adfae48 commit 72db600
Show file tree
Hide file tree
Showing 15 changed files with 318 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,10 @@ public static string GetDistroVersionString()
public static bool IsNotInvariantGlobalization => !IsInvariantGlobalization;
public static bool IsNotHybridGlobalization => !IsHybridGlobalization;
public static bool IsNotHybridGlobalizationOnOSX => !IsHybridGlobalizationOnOSX;
public static bool IsIcuGlobalization => ICUVersion > new Version(0, 0, 0, 0);

// HG on apple platforms implies ICU
public static bool IsIcuGlobalization => !IsInvariantGlobalization && (IsHybridGlobalizationOnOSX || ICUVersion > new Version(0, 0, 0, 0));

public static bool IsIcuGlobalizationAndNotHybridOnBrowser => IsIcuGlobalization && IsNotHybridGlobalizationOnBrowser;
public static bool IsIcuGlobalizationAndNotHybrid => IsIcuGlobalization && IsNotHybridGlobalization;
public static bool IsNlsGlobalization => IsNotInvariantGlobalization && !IsIcuGlobalization && !IsHybridGlobalization;
Expand Down Expand Up @@ -416,22 +419,26 @@ public static bool IsSubstAvailable
private static Version GetICUVersion()
{
int version = 0;
try
// When HG on Apple platforms, our ICU lib is not loaded
if (IsNotHybridGlobalizationOnOSX)
{
Type interopGlobalization = Type.GetType("Interop+Globalization, System.Private.CoreLib");
if (interopGlobalization != null)
try
{
MethodInfo methodInfo = interopGlobalization.GetMethod("GetICUVersion", BindingFlags.NonPublic | BindingFlags.Static);
if (methodInfo != null)
Type interopGlobalization = Type.GetType("Interop+Globalization, System.Private.CoreLib");
if (interopGlobalization != null)
{
// Ensure that ICU has been loaded
GC.KeepAlive(System.Globalization.CultureInfo.InstalledUICulture);
MethodInfo methodInfo = interopGlobalization.GetMethod("GetICUVersion", BindingFlags.NonPublic | BindingFlags.Static);
if (methodInfo != null)
{
// Ensure that ICU has been loaded
GC.KeepAlive(System.Globalization.CultureInfo.InstalledUICulture);

version = (int)methodInfo.Invoke(null, null);
version = (int)methodInfo.Invoke(null, null);
}
}
}
catch { }
}
catch { }

return new Version(version >> 24,
(version >> 16) & 0xFF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace System.Globalization.Tests
{
public class IcuAppLocalTests
{
private static bool SupportsIcuPackageDownload => RemoteExecutor.IsSupported &&
private static bool SupportsIcuPackageDownload => PlatformDetection.IsNotHybridGlobalizationOnOSX && RemoteExecutor.IsSupported &&
((PlatformDetection.IsWindows && !PlatformDetection.IsArmProcess) ||
(PlatformDetection.IsLinux && (PlatformDetection.IsX64Process || PlatformDetection.IsArm64Process) &&
!PlatformDetection.IsAlpine && !PlatformDetection.IsLinuxBionic));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static void Casing_Invariant(int original, int upper, int lower)
[InlineData('\u0131', '\u0131', '\u0131')] // U+0131 LATIN SMALL LETTER DOTLESS I
[InlineData(0x10400, 0x10400, 0x10428)] // U+10400 DESERET CAPITAL LETTER LONG I
[InlineData(0x10428, 0x10400, 0x10428)] // U+10428 DESERET SMALL LETTER LONG I
[ActiveIssue("https://github.com/dotnet/runtime/issues/95338", typeof(PlatformDetection), nameof(PlatformDetection.IsHybridGlobalizationOnOSX))]
public static void ICU_Casing_Invariant(int original, int upper, int lower)
{
var rune = new Rune(original);
Expand Down
7 changes: 7 additions & 0 deletions src/mono/mono/mini/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM
)
endif()

if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
set(icu_shim_sources_base
${icu_shim_sources_base}
pal_placeholders.c
)
endif()

addprefix(icu_shim_sources "${ICU_SHIM_PATH}" "${icu_shim_sources_base}")

if (TARGET_DARWIN)
Expand Down
7 changes: 7 additions & 0 deletions src/native/libs/System.Globalization.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CM
)
endif()

if (CLR_CMAKE_TARGET_MACCATALYST OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
set(NATIVEGLOBALIZATION_SOURCES
${NATIVEGLOBALIZATION_SOURCES}
pal_placeholders.c
)
endif()

if (NOT CLR_CMAKE_TARGET_MACCATALYST AND NOT CLR_CMAKE_TARGET_IOS AND NOT CLR_CMAKE_TARGET_TVOS AND DEFINED CMAKE_ICU_DIR)
include_directories(${CMAKE_ICU_DIR}/include)
link_libraries(${CMAKE_ICU_DIR}/lib/libicuuc.a ${CMAKE_ICU_DIR}/lib/libicui18n.a ${CMAKE_ICU_DIR}/lib/libicudata.a)
Expand Down
3 changes: 1 addition & 2 deletions src/native/libs/System.Globalization.Native/entrypoints.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ typedef uint16_t UChar;

static const Entry s_globalizationNative[] =
{
#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
DllImportEntry(GlobalizationNative_ChangeCase)
DllImportEntry(GlobalizationNative_ChangeCaseInvariant)
DllImportEntry(GlobalizationNative_ChangeCaseTurkish)
Expand Down Expand Up @@ -56,7 +55,7 @@ static const Entry s_globalizationNative[] =
DllImportEntry(GlobalizationNative_NormalizeString)
DllImportEntry(GlobalizationNative_StartsWith)
DllImportEntry(GlobalizationNative_WindowsIdToIanaId)
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
DllImportEntry(GlobalizationNative_ChangeCaseInvariantNative)
DllImportEntry(GlobalizationNative_ChangeCaseNative)
DllImportEntry(GlobalizationNative_CompareStringNative)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ typedef enum
// the function pointer definition for the callback used in EnumCalendarInfo
typedef void (PAL_CALLBACK_CALLTYPE *EnumCalendarInfoCallback)(const UChar*, const void*);

#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_GetCalendars(const UChar* localeName,
CalendarId* calendars,
int32_t calendarsCapacity);
Expand All @@ -102,7 +101,7 @@ PALEXPORT int32_t GlobalizationNative_GetJapaneseEraStartDate(int32_t era,
int32_t* startYear,
int32_t* startMonth,
int32_t* startDay);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT const char* GlobalizationNative_GetCalendarInfoNative(const char* localeName,
CalendarId calendarId,
CalendarDataType dataType);
Expand Down
3 changes: 1 addition & 2 deletions src/native/libs/System.Globalization.Native/pal_casing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

PALEXPORT void GlobalizationNative_InitOrdinalCasingPage(int32_t pageNumber, UChar* pTarget);

#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT void GlobalizationNative_ChangeCase(const UChar* lpSrc,
int32_t cwSrcLength,
UChar* lpDst,
Expand All @@ -24,7 +23,7 @@ PALEXPORT void GlobalizationNative_ChangeCaseTurkish(const UChar* lpSrc,
UChar* lpDst,
int32_t cwDstLength,
int32_t bToUpper);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName,
int32_t lNameLength,
const uint16_t* lpSrc,
Expand Down
3 changes: 1 addition & 2 deletions src/native/libs/System.Globalization.Native/pal_collation.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ typedef struct _Range {
int32_t length;
} Range;

#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT ResultCode GlobalizationNative_GetSortHandle(const char* lpLocaleName, SortHandle** ppSortHandle);

PALEXPORT void GlobalizationNative_CloseSortHandle(SortHandle* pSortHandle);
Expand Down Expand Up @@ -66,7 +65,7 @@ PALEXPORT int32_t GlobalizationNative_GetSortKey(SortHandle* pSortHandle,
uint8_t* sortKey,
int32_t cbSortKeyLength,
int32_t options);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName,
int32_t lNameLength,
const uint16_t* lpTarget,
Expand Down
3 changes: 1 addition & 2 deletions src/native/libs/System.Globalization.Native/pal_locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

#include "pal_compiler.h"

#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_GetLocales(UChar *value, int32_t valueLength);

PALEXPORT int32_t GlobalizationNative_GetLocaleName(const UChar* localeName, UChar* value, int32_t valueLength);
Expand All @@ -17,7 +16,7 @@ PALEXPORT int32_t GlobalizationNative_IsPredefinedLocale(const UChar* localeName
PALEXPORT int32_t GlobalizationNative_GetLocaleTimeFormat(const UChar* localeName,
int shortFormat, UChar* value,
int32_t valueLength);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))

PALEXPORT const char* GlobalizationNative_GetDefaultLocaleNameNative(void);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ typedef enum
WeekRule_FirstFullWeek = 1,
WeekRule_FirstFourDayWeek = 2
} CalendarWeekRule;
#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_GetLocaleInfoInt(const UChar* localeName,
LocaleNumberData localeNumberData,
int32_t* value);
Expand All @@ -43,7 +42,7 @@ PALEXPORT int32_t GlobalizationNative_GetLocaleInfoGroupingSizes(const UChar* lo
LocaleNumberData localeGroupingData,
int32_t* primaryGroupSize,
int32_t* secondaryGroupSize);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName,
LocaleNumberData localeNumberData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,12 @@ typedef enum
LocaleString_PercentSymbol = 0x00000076,
LocaleString_PerMilleSymbol = 0x00000077
} LocaleStringData;
#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_GetLocaleInfoString(const UChar* localeName,
LocaleStringData localeStringData,
UChar* value,
int32_t valueLength,
const UChar* uiLocaleName);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT const char* GlobalizationNative_GetLocaleInfoStringNative(const char* localeName, LocaleStringData localeStringData, const char* currentUILocaleName);
#endif

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ typedef enum
FormKC = 0x5,
FormKD = 0x6
} NormalizationForm;
#if !defined(__APPLE__) || (defined(__APPLE__) && !(TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_IsNormalized(NormalizationForm normalizationForm,
const UChar* lpStr,
int32_t cwStrLength);
Expand All @@ -27,7 +26,7 @@ PALEXPORT int32_t GlobalizationNative_NormalizeString(NormalizationForm normaliz
int32_t cwSrcLength,
UChar* lpDst,
int32_t cwDstLength);
#else
#if (defined(__APPLE__) && (TARGET_MACCATALYST || TARGET_IOS || TARGET_TVOS))
PALEXPORT int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationForm,
const uint16_t* lpStr,
int32_t cwStrLength);
Expand Down
Loading

0 comments on commit 72db600

Please sign in to comment.