22using UnityEditor . Build ;
33using UnityEditor . Build . Reporting ;
44using UnityEngine ;
5- #if UNITY_IOS || UNITY_VISIONOS
5+ using System . Collections . Generic ;
6+ #if UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_VISIONOS
67using System . IO ;
78using UnityEditor . iOS . Xcode ;
89#endif
@@ -27,56 +28,83 @@ private void OnBuildError(string condition, string stacktrace, LogType type)
2728 if ( type == LogType . Error ) BuildCompleted ( ) ;
2829 }
2930
30- #if UNITY_IOS || UNITY_VISIONOS
31+ #if UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_VISIONOS
3132 /// <summary>
3233 /// Postprocess the iOS Build
3334 /// </summary>
3435 public static void PostprocessIOSBuild ( BuildTarget buildTarget , string outputPath )
3536 {
37+ List < string > libraryFileNames = new List < string > ( ) ;
38+ #if UNITY_IOS
3639 string projPath = PBXProject . GetPBXProjectPath ( outputPath ) ;
37- #if UNITY_VISIONOS
38- projPath = projPath . Replace ( "Unity-iPhone" , "Unity-VisionOS" ) ;
40+ libraryFileNames . Add ( "libllamalib_ios-arm64.a" ) ;
41+ #elif UNITY_VISIONOS
42+ string projPath = PBXProject . GetPBXProjectPath ( outputPath ) . Replace ( "Unity-iPhone" , "Unity-VisionOS" ) ;
43+ libraryFileNames . Add ( "libllamalib_visionos-arm64.a" ) ;
44+ #else
45+ string projPath = Path . Combine ( outputPath , Path . GetFileName ( outputPath ) + ".xcodeproj" , "project.pbxproj" ) ;
46+ if ( ! File . Exists ( projPath ) ) return ;
47+ libraryFileNames . Add ( "libllamalib_osx-universal_acc.dylib" ) ;
48+ libraryFileNames . Add ( "libllamalib_osx-universal_no-acc.dylib" ) ;
3949#endif
50+
4051 PBXProject project = new PBXProject ( ) ;
4152 project . ReadFromFile ( projPath ) ;
4253
43- string targetGuid = project . GetUnityFrameworkTargetGuid ( ) ;
44- string frameworkTargetGuid = project . GetUnityFrameworkTargetGuid ( ) ;
4554 string unityMainTargetGuid = project . GetUnityMainTargetGuid ( ) ;
46- string embedFrameworksGuid = project . GetResourcesBuildPhaseByTarget ( frameworkTargetGuid ) ;
55+ string targetGuid = project . GetUnityFrameworkTargetGuid ( ) ;
4756
4857 // Add Accelerate framework
4958 project . AddFrameworkToProject ( unityMainTargetGuid , "Accelerate.framework" , false ) ;
50- project . AddFrameworkToProject ( targetGuid , "Accelerate.framework" , false ) ;
59+ if ( targetGuid != null ) project . AddFrameworkToProject ( targetGuid , "Accelerate.framework" , false ) ;
60+
61+ List < string > libraryFiles = new List < string > ( ) ;
62+ foreach ( string libraryFileName in libraryFileNames )
63+ {
64+ string lib = LLMUnitySetup . SearchDirectory ( outputPath , libraryFileName ) ;
65+ if ( lib != null ) libraryFiles . Add ( lib ) ;
66+ }
5167
52- string libraryFile = LLMUnitySetup . RelativePath ( LLMUnitySetup . SearchDirectory ( outputPath , $ "libundreamai_{ buildTarget . ToString ( ) . ToLower ( ) } .a") , outputPath ) ;
53- string fileGuid = project . FindFileGuidByProjectPath ( libraryFile ) ;
54- if ( string . IsNullOrEmpty ( fileGuid ) ) LLMUnitySetup . LogError ( $ "Library file { libraryFile } not found in project") ;
68+ if ( libraryFiles . Count == 0 )
69+ {
70+ Debug . LogError ( $ "No library files found for the build") ;
71+ }
5572 else
5673 {
57- foreach ( var phaseGuid in project . GetAllBuildPhasesForTarget ( unityMainTargetGuid ) )
74+ foreach ( string libraryFile in libraryFiles )
5875 {
59- if ( project . GetBuildPhaseName ( phaseGuid ) == "Embed Frameworks" )
76+ string relLibraryFile = LLMUnitySetup . RelativePath ( libraryFile , outputPath ) ;
77+ string fileGuid = project . FindFileGuidByProjectPath ( relLibraryFile ) ;
78+ if ( string . IsNullOrEmpty ( fileGuid ) )
6079 {
61- project . RemoveFileFromBuild ( phaseGuid , fileGuid ) ;
62- break ;
80+ Debug . LogError ( $ "Library file { relLibraryFile } not found in project") ;
6381 }
64- }
82+ else
83+ {
84+ foreach ( var phaseGuid in project . GetAllBuildPhasesForTarget ( unityMainTargetGuid ) )
85+ {
86+ if ( project . GetBuildPhaseName ( phaseGuid ) == "Embed Frameworks" )
87+ {
88+ project . RemoveFileFromBuild ( phaseGuid , fileGuid ) ;
89+ break ;
90+ }
91+ }
6592
66- project . AddFileToBuild ( unityMainTargetGuid , fileGuid ) ;
67- project . AddFileToBuild ( targetGuid , fileGuid ) ;
93+ project . AddFileToBuild ( unityMainTargetGuid , fileGuid ) ;
94+ if ( targetGuid != null ) project . AddFileToBuild ( targetGuid , fileGuid ) ;
95+ }
96+ }
6897 }
6998
7099 project . WriteToFile ( projPath ) ;
71- AssetDatabase . ImportAsset ( projPath ) ;
72100 }
73101
74102#endif
75103
76104 // called after the build
77105 public void OnPostprocessBuild ( BuildReport report )
78106 {
79- #if UNITY_IOS || UNITY_VISIONOS
107+ #if UNITY_STANDALONE_OSX || UNITY_IOS || UNITY_VISIONOS
80108 PostprocessIOSBuild ( report . summary . platform , report . summary . outputPath ) ;
81109#endif
82110 EditorApplication . delayCall += ( ) =>
0 commit comments