Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions image/internal/pkg/platform/platform_matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ func getCPUInfo(pattern string) (info string, err error) {
return "", fmt.Errorf("getCPUInfo for pattern: %s not found", pattern)
}

func getCPUVariantDarwinWindows(arch string) string {
// Darwin and Windows only support v7 for ARM32 and v8 for ARM64 and so we can use
// runtime.GOARCH to determine the variants
func getCPUVariantFromArch(arch string) string {
// ARMv8 is unambiguously 64-bit. Assuming v7 for 32-bit ARM is a safe guess:
// it's strictly true for Darwin/Windows and fine for FreeBSD in practice. On FreeBSD,
// ARMv6 is effectively deprecated and ARMv7 lacks pre-built packages, so this
// assumption won't impact realistic workloads (https://www.freebsd.org/platforms/).
var variant string
switch arch {
case "arm64":
Expand All @@ -80,7 +82,7 @@ func getCPUVariantDarwinWindows(arch string) string {
return variant
}

func getCPUVariantArm() string {
func getCPUVariantLinuxArm() string {
variant, err := getCPUInfo("Cpu architecture")
if err != nil {
logrus.Errorf("Couldn't get cpu architecture: %v", err)
Expand Down Expand Up @@ -133,11 +135,13 @@ func getCPUVariantArm() string {
}

func getCPUVariant(os string, arch string) string {
if os == "darwin" || os == "windows" {
return getCPUVariantDarwinWindows(arch)
// Only Linux exposes the CPU variant via /proc/cpuinfo; on other OSes
// (darwin, windows, freebsd) infer it from the architecture (arm64 -> v8).
if os != "linux" {
return getCPUVariantFromArch(arch)
}
if arch == "arm" || arch == "arm64" {
return getCPUVariantArm()
return getCPUVariantLinuxArm()
}
return ""
}
Expand Down
Loading