Skip to content

Commit f450f49

Browse files
authored
Support relative path for ICU_DAT_FILE_PATH on iOS/tvOS/Catalyst (#87813)
We consider it relative to the app bundle root. Required for dotnet/macios#17877 and NativeAOT scenarios.
1 parent af18709 commit f450f49

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/native/libs/System.Globalization.Native/pal_icushim_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ FOR_ALL_ICU_FUNCTIONS
341341
#define ucal_getTimeZoneIDForWindowsID_ptr ucal_getTimeZoneIDForWindowsID
342342

343343
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
344+
const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path);
344345
const char* GlobalizationNative_GetICUDataPathFallback(void);
345346
#endif
346347

src/native/libs/System.Globalization.Native/pal_icushim_static.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,14 @@ int32_t
171171
GlobalizationNative_LoadICUData(const char* path)
172172
{
173173
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
174+
if (path && path[0] != '/')
175+
{
176+
// if the path is relative, prepend the app bundle root
177+
path = GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(path);
178+
}
174179
if (!path)
175180
{
176-
// fallback to icudt.dat in the app bundle root in case the path isn't set
181+
// fallback to icudt.dat in the app bundle resources in case the path isn't set
177182
path = GlobalizationNative_GetICUDataPathFallback();
178183
}
179184
#endif

src/native/libs/System.Globalization.Native/pal_locale.m

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import <Foundation/Foundation.h>
1010
#import <Foundation/NSFormatter.h>
1111

12-
char* DetectDefaultAppleLocaleName()
12+
char* DetectDefaultAppleLocaleName(void)
1313
{
1414
NSLocale *currentLocale = [NSLocale currentLocale];
1515
NSString *localeName = @"";
@@ -571,9 +571,17 @@ Returns time format information (in native format, it needs to be converted to .
571571
#endif
572572

573573
#if defined(TARGET_MACCATALYST) || defined(TARGET_IOS) || defined(TARGET_TVOS)
574+
const char* GlobalizationNative_GetICUDataPathRelativeToAppBundleRoot(const char* path)
575+
{
576+
NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
577+
NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]];
578+
579+
return strdup([dataPath UTF8String]);
580+
}
581+
574582
const char* GlobalizationNative_GetICUDataPathFallback(void)
575583
{
576-
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"];
577-
return strdup([bundlePath UTF8String]);
584+
NSString *dataPath = [[NSBundle mainBundle] pathForResource:@"icudt" ofType:@"dat"];
585+
return strdup([dataPath UTF8String]);
578586
}
579587
#endif

0 commit comments

Comments
 (0)