55using System . Threading ;
66using NuGet . Common ;
77using NuGet . Packaging ;
8- using Scriban ;
98
109namespace UnityNuGet
1110{
1211 static class NativeLibraries
1312 {
14- public static async IAsyncEnumerable < ( string file , string [ ] folders , string platform , string architecture ) > GetSupportedNativeLibsAsync ( PackageReaderBase packageReader , ILogger logger )
13+ public static async IAsyncEnumerable < ( string file , string [ ] folders , UnityOs os , UnityCpu cpu ) > GetSupportedNativeLibsAsync (
14+ PackageReaderBase packageReader ,
15+ ILogger logger )
1516 {
1617 var versions = await packageReader . GetItemsAsync ( PackagingConstants . Folders . Runtimes , CancellationToken . None ) ;
1718 var files = versions . SelectMany ( v => v . Items ) ;
@@ -35,144 +36,36 @@ static class NativeLibraries
3536 continue ;
3637 }
3738
38- var platform = system [ 0 ] [ ..3 ] switch
39+ UnityOs ? os = system [ 0 ] [ ..3 ] switch
3940 {
40- "lin" => " Linux" ,
41- "osx" => " OSX" ,
42- "win" => " Windows" ,
41+ "lin" => UnityOs . Linux ,
42+ "osx" => UnityOs . OSX ,
43+ "win" => UnityOs . Windows ,
4344 _ => null
4445 } ;
4546
46- if ( platform is null )
47+ if ( os is null )
4748 {
48- logger . LogInformation ( $ "Skipping file for unsupported platform : { file } ...") ;
49+ logger . LogInformation ( $ "Skipping file for unsupported OS : { file } ...") ;
4950 continue ;
5051 }
5152
52- var architecture = system [ 1 ] switch
53+ UnityCpu ? cpu = system [ 1 ] switch
5354 {
54- "x86" => "x86" ,
55- "x64" => "x86_64" ,
56- "arm64" => " ARM64" ,
55+ "x86" => UnityCpu . X86 ,
56+ "x64" => UnityCpu . X64 ,
57+ "arm64" => UnityCpu . ARM64 ,
5758 _ => null
5859 } ;
5960
60- if ( architecture is null )
61+ if ( cpu is null )
6162 {
62- logger . LogInformation ( $ "Skipping file for unsupported architecture : { file } ...") ;
63+ logger . LogInformation ( $ "Skipping file for unsupported CPU : { file } ...") ;
6364 continue ;
6465 }
6566
66- yield return ( file , folders , platform , architecture ) ;
67+ yield return ( file , folders , os . Value , cpu . Value ) ;
6768 }
6869 }
69-
70- private readonly struct PlatformEnables
71- {
72- public readonly int Editor , Linux64 , OSXUniversal , Win , Win64 ;
73-
74- public PlatformEnables ( int editor , int linux64 , int oSXUniversal , int win , int win64 )
75- {
76- Editor = editor ;
77- Linux64 = linux64 ;
78- OSXUniversal = oSXUniversal ;
79- Win = win ;
80- Win64 = win64 ;
81- }
82- }
83-
84- public static string ? GetMetaForNative ( Guid guid , string platform , string architecture , string [ ] labels )
85- {
86- // TODO: Support other platforms
87- PlatformEnables ? enables = ( platform , architecture ) switch
88- {
89- ( "Linux" , _ ) => new ( 1 , 1 , 0 , 0 , 0 ) ,
90- ( "OSX" , _ ) => new ( 1 , 0 , 1 , 0 , 0 ) ,
91- ( "Windows" , "x86" ) => new ( 0 , 0 , 0 , 1 , 0 ) ,
92- ( "Windows" , "x86_64" ) => new ( 1 , 0 , 0 , 0 , 1 ) ,
93- _ => null ,
94- } ;
95-
96- if ( enables is null ) return null ;
97-
98- const string text = @"{{ cpu(x) = x == 1 ? architecture : ""None"" }}fileFormatVersion: 2
99- guid: {{ guid }}
100- {{ labels }}PluginImporter:
101- externalObjects: {}
102- serializedVersion: 2
103- iconMap: {}
104- executionOrder: {}
105- defineConstraints: []
106- isPreloaded: 0
107- isOverridable: 0
108- isExplicitlyReferenced: 0
109- validateReferences: 1
110- platformData:
111- - first:
112- : Any
113- second:
114- enabled: 0
115- settings:
116- Exclude Editor: {{ 1 - enables.Editor }}
117- Exclude Linux64: {{ 1 - enables.Linux64 }}
118- Exclude OSXUniversal: {{ 1 - enables.OSXUniversal }}
119- Exclude Win: {{ 1 - enables.Win }}
120- Exclude Win64: {{ 1 - enables.Win64 }}
121- - first:
122- Any:
123- second:
124- enabled: 1
125- settings: {}
126- - first:
127- Editor: Editor
128- second:
129- enabled: {{ enables.Editor }}
130- settings:
131- CPU: {{ cpu enables.Editor }}
132- DefaultValueInitialized: true
133- OS: {{ enables.Editor == 1 ? platform : ""None"" }}
134- - first:
135- Standalone: Linux64
136- second:
137- enabled: {{ enables.Linux64 }}
138- settings:
139- CPU: {{ cpu enables.Linux64 }}
140- - first:
141- Standalone: OSXUniversal
142- second:
143- enabled: {{ enables.OSXUniversal }}
144- settings:
145- CPU: {{ cpu enables.OSXUniversal }}
146- - first:
147- Standalone: Win
148- second:
149- enabled: {{ enables.Win }}
150- settings:
151- CPU: {{ cpu enables.Win }}
152- - first:
153- Standalone: Win64
154- second:
155- enabled: {{ enables.Win64 }}
156- settings:
157- CPU: {{ cpu enables.Win64 }}
158- userData:
159- assetBundleName:
160- assetBundleVariant:
161- " ;
162-
163- return Template
164- . Parse ( text )
165- . Render ( new
166- {
167- guid = guid . ToString ( "N" ) ,
168- enables ,
169- platform ,
170- architecture ,
171- labels = labels . Length == 0
172- ? string . Empty
173- : $ "labels:\n { string . Concat ( labels . Select ( l => $ " - { l } \n ") ) } ",
174- } )
175- . Replace ( "\r \n " , "\n " ) ;
176- }
17770 }
17871}
0 commit comments