@@ -36,6 +36,13 @@ public void OnPostprocessBuild(BuildReport report)
3636 }
3737 }
3838
39+ /// <summary>
40+ /// A common method that copies and sets options for ONNX Runtime XCFramework in iOS
41+ /// </summary>
42+ /// <param name="report">A build report</param>
43+ /// <param name="packagePath">A package path starting from "Packages/com.domain.package"</param>
44+ /// <param name="frameworkSrcPath">A source XCFramework path</param>
45+ /// <param name="frameworkDstPath">A destination XCFramework path</param>
3946 public static void CopyOrtXCFramework (
4047 BuildReport report ,
4148 string packagePath ,
@@ -50,21 +57,32 @@ public static void CopyOrtXCFramework(
5057 // Copy XCFramework to the Xcode project folder
5158 string frameworkSrcAbsPath = Path . Combine ( packagePath , frameworkSrcPath ) ;
5259 string frameworkDstAbsPath = Path . Combine ( report . summary . outputPath , frameworkDstPath ) ;
53- FileUtil . ReplaceDirectory ( frameworkSrcAbsPath , frameworkDstAbsPath ) ;
60+ CopyDirectory ( frameworkSrcAbsPath , frameworkDstAbsPath ) ;
5461
5562 // Then add to Xcode project
5663 string frameworkGuid = pbxProject . AddFile ( frameworkDstAbsPath , frameworkDstPath , PBXSourceTree . Source ) ;
5764 string unityTargetGuid = pbxProject . GetUnityFrameworkTargetGuid ( ) ;
5865 string targetBuildPhaseGuid = pbxProject . AddFrameworksBuildPhase ( unityTargetGuid ) ;
5966 pbxProject . AddFileToBuildSection ( unityTargetGuid , targetBuildPhaseGuid , frameworkGuid ) ;
6067
61- // TODO: Required only when GenAI is installed
62- // Add to Embed Frameworks in the main target
68+ #if ORT_GENAI_ENABLED
69+ // NOTE: Required only when GenAI package is installed
70+ // GenAI loads the dynamic library in runtime. need to embed in the main target
6371 string mainTargetGuid = pbxProject . GetUnityMainTargetGuid ( ) ;
6472 pbxProject . AddFileToEmbedFrameworks ( mainTargetGuid , frameworkGuid ) ;
73+ #endif // ORT_GENAI_ENABLED
6574
6675 pbxProject . WriteToFile ( pbxProjectPath ) ;
6776#endif // UNITY_IOS
6877 }
78+
79+ static void CopyDirectory ( string source , string dest )
80+ {
81+ if ( Directory . Exists ( dest ) && ! FileUtil . DeleteFileOrDirectory ( dest ) )
82+ {
83+ throw new IOException ( $ "Failed to delete directory '{ dest } '.") ;
84+ }
85+ FileUtil . CopyFileOrDirectoryFollowSymlinks ( source , dest ) ;
86+ }
6987 }
7088}
0 commit comments