From f2d4f2b6d51641ac43412eb70bae9c19d4b11ab8 Mon Sep 17 00:00:00 2001 From: Felix Deimel Date: Fri, 14 Jul 2023 09:31:10 +0200 Subject: [PATCH] Set icudt.dat file path at runtime when loading library --- .../Collectors/TypeCollector.cs | 3 +- .../Beyond.NET.Sample.Native.csproj | 11 ++-- .../project.pbxproj | 18 +++++++ .../project.pbxproj | 4 -- .../Source/LibraryInit/__LibraryInit.m | 52 +++++++++++++++++++ 5 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 Samples/Beyond.NET.Sample.Swift/Source/LibraryInit/__LibraryInit.m diff --git a/Generator/Beyond.NET.CodeGenerator/Collectors/TypeCollector.cs b/Generator/Beyond.NET.CodeGenerator/Collectors/TypeCollector.cs index 93e2105d..ac7c70ac 100644 --- a/Generator/Beyond.NET.CodeGenerator/Collectors/TypeCollector.cs +++ b/Generator/Beyond.NET.CodeGenerator/Collectors/TypeCollector.cs @@ -37,7 +37,8 @@ public class TypeCollector typeof(System.Enum), typeof(System.Array), typeof(byte[]), - typeof(string[]) + typeof(string[]), + typeof(System.AppContext) }; private static readonly Type[] UNSUPPORTED_TYPES = new [] { diff --git a/Samples/Beyond.NET.Sample.Native/Beyond.NET.Sample.Native.csproj b/Samples/Beyond.NET.Sample.Native/Beyond.NET.Sample.Native.csproj index 0748e6d2..01a64bc9 100644 --- a/Samples/Beyond.NET.Sample.Native/Beyond.NET.Sample.Native.csproj +++ b/Samples/Beyond.NET.Sample.Native/Beyond.NET.Sample.Native.csproj @@ -35,14 +35,15 @@ - + + - - + - + diff --git a/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwift.xcodeproj/project.pbxproj b/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwift.xcodeproj/project.pbxproj index d47e815a..aa105307 100644 --- a/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwift.xcodeproj/project.pbxproj +++ b/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwift.xcodeproj/project.pbxproj @@ -91,6 +91,8 @@ E7C8CF0B29C1FE5800C4230F /* SystemArrayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C8CF0A29C1FE5800C4230F /* SystemArrayTests.swift */; }; E7C8CF0D29C2139B00C4230F /* PersonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C8CF0C29C2139B00C4230F /* PersonTests.swift */; }; E7C8CF0F29C2180200C4230F /* AnimalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7C8CF0E29C2180200C4230F /* AnimalTests.swift */; }; + E7CB97C62A612A8A0086CF43 /* icudt.dat in Resources */ = {isa = PBXBuildFile; fileRef = E71E42282A6030760075FE5F /* icudt.dat */; }; + E7CB97CE2A612BE30086CF43 /* __LibraryInit.m in Sources */ = {isa = PBXBuildFile; fileRef = E7CB97CC2A612BE30086CF43 /* __LibraryInit.m */; }; E7EB338629C8879100392F3D /* AddressTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7EB338529C8879100392F3D /* AddressTests.swift */; }; E7ED7A1829D35DF4008C96E0 /* SystemVersionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7ED7A1729D35DF4008C96E0 /* SystemVersionTests.swift */; }; E7ED7A1A29D445C8008C96E0 /* SystemActionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E7ED7A1929D445C8008C96E0 /* SystemActionTests.swift */; }; @@ -198,6 +200,7 @@ E7C8CF0A29C1FE5800C4230F /* SystemArrayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SystemArrayTests.swift; sourceTree = ""; }; E7C8CF0C29C2139B00C4230F /* PersonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersonTests.swift; sourceTree = ""; }; E7C8CF0E29C2180200C4230F /* AnimalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnimalTests.swift; sourceTree = ""; }; + E7CB97CC2A612BE30086CF43 /* __LibraryInit.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = __LibraryInit.m; sourceTree = ""; }; E7E7491B2A026A1C009590A8 /* Generated_C.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Generated_C.h; path = ../../Generated/Generated_C.h; sourceTree = ""; }; E7E7491C2A026A1C009590A8 /* Generated_Swift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Generated_Swift.swift; path = ../../Generated/Generated_Swift.swift; sourceTree = ""; }; E7EB338529C8879100392F3D /* AddressTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressTests.swift; sourceTree = ""; }; @@ -261,6 +264,7 @@ children = ( E7C8CF0129C1FA6C00C4230F /* Tests */, E7E749192A0269AB009590A8 /* Playground */, + E7CB97CA2A612BC10086CF43 /* LibraryInit */, E7E7491A2A0269DD009590A8 /* Generated */, E70D116029BF9F2600B4E738 /* BeyondNETSampleSwift.h */, ); @@ -383,6 +387,14 @@ path = TestClasses; sourceTree = ""; }; + E7CB97CA2A612BC10086CF43 /* LibraryInit */ = { + isa = PBXGroup; + children = ( + E7CB97CC2A612BE30086CF43 /* __LibraryInit.m */, + ); + path = LibraryInit; + sourceTree = ""; + }; E7E749192A0269AB009590A8 /* Playground */ = { isa = PBXGroup; children = ( @@ -468,6 +480,7 @@ }; E71E41E52A60030F0075FE5F = { CreatedOnToolsVersion = 14.3.1; + LastSwiftMigration = 1430; }; E7B491D32A5FDBD900A7C75D = { CreatedOnToolsVersion = 14.3.1; @@ -507,6 +520,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + E7CB97C62A612A8A0086CF43 /* icudt.dat in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -620,6 +634,7 @@ files = ( E71E41F62A6003F30075FE5F /* Generated_Swift.swift in Sources */, E71E41FB2A6010970075FE5F /* SwiftSyntaxPlayground.swift in Sources */, + E7CB97CE2A612BE30086CF43 /* __LibraryInit.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -808,6 +823,7 @@ E71E41EA2A60030F0075FE5F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; @@ -837,6 +853,7 @@ SKIP_INSTALL = YES; SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx"; SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -845,6 +862,7 @@ E71E41EB2A60030F0075FE5F /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEFINES_MODULE = YES; diff --git a/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwiftiOSApp/BeyondNETSampleSwiftiOSApp.xcodeproj/project.pbxproj b/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwiftiOSApp/BeyondNETSampleSwiftiOSApp.xcodeproj/project.pbxproj index 504cd733..9aa2f38c 100644 --- a/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwiftiOSApp/BeyondNETSampleSwiftiOSApp.xcodeproj/project.pbxproj +++ b/Samples/Beyond.NET.Sample.Swift/BeyondNETSampleSwiftiOSApp/BeyondNETSampleSwiftiOSApp.xcodeproj/project.pbxproj @@ -12,7 +12,6 @@ E71E42112A6015C90075FE5F /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E71E42102A6015C90075FE5F /* Assets.xcassets */; }; E71E42242A6017710075FE5F /* libBeyondDotNETSampleNative.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = E71E42232A6017710075FE5F /* libBeyondDotNETSampleNative.xcframework */; }; E71E42252A6017710075FE5F /* libBeyondDotNETSampleNative.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E71E42232A6017710075FE5F /* libBeyondDotNETSampleNative.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; - E71E422E2A6032A30075FE5F /* icudt.dat in Resources */ = {isa = PBXBuildFile; fileRef = E71E422A2A6030820075FE5F /* icudt.dat */; }; E71E424B2A603E030075FE5F /* BeyondNETSampleSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E71E424A2A603E030075FE5F /* BeyondNETSampleSwift.framework */; }; E71E424C2A603E030075FE5F /* BeyondNETSampleSwift.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = E71E424A2A603E030075FE5F /* BeyondNETSampleSwift.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ @@ -38,7 +37,6 @@ E71E420E2A6015C80075FE5F /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; E71E42102A6015C90075FE5F /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; E71E42232A6017710075FE5F /* libBeyondDotNETSampleNative.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = libBeyondDotNETSampleNative.xcframework; path = ../libBeyondDotNETSampleNative.xcframework; sourceTree = ""; }; - E71E422A2A6030820075FE5F /* icudt.dat */ = {isa = PBXFileReference; lastKnownFileType = file; name = icudt.dat; path = ../icudt.dat; sourceTree = ""; }; E71E424A2A603E030075FE5F /* BeyondNETSampleSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = BeyondNETSampleSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -58,7 +56,6 @@ E71E42002A6015C80075FE5F = { isa = PBXGroup; children = ( - E71E422A2A6030820075FE5F /* icudt.dat */, E71E420B2A6015C80075FE5F /* Source */, E71E420A2A6015C80075FE5F /* Products */, E71E421A2A6016040075FE5F /* Frameworks */, @@ -152,7 +149,6 @@ buildActionMask = 2147483647; files = ( E71E42112A6015C90075FE5F /* Assets.xcassets in Resources */, - E71E422E2A6032A30075FE5F /* icudt.dat in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Samples/Beyond.NET.Sample.Swift/Source/LibraryInit/__LibraryInit.m b/Samples/Beyond.NET.Sample.Swift/Source/LibraryInit/__LibraryInit.m new file mode 100644 index 00000000..6591b533 --- /dev/null +++ b/Samples/Beyond.NET.Sample.Swift/Source/LibraryInit/__LibraryInit.m @@ -0,0 +1,52 @@ +#import +#import + +#import + +@interface __DNLibraryInit : NSObject +@end + +@implementation __DNLibraryInit + ++ (void)load { +#if TARGET_OS_IOS + // iOS/iOS Simulator + NSBundle* bundle = [NSBundle bundleForClass:__DNLibraryInit.class]; + + if (!bundle) { + return; + } + + System_Exception_t ex = NULL; + System_String_t name = DNStringFromC("ICU_DAT_FILE_PATH"); + + if (!name) { + return; + } + + NSString* icuPath = [bundle pathForResource:@"icudt" ofType:@"dat"]; + + if (!icuPath) { + return; + } + + System_String_t icuPathDN = DNStringFromC(icuPath.UTF8String); + + System_AppContext_SetData(name, + icuPathDN, + &ex); + + System_String_Destroy(name); + System_String_Destroy(icuPathDN); + + if (ex) { + NSLog(@"Error: Setting icudt.dat path failed."); + } +#elif TARGET_OS_MAC && !TARGET_OS_IPHONE + // macOS +#else + // Other platform +#endif +} + +@end