diff --git a/build.go b/build.go index cbee872..a6e82b8 100644 --- a/build.go +++ b/build.go @@ -689,10 +689,14 @@ func archMatches(architectures []string) bool { return true } - if slices.Contains(architectures, "arm") { - architectures = append(architectures, cpu.ARMVariant()) + for _, arch := range architectures { + if strings.HasPrefix(arch, "arm") { + architectures = append(architectures, cpu.CompatibleARMReverse(arch)...) + } } + fmt.Println(architectures) + return slices.Contains(architectures, cpu.Arch()) } diff --git a/internal/cpu/cpu.go b/internal/cpu/cpu.go index 45e5078..ff3f349 100644 --- a/internal/cpu/cpu.go +++ b/internal/cpu/cpu.go @@ -44,15 +44,55 @@ func ARMVariant() string { } } +// CompatibleARM returns all the compatible ARM variants given the system architecture +func CompatibleARM(variant string) []string { + switch variant { + case "arm7", "arm": + return []string{"arm7", "arm6", "arm5"} + case "arm6": + return []string{"arm6", "arm5"} + case "arm5": + return []string{"arm5"} + default: + return []string{variant} + } +} + +// CompatibleARMReverse returns all the compatible ARM variants given the package's architecture +func CompatibleARMReverse(variant string) []string { + switch variant { + case "arm7": + return []string{"arm7"} + case "arm6": + return []string{"arm6", "arm7"} + case "arm5", "arm": + return []string{"arm5", "arm6", "arm7"} + default: + return []string{variant} + } +} + // Arch returns the canonical CPU architecture of the system func Arch() string { arch := os.Getenv("LURE_ARCH") - if arch != "" { - return arch + if arch == "" { + arch = runtime.GOARCH } - arch = runtime.GOARCH if arch == "arm" { arch = ARMVariant() } return arch } + +// Arches returns all the architectures the system is compatible with +func Arches() []string { + arch := os.Getenv("LURE_ARCH") + if arch == "" { + arch = runtime.GOARCH + } + if strings.HasPrefix(arch, "arm") { + return append(CompatibleARM(arch), "arm") + } else { + return []string{Arch()} + } +} diff --git a/internal/overrides/overrides.go b/internal/overrides/overrides.go index dd32e72..3e6c741 100644 --- a/internal/overrides/overrides.go +++ b/internal/overrides/overrides.go @@ -20,7 +20,6 @@ package overrides import ( "reflect" - "runtime" "strings" "go.elara.ws/lure/distro" @@ -59,13 +58,7 @@ func Resolve(info *distro.OSRelease, opts *Opts) ([]string, error) { return nil, err } - architectures := []string{runtime.GOARCH} - - if runtime.GOARCH == "arm" { - // More specific goes first - architectures[0] = cpu.ARMVariant() - architectures = append(architectures, "arm") - } + architectures := cpu.Arches() distros := []string{info.ID} if opts.LikeDistros {