@@ -20,6 +20,9 @@ public class GetNativeRuntimeComponents : AndroidTask
20
20
[ Required ]
21
21
public ITaskItem [ ] ResolvedNativeObjectFiles { get ; set ; }
22
22
23
+ [ Required ]
24
+ public string HackLocalClrRepoPath { get ; set ; }
25
+
23
26
[ Output ]
24
27
public ITaskItem [ ] NativeArchives { get ; set ; }
25
28
@@ -60,6 +63,28 @@ public override bool RunTask ()
60
63
MakeLibItem ( symbolName , symbolsToExport , uniqueAbis ) ;
61
64
}
62
65
}
66
+
67
+ // HACK! START: until CoreCLR runtime pack has the necessary .a archives
68
+ var discoveredItemNames = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) ;
69
+ foreach ( ITaskItem item in archives ) {
70
+ discoveredItemNames . Add ( Path . GetFileName ( item . ItemSpec ) ) ;
71
+ }
72
+
73
+ Log . LogWarning ( "[HACK] Looking for native archives which require CoreCLR hack" ) ;
74
+ foreach ( NativeRuntimeComponents . Archive archiveItem in components . KnownArchives ) {
75
+ if ( ! archiveItem . Include || ! archiveItem . NeedsClrHack ) {
76
+ continue ;
77
+ }
78
+
79
+ Log . LogDebugMessage ( $ " [HACK] archive { archiveItem . Name } ") ;
80
+ if ( discoveredItemNames . Contains ( archiveItem . Name ) ) {
81
+ Log . LogDebugMessage ( " [HACK] already found elsewhere" ) ;
82
+ continue ;
83
+ }
84
+ HackMakeArchiveItem ( archiveItem , archives , uniqueAbis ) ;
85
+ }
86
+ // HACK! END
87
+
63
88
NativeArchives = archives . ToArray ( ) ;
64
89
NativeSymbolsToExport = symbolsToExport . ToArray ( ) ;
65
90
@@ -132,4 +157,70 @@ ITaskItem DoMakeItem (string msbuildItemName, ITaskItem sourceItem, HashSet<stri
132
157
133
158
return ret ;
134
159
}
160
+
161
+ void HackMakeArchiveItem ( NativeRuntimeComponents . Archive archive , List < ITaskItem > archives , HashSet < string > uniqueAbis )
162
+ {
163
+ var relativeArtifactPaths = new List < ( string path , string abi ) > ( ) ;
164
+ string archiveName = Path . GetFileName ( archive . Name ) ;
165
+ string commonClrObjDir = Path . Combine ( "artifacts" , "obj" , "coreclr" ) ;
166
+
167
+ if ( IsArchive ( "libcoreclr.a" ) ) {
168
+ archiveName = "libcoreclr_static.a" ;
169
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "dlls" , "mscoree" , "coreclr" ) ) ;
170
+ } else if ( IsArchive ( "libcoreclrpal.a" ) ) {
171
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "pal" , "src" ) ) ;
172
+ } else if ( IsArchive ( "libminipal.a" ) ) {
173
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "shared_minipal" ) ) ;
174
+ } else if ( IsArchive ( "libcoreclrminipal.a" ) ) {
175
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "minipal" , "Unix" ) ) ;
176
+ } else if ( IsArchive ( "libgc_pal.a" ) ) {
177
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "gc" , "unix" ) ) ;
178
+ } else if ( IsArchive ( "libeventprovider.a" ) ) {
179
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "pal" , "src" , "eventprovider" , "dummyprovider" ) ) ;
180
+ } else if ( IsArchive ( "libnativeresourcestring.a" ) ) {
181
+ MakeRelativeArtifactPaths ( ( string clrArch ) => Path . Combine ( commonClrObjDir , $ "android.{ clrArch } .Release", "pal" , "nativeresources" ) ) ;
182
+ } else {
183
+ foreach ( string abi in uniqueAbis ) {
184
+ string clrArch = GetClrArch ( abi ) ;
185
+ relativeArtifactPaths . Add ( ( Path . Combine ( "artifacts" , "bin" , $ "microsoft.netcore.app.runtime.android-{ clrArch } ", "Release" , "runtimes" , $ "android-{ clrArch } ", "native" ) , abi ) ) ;
186
+ }
187
+ }
188
+
189
+ foreach ( ( string relPath , string abi ) in relativeArtifactPaths ) {
190
+ string filePath = Path . Combine ( HackLocalClrRepoPath , relPath , archiveName ) ;
191
+ if ( ! File . Exists ( filePath ) ) {
192
+ Log . LogWarning ( $ " [HACK] file { filePath } not found") ;
193
+ continue ;
194
+ }
195
+ Log . LogWarning ( $ " [HACK] adding runtime component '{ filePath } '") ;
196
+ var tempItem = new TaskItem ( filePath ) ;
197
+ tempItem . SetMetadata ( KnownMetadata . Abi , abi ) ;
198
+ tempItem . SetMetadata ( KnownMetadata . RuntimeIdentifier , MonoAndroidHelper . AbiToRid ( abi ) ) ;
199
+ ITaskItem newItem = DoMakeItem ( "_ResolvedNativeArchive" , tempItem , uniqueAbis ) ;
200
+ newItem . SetMetadata ( KnownMetadata . NativeLinkWholeArchive , archive . WholeArchive . ToString ( ) ) ;
201
+ if ( archive . DontExportSymbols ) {
202
+ newItem . SetMetadata ( KnownMetadata . NativeDontExportSymbols , "true" ) ;
203
+ }
204
+ archives . Add ( newItem ) ;
205
+ }
206
+
207
+ string GetClrArch ( string abi )
208
+ {
209
+ return abi switch {
210
+ "arm64-v8a" => "arm64" ,
211
+ "x86_64" => "x64" ,
212
+ _ => throw new NotSupportedException ( $ "ABI { abi } is not supported for CoreCLR")
213
+ } ;
214
+ }
215
+
216
+ void MakeRelativeArtifactPaths ( Func < string , string > create )
217
+ {
218
+ foreach ( string abi in uniqueAbis ) {
219
+ string clrArch = GetClrArch ( abi ) ;
220
+ relativeArtifactPaths . Add ( ( create ( clrArch ) , abi ) ) ;
221
+ }
222
+ }
223
+
224
+ bool IsArchive ( string name ) => String . Compare ( name , archiveName , StringComparison . OrdinalIgnoreCase ) == 0 ;
225
+ }
135
226
}
0 commit comments