@@ -140,8 +140,8 @@ 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 {
144
- library = findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (libraries , platform ))
143
+ if platform != nil {
144
+ library = findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (libraries , platform , true ))
145
145
}
146
146
}
147
147
@@ -150,6 +150,12 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
150
150
}
151
151
152
152
if library == nil {
153
+ // reorder libraries to promote fully compatible ones
154
+ for _ , platform := range platforms {
155
+ if platform != nil {
156
+ libraries = append (librariesCompatibleWithPlatform (libraries , platform , false ), libraries ... )
157
+ }
158
+ }
153
159
library = libraries [0 ]
154
160
}
155
161
@@ -218,21 +224,34 @@ func findLibraryIn(libraries []*types.Library, library *types.Library) *types.Li
218
224
return nil
219
225
}
220
226
221
- func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) bool {
227
+ func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) ( bool , bool ) {
222
228
if len (library .Archs ) == 0 {
223
- return true
229
+ return true , true
230
+ }
231
+ if utils .SliceContains (library .Archs , constants .LIBRARY_ALL_ARCHS ) {
232
+ return true , true
224
233
}
234
+ return utils .SliceContains (library .Archs , platform .PlatformId ), false
235
+ }
236
+
237
+ func libraryCompatibleWithAllPlatforms (library * types.Library ) bool {
225
238
if utils .SliceContains (library .Archs , constants .LIBRARY_ALL_ARCHS ) {
226
239
return true
227
240
}
228
- return utils . SliceContains ( library . Archs , platform . PlatformId )
241
+ return false
229
242
}
230
243
231
- func librariesCompatibleWithPlatform (libraries []* types.Library , platform * types.Platform ) []* types.Library {
244
+ func librariesCompatibleWithPlatform (libraries []* types.Library , platform * types.Platform , reorder bool ) []* types.Library {
232
245
var compatibleLibraries []* types.Library
233
246
for _ , library := range libraries {
234
- if libraryCompatibleWithPlatform (library , platform ) {
235
- compatibleLibraries = append (compatibleLibraries , library )
247
+ compatible , generic := libraryCompatibleWithPlatform (library , platform )
248
+ if compatible {
249
+ if ! generic && len (compatibleLibraries ) != 0 && libraryCompatibleWithAllPlatforms (compatibleLibraries [0 ]) && reorder == true {
250
+ //priority inversion
251
+ compatibleLibraries = append ([]* types.Library {library }, compatibleLibraries ... )
252
+ } else {
253
+ compatibleLibraries = append (compatibleLibraries , library )
254
+ }
236
255
}
237
256
}
238
257
0 commit comments