@@ -98,7 +98,7 @@ public static void MovePath(string source, string target)
9898 /// <param name="path">path</param>
9999 public static bool DeletePath ( string path )
100100 {
101- string [ ] allowedDirs = new string [ ] { LLMUnitySetup . GetAssetPath ( ) , BuildTempDir , PluginDir ( "Android" ) , PluginDir ( "iOS" ) , PluginDir ( "VisionOS" ) } ;
101+ string [ ] allowedDirs = new string [ ] { LLMUnitySetup . GetAssetPath ( ) , BuildTempDir , PluginDir ( "Android" ) , PluginDir ( "iOS" ) , PluginDir ( "VisionOS" ) } ;
102102 bool deleteOK = false ;
103103 foreach ( string allowedDir in allowedDirs ) deleteOK = deleteOK || LLMUnitySetup . IsSubPath ( path , allowedDir ) ;
104104 if ( ! deleteOK )
@@ -113,7 +113,7 @@ public static bool DeletePath(string path)
113113
114114 static void AddMovedPair ( string source , string target )
115115 {
116- movedPairs . Add ( new StringPair { source = source , target = target } ) ;
116+ movedPairs . Add ( new StringPair { source = source , target = target } ) ;
117117 File . WriteAllText ( movedCache , JsonUtility . ToJson ( new ListStringPair { pairs = movedPairs } , true ) ) ;
118118 }
119119
@@ -164,70 +164,102 @@ static void AddActionAddMeta(string target)
164164 /// <param name="platform">target platform</param>
165165 public static void BuildLibraryPlatforms ( BuildTarget buildTarget )
166166 {
167- string platform = "" ;
167+ List < string > platforms = new List < string > ( ) ;
168+ bool checkCUBLAS = false ;
168169 switch ( buildTarget )
169170 {
170171 case BuildTarget . StandaloneWindows :
171172 case BuildTarget . StandaloneWindows64 :
172- platform = "windows" ;
173+ platforms . Add ( "win-x64" ) ;
174+ checkCUBLAS = true ;
173175 break ;
174176 case BuildTarget . StandaloneLinux64 :
175- platform = "linux" ;
177+ platforms . Add ( "linux-x64" ) ;
178+ checkCUBLAS = true ;
176179 break ;
177180 case BuildTarget . StandaloneOSX :
178- platform = "macos" ;
181+ platforms . Add ( "osx-universal" ) ;
179182 break ;
180183 case BuildTarget . Android :
181- platform = "android" ;
184+ platforms . Add ( "android-arm64" ) ;
185+ platforms . Add ( "android-x64" ) ;
182186 break ;
183187 case BuildTarget . iOS :
184- platform = "ios" ;
188+ platforms . Add ( "ios-arm64" ) ;
185189 break ;
186190 case BuildTarget . VisionOS :
187- platform = "visionos" ;
191+ platforms . Add ( "visionos-arm64" ) ;
188192 break ;
189193 }
190194
191195 foreach ( string source in Directory . GetDirectories ( LLMUnitySetup . libraryPath ) )
192196 {
193197 string sourceName = Path . GetFileName ( source ) ;
194- bool move = ! sourceName . StartsWith ( platform ) ;
195- move = move || ( sourceName . Contains ( "cuda" ) && ! sourceName . Contains ( "full" ) && LLMUnitySetup . FullLlamaLib ) ;
196- move = move || ( sourceName . Contains ( "cuda" ) && sourceName . Contains ( "full" ) && ! LLMUnitySetup . FullLlamaLib ) ;
197- if ( move )
198+ if ( ! platforms . Contains ( sourceName ) )
198199 {
199200 string target = Path . Combine ( BuildTempDir , sourceName ) ;
200201 MoveAction ( source , target ) ;
201202 MoveAction ( source + ".meta" , target + ".meta" ) ;
202203 }
203204 }
204205
206+ if ( checkCUBLAS )
207+ {
208+ List < string > exclusionKeywords = LLMUnitySetup . CUBLAS ? new List < string > ( ) { "tinyblas" } : new List < string > ( ) { "cublas" , "cudart" } ;
209+ foreach ( string platform in platforms )
210+ {
211+ string platformDir = Path . Combine ( LLMUnitySetup . libraryPath , platform , "native" ) ;
212+ foreach ( string source in Directory . GetFiles ( platformDir ) )
213+ {
214+ string sourceName = Path . GetFileName ( source ) ;
215+ foreach ( string exclusionKeyword in exclusionKeywords )
216+ {
217+ if ( sourceName . Contains ( exclusionKeyword ) )
218+ {
219+ string target = Path . Combine ( BuildTempDir , platform , "native" , sourceName ) ;
220+ MoveAction ( source , target ) ;
221+ MoveAction ( source + ".meta" , target + ".meta" ) ; ;
222+ break ;
223+ }
224+ }
225+ }
226+ }
227+ }
228+
205229 if ( buildTarget == BuildTarget . Android || buildTarget == BuildTarget . iOS || buildTarget == BuildTarget . VisionOS )
206230 {
207- string source = Path . Combine ( LLMUnitySetup . libraryPath , platform ) ;
208- string target = PluginLibraryDir ( buildTarget . ToString ( ) ) ;
209- string pluginDir = PluginDir ( buildTarget . ToString ( ) ) ;
210- MoveAction ( source , target ) ;
211- MoveAction ( source + ".meta" , target + ".meta" ) ;
212- AddActionAddMeta ( pluginDir ) ;
231+ foreach ( string platform in platforms )
232+ {
233+ string source = Path . Combine ( LLMUnitySetup . libraryPath , platform , "native" ) ;
234+ string target = Path . Combine ( PluginLibraryDir ( buildTarget . ToString ( ) ) , platform ) ;
235+ string pluginDir = PluginDir ( buildTarget . ToString ( ) ) ;
236+ MoveAction ( source , target ) ;
237+ MoveAction ( source + ".meta" , target + ".meta" ) ;
238+ AddActionAddMeta ( pluginDir ) ;
239+ }
213240 }
214241 }
215242
216243 static void OnPostprocessAllAssets ( string [ ] importedAssets , string [ ] deletedAssets , string [ ] movedAssets , string [ ] movedFromAssetPaths , bool didDomainReload )
217244 {
218- foreach ( BuildTarget buildTarget in new BuildTarget [ ] { BuildTarget . iOS , BuildTarget . VisionOS } )
245+ foreach ( BuildTarget buildTarget in new BuildTarget [ ] { BuildTarget . iOS , BuildTarget . VisionOS , BuildTarget . Android } )
219246 {
220- string pathToPlugin = Path . Combine ( "Assets" , PluginLibraryDir ( buildTarget . ToString ( ) , true ) , $ "libundreamai_ { buildTarget . ToString ( ) . ToLower ( ) } .a" ) ;
221- for ( int i = 0 ; i < movedAssets . Length ; i ++ )
247+ string suffix = ( buildTarget == BuildTarget . Android ) ? "so" : "a" ;
248+ foreach ( string platformDir in Directory . GetDirectories ( Path . Combine ( "Assets" , PluginLibraryDir ( buildTarget . ToString ( ) , true ) ) ) )
222249 {
223- if ( movedAssets [ i ] == pathToPlugin )
250+ string platform = Path . GetFileName ( platformDir ) ;
251+ string pathToPlugin = Path . Combine ( platformDir , $ "libllamalib_{ platform } .{ suffix } ") ;
252+ for ( int i = 0 ; i < movedAssets . Length ; i ++ )
224253 {
225- var importer = AssetImporter . GetAtPath ( pathToPlugin ) as PluginImporter ;
226- if ( importer != null && importer . isNativePlugin )
254+ if ( movedAssets [ i ] == pathToPlugin )
227255 {
228- importer . SetCompatibleWithPlatform ( buildTarget , true ) ;
229- importer . SetPlatformData ( buildTarget , "CPU" , "ARM64" ) ;
230- AssetDatabase . ImportAsset ( pathToPlugin ) ;
256+ var importer = AssetImporter . GetAtPath ( pathToPlugin ) as PluginImporter ;
257+ if ( importer != null && importer . isNativePlugin )
258+ {
259+ importer . SetCompatibleWithPlatform ( buildTarget , true ) ;
260+ importer . SetPlatformData ( buildTarget , "CPU" , platform . Split ( "_" ) [ 1 ] . ToUpper ( ) ) ;
261+ AssetDatabase . ImportAsset ( pathToPlugin ) ;
262+ }
231263 }
232264 }
233265 }
0 commit comments