|
5 | 5 | $ErrorActionPreference = 'Stop' |
6 | 6 |
|
7 | 7 | # Detect architecture (x64, ARM64, or x86) |
| 8 | +# Try RuntimeInformation first, fall back to environment/pointer size for older systems |
| 9 | +$architecture = $null |
| 10 | + |
8 | 11 | $runtimeArch = [System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture |
9 | | -$architecture = switch ($runtimeArch) { |
10 | | - ([System.Runtime.InteropServices.Architecture]::X64) { 'x64' } |
11 | | - ([System.Runtime.InteropServices.Architecture]::Arm64) { 'arm64' } |
12 | | - ([System.Runtime.InteropServices.Architecture]::X86) { 'x86' } |
13 | | - ([System.Runtime.InteropServices.Architecture]::Arm) { 'arm' } |
14 | | - default { throw "Unsupported architecture: $runtimeArch" } |
| 12 | +if ($null -ne $runtimeArch) { |
| 13 | + $architecture = switch ($runtimeArch) { |
| 14 | + ([System.Runtime.InteropServices.Architecture]::X64) { 'x64' } |
| 15 | + ([System.Runtime.InteropServices.Architecture]::Arm64) { 'arm64' } |
| 16 | + ([System.Runtime.InteropServices.Architecture]::X86) { 'x86' } |
| 17 | + ([System.Runtime.InteropServices.Architecture]::Arm) { 'arm' } |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +# Fallback detection when RuntimeInformation is unavailable or returns null |
| 22 | +if ($null -eq $architecture) { |
| 23 | + $processorArch = $env:PROCESSOR_ARCHITECTURE |
| 24 | + if ($processorArch -eq 'AMD64') { |
| 25 | + $architecture = 'x64' |
| 26 | + } elseif ($processorArch -eq 'ARM64') { |
| 27 | + $architecture = 'arm64' |
| 28 | + } elseif ($processorArch -eq 'x86') { |
| 29 | + $architecture = 'x86' |
| 30 | + } elseif ($processorArch -eq 'ARM') { |
| 31 | + $architecture = 'arm' |
| 32 | + } else { |
| 33 | + # Last resort: use pointer size to distinguish 32-bit vs 64-bit |
| 34 | + if ([IntPtr]::Size -eq 8) { |
| 35 | + $architecture = 'x64' |
| 36 | + } elseif ([IntPtr]::Size -eq 4) { |
| 37 | + $architecture = 'x86' |
| 38 | + } else { |
| 39 | + throw "Unable to detect architecture. PROCESSOR_ARCHITECTURE='$processorArch', IntPtr.Size=$([IntPtr]::Size)" |
| 40 | + } |
| 41 | + } |
15 | 42 | } |
16 | 43 |
|
17 | 44 | # Determine library filename based on platform |
|
0 commit comments