Skip to content

Commit

Permalink
Improve arm64 comparing
Browse files Browse the repository at this point in the history
Signed-off-by: Chongyi Zheng <git@zcy.dev>
  • Loading branch information
harryzcy committed Mar 30, 2024
1 parent b5783e6 commit 51a4916
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package platforms

import (
"fmt"
"strconv"
"strings"

Expand Down Expand Up @@ -72,6 +73,57 @@ func platformVector(platform specs.Platform) []specs.Platform {
if variant == "" {
variant = "v8"
}

if armMajor, err := strconv.Atoi(strings.TrimPrefix(variant[:2], "v")); err == nil && armMajor >= 8 {
armMinor := 0
if len(variant) == 4 {
if minor, err := strconv.Atoi(variant[3:]); err == nil && variant[2] == '.' {
armMinor = minor
}
}

if armMajor == 9 {
for minor := armMinor - 1; minor >= 0; minor-- {
arm64Variant := "v" + strconv.Itoa(armMajor) + "." + strconv.Itoa(minor)
if minor == 0 {
arm64Variant = "v" + strconv.Itoa(armMajor)
}
vector = append(vector, specs.Platform{
Architecture: platform.Architecture,
OS: platform.OS,
OSVersion: platform.OSVersion,
OSFeatures: platform.OSFeatures,
Variant: arm64Variant,
})
}

// v9.0 diverged from v8.5, meaning that v9.x is compatible with v8.{x+5}
armMinor := armMinor + 5
vector = append(vector, specs.Platform{
Architecture: platform.Architecture,
OS: platform.OS,
OSVersion: platform.OSVersion,
OSFeatures: platform.OSFeatures,
Variant: "v8." + strconv.Itoa(armMinor),
})
}

for minor := armMinor - 1; minor >= 0; minor-- {
arm64Variant := "v" + strconv.Itoa(armMajor) + "." + strconv.Itoa(minor)
if minor == 0 {
arm64Variant = "v" + strconv.Itoa(armMajor)
}
fmt.Println(117, variant, armMajor, armMinor, arm64Variant)
vector = append(vector, specs.Platform{
Architecture: platform.Architecture,
OS: platform.OS,
OSVersion: platform.OSVersion,
OSFeatures: platform.OSFeatures,
Variant: arm64Variant,
})
}
}

vector = append(vector, platformVector(specs.Platform{
Architecture: "arm",
OS: platform.OS,
Expand All @@ -87,6 +139,8 @@ func platformVector(platform specs.Platform) []specs.Platform {
// Only returns a match comparer for a single platform
// using default resolution logic for the platform.
//
// For arm64/v9.x, will also match arm64/v9.{0..x-1} and arm64/v8.{0..x+5}
// For arm64/v8.x, will also match arm64/v8.{0..x-1}
// For arm/v8, will also match arm/v7, arm/v6 and arm/v5
// For arm/v7, will also match arm/v6 and arm/v5
// For arm/v6, will also match arm/v5
Expand Down

0 comments on commit 51a4916

Please sign in to comment.