@@ -140,7 +140,7 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
140
140
var library * types.Library
141
141
142
142
for _ , platform := range platforms {
143
- if platform != nil && library == nil {
143
+ if platform != nil {
144
144
library = findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (libraries , platform ))
145
145
}
146
146
}
@@ -218,21 +218,34 @@ func findLibraryIn(libraries []*types.Library, library *types.Library) *types.Li
218
218
return nil
219
219
}
220
220
221
- func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) bool {
221
+ func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) ( bool , bool ) {
222
222
if len (library .Archs ) == 0 {
223
- return true
223
+ return true , true
224
+ }
225
+ if utils .SliceContains (library .Archs , constants .LIBRARY_ALL_ARCHS ) {
226
+ return true , true
224
227
}
228
+ return utils .SliceContains (library .Archs , platform .PlatformId ), false
229
+ }
230
+
231
+ func libraryCompatibleWithAllPlatforms (library * types.Library ) bool {
225
232
if utils .SliceContains (library .Archs , constants .LIBRARY_ALL_ARCHS ) {
226
233
return true
227
234
}
228
- return utils . SliceContains ( library . Archs , platform . PlatformId )
235
+ return false
229
236
}
230
237
231
238
func librariesCompatibleWithPlatform (libraries []* types.Library , platform * types.Platform ) []* types.Library {
232
239
var compatibleLibraries []* types.Library
233
240
for _ , library := range libraries {
234
- if libraryCompatibleWithPlatform (library , platform ) {
235
- compatibleLibraries = append (compatibleLibraries , library )
241
+ compatible , generic := libraryCompatibleWithPlatform (library , platform )
242
+ if compatible {
243
+ if ! generic && len (compatibleLibraries ) != 0 && libraryCompatibleWithAllPlatforms (compatibleLibraries [0 ]) {
244
+ //priority inversion
245
+ compatibleLibraries = append ([]* types.Library {library }, compatibleLibraries ... )
246
+ } else {
247
+ compatibleLibraries = append (compatibleLibraries , library )
248
+ }
236
249
}
237
250
}
238
251
0 commit comments