Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: More reliable arch detection in install.ps1 #4128

Merged
merged 1 commit into from
Dec 9, 2024
Merged
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
52 changes: 29 additions & 23 deletions assets/scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -93,36 +93,42 @@ function Get-GoOS {
}

function Get-GoArch {
$goArch = @{
'32-bit' = 'i386'
'64-bit' = 'amd64'
'Arm' = 'arm'
'Arm64' = 'arm64'
'X86' = 'i386'
'X64' = 'amd64'
if ($PSVersionTable.PSEdition -eq 'Core') {
$goArch = @{
'Arm' = 'arm'
'Arm64' = 'arm64'
'X86' = 'i386'
'X64' = 'amd64'
}
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()
$result = $goArch[$arch]
if (-not $result) {
throw "Unsupported OS architecture: $arch"
}
return $result
}

$arch = $null
$cpuArch = (Get-CimInstance -ClassName Win32_Processor).Architecture

if ($PSVersionTable.PSEdition -eq 'Desktop') {
$arch = (Get-CimInstance -Class Win32_OperatingSystem).OSArchitecture
if ([System.Environment]::Is64BitOperatingSystem) {
switch ($cpuArch) {
9 { return 'amd64' }
12 { return 'arm64' }
default {
throw "Unsupported CPU architecture ($cpuArch) on a 64-bit OS."
}
}
} else {
$arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString()

if ([string]::IsNullOrEmpty($arch)) {
$arch = if ([System.Environment]::Is64BitOperatingSystem) {
'X64'
} else {
'X86'
switch ($cpuArch) {
0 { return 'i386' }
9 { return 'i386' } # AMD64 CPU running 32-bit OS
5 { return 'arm' }
12 { return 'arm' } # ARM64 CPU running 32-bit OS
default {
throw "Unsupported CPU architecture ($cpuArch) on a 32-bit OS."
}
}
}

if ([string]::IsNullOrEmpty($arch)) {
Write-Error 'unable to determine GOARCH'
}

return $goArch[$arch]
}

function Get-RealTag ($tag) {
Expand Down