@@ -140,7 +140,7 @@ func resolveLibrary(header string, headerToLibraries map[string][]*types.Library
140140 var library * types.Library
141141
142142 for _ , platform := range platforms {
143- if platform != nil && library == nil {
143+ if platform != nil {
144144 library = findBestLibraryWithHeader (header , librariesCompatibleWithPlatform (libraries , platform ))
145145 }
146146 }
@@ -218,21 +218,34 @@ func findLibraryIn(libraries []*types.Library, library *types.Library) *types.Li
218218 return nil
219219}
220220
221- func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) bool {
221+ func libraryCompatibleWithPlatform (library * types.Library , platform * types.Platform ) ( bool , bool ) {
222222 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
224227 }
228+ return utils .SliceContains (library .Archs , platform .PlatformId ), false
229+ }
230+
231+ func libraryCompatibleWithAllPlatforms (library * types.Library ) bool {
225232 if utils .SliceContains (library .Archs , constants .LIBRARY_ALL_ARCHS ) {
226233 return true
227234 }
228- return utils . SliceContains ( library . Archs , platform . PlatformId )
235+ return false
229236}
230237
231238func librariesCompatibleWithPlatform (libraries []* types.Library , platform * types.Platform ) []* types.Library {
232239 var compatibleLibraries []* types.Library
233240 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+ }
236249 }
237250 }
238251
0 commit comments