From 083ff698c8ce88eb91b0ffa6c549d63483210cfc Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:20:19 -0400 Subject: [PATCH 1/9] feat(install): Add support for x64 microarchitectures `x86-x64-v2` `x86-x64-v3` `x86-x64-v4` --- bin/checkhashes.ps1 | 75 ++++++++++++++++++++++++-------------- bin/checkurls.ps1 | 22 ++++++----- lib/autoupdate.ps1 | 2 +- lib/core.ps1 | 37 ++++++++++++++----- lib/install.ps1 | 2 +- lib/manifest.ps1 | 32 +++++++++++----- libexec/scoop-config.ps1 | 2 +- libexec/scoop-download.ps1 | 2 +- libexec/scoop-install.ps1 | 2 +- schema.json | 33 +++++++++++++++++ test/Scoop-Core.Tests.ps1 | 26 +++++++++++++ 11 files changed, 174 insertions(+), 61 deletions(-) diff --git a/bin/checkhashes.ps1 b/bin/checkhashes.ps1 index 6e6420fb2a..bee822beff 100644 --- a/bin/checkhashes.ps1 +++ b/bin/checkhashes.ps1 @@ -58,7 +58,7 @@ function err ([String] $name, [String[]] $message) { Write-Host ($message -join "`r`n") -ForegroundColor Red } -$MANIFESTS = @() +$MANIFESTS = [System.Collections.ArrayList]::new() foreach ($single in Get-ChildItem $Dir -Filter "$App.json" -Recurse) { $name = $single.BaseName $file = $single.FullName @@ -67,20 +67,31 @@ foreach ($single in Get-ChildItem $Dir -Filter "$App.json" -Recurse) { # Skip nighly manifests, since their hash validation is skipped if ($manifest.version -eq 'nightly') { continue } - $urls = @() - $hashes = @() + $urls = [System.Collections.ArrayList]::new() + $hashes = [System.Collections.ArrayList]::new() if ($manifest.url) { - $manifest.url | ForEach-Object { $urls += $_ } - $manifest.hash | ForEach-Object { $hashes += $_ } + $manifest.url | ForEach-Object { $urls.Add($_) } + $manifest.hash | ForEach-Object { $hashes.Add($_) } } elseif ($manifest.architecture) { # First handle 64bit - script:url $manifest '64bit' | ForEach-Object { $urls += $_ } - hash $manifest '64bit' | ForEach-Object { $hashes += $_ } - script:url $manifest '32bit' | ForEach-Object { $urls += $_ } - hash $manifest '32bit' | ForEach-Object { $hashes += $_ } - script:url $manifest 'arm64' | ForEach-Object { $urls += $_ } - hash $manifest 'arm64' | ForEach-Object { $hashes += $_ } + script:url $manifest '64bit' | ForEach-Object { $urls.Add($_) } + hash $manifest '64bit' | ForEach-Object { $hashes.Add($_) } + + script:url $manifest '64bit-v2' | ForEach-Object { $urls.Add($_) } + hash $manifest '64bit-v2' | ForEach-Object { $hashes.Add($_) } + + script:url $manifest '64bit-v3' | ForEach-Object { $urls.Add($_) } + hash $manifest '64bit-v3' | ForEach-Object { $hashes.Add($_) } + + script:url $manifest '64bit-v4' | ForEach-Object { $urls.Add($_) } + hash $manifest '64bit-v4' | ForEach-Object { $hashes.Add($_) } + + script:url $manifest '32bit' | ForEach-Object { $urls.Add($_) } + hash $manifest '32bit' | ForEach-Object { $hashes.Add($_) } + + script:url $manifest 'arm64' | ForEach-Object { $urls.Add($_) } + hash $manifest 'arm64' | ForEach-Object { $hashes.Add($_) } } else { err $name 'Manifest does not contain URL property.' continue @@ -92,13 +103,13 @@ foreach ($single in Get-ChildItem $Dir -Filter "$App.json" -Recurse) { continue } - $MANIFESTS += @{ - app = $name - file = $file - manifest = $manifest - urls = $urls - hashes = $hashes - } + $MANIFESTS.Add(@{ + app = $name + file = $file + manifest = $manifest + urls = $urls + hashes = $hashes + }) } # clear any existing events @@ -107,9 +118,9 @@ Get-Event | ForEach-Object { Remove-Event $_.SourceIdentifier } foreach ($current in $MANIFESTS) { $count = 0 # Array of indexes mismatched hashes. - $mismatched = @() + $mismatched = [System.Collections.ArrayList]::new() # Array of computed hashes - $actuals = @() + $actuals = [System.Collections.ArrayList]::new() $current.urls | ForEach-Object { $algorithm, $expected = get_hash $current.hashes[$count] @@ -130,9 +141,9 @@ foreach ($current in $MANIFESTS) { $expected = "$algorithm`:$expected" } - $actuals += $actual_hash + $actuals.Add($actual_hash) if ($actual_hash -ne $expected) { - $mismatched += $count + $mismatched.Add($count) } $count++ } @@ -161,16 +172,26 @@ foreach ($current in $MANIFESTS) { $current.manifest.hash = $actuals } else { $platforms = ($current.manifest.architecture | Get-Member -MemberType NoteProperty).Name - # Defaults to zero, don't know, which architecture is available - $64bit_count = 0 - $32bit_count = 0 - $arm64_count = 0 + # Defaults to zero, don't know which architecture is available yet + $64bit_v4_count = $64bit_v3_count = $64bit_v2_count = $64bit_count = $32bit_count = $arm64_count = 0 - # 64bit is get, donwloaded and added first + # 64bit is checked, downloaded and added first if ($platforms.Contains('64bit')) { $64bit_count = $current.manifest.architecture.'64bit'.hash.Count $current.manifest.architecture.'64bit'.hash = $actuals[0..($64bit_count - 1)] } + if ($platforms.Contains('64bit-v2')) { + $64bit_v2_count = $current.manifest.architecture.'64bit-v2'.hash.Count + $current.manifest.architecture.'64bit-v2'.hash = $actuals[0..($64bit_v2_count - 1)] + } + if ($platforms.Contains('64bit-v3')) { + $64bit_v3_count = $current.manifest.architecture.'64bit-v3'.hash.Count + $current.manifest.architecture.'64bit-v3'.hash = $actuals[0..($64bit_v3_count - 1)] + } + if ($platforms.Contains('64bit-v4')) { + $64bit_v4_count = $current.manifest.architecture.'64bit-v4'.hash.Count + $current.manifest.architecture.'64bit-v4'.hash = $actuals[0..($64bit_v4_count - 1)] + } if ($platforms.Contains('32bit')) { $32bit_count = $current.manifest.architecture.'32bit'.hash.Count $current.manifest.architecture.'32bit'.hash = $actuals[($64bit_count)..($64bit_count + $32bit_count - 1)] diff --git a/bin/checkurls.ps1 b/bin/checkurls.ps1 index 0ac593362a..3cd294f941 100644 --- a/bin/checkurls.ps1 +++ b/bin/checkurls.ps1 @@ -88,23 +88,25 @@ function test_dl([String] $url, $cookies) { foreach ($man in $Queue) { $name, $manifest = $man - $urls = @() - $ok = 0 - $failed = 0 - $errors = @() + $urls = [System.Collections.ArrayList]::new() + $ok = $failed = 0 + $errors = [System.Collections.ArrayList]::new() if ($manifest.url) { - $manifest.url | ForEach-Object { $urls += $_ } + $manifest.url | ForEach-Object { $urls.Add($_) } } else { - script:url $manifest '64bit' | ForEach-Object { $urls += $_ } - script:url $manifest '32bit' | ForEach-Object { $urls += $_ } - script:url $manifest 'arm64' | ForEach-Object { $urls += $_ } + script:url $manifest '64bit' | ForEach-Object { $urls.Add($_) } + script:url $manifest '64bit-v2' | ForEach-Object { $urls.Add($_) } + script:url $manifest '64bit-v3' | ForEach-Object { $urls.Add($_) } + script:url $manifest '64bit-v4' | ForEach-Object { $urls.Add($_) } + script:url $manifest '32bit' | ForEach-Object { $urls.Add($_) } + script:url $manifest 'arm64' | ForEach-Object { $urls.Add($_) } } $urls | ForEach-Object { $url, $status, $msg = test_dl $_ $manifest.cookie - if ($msg) { $errors += "$msg ($url)" } - if ($status -eq 'OK' -or $status -eq 'OpeningData') { $ok += 1 } else { $failed += 1 } + if ($msg) { $errors.Add("$msg ($url)") } + if ($status -eq 'OK' -or $status -eq 'OpeningData') { ++$ok } else { ++$failed } } if (($ok -eq $urls.Length) -and $SkipValid) { continue } diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 5cef1622a0..182526a8d7 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -493,7 +493,7 @@ function Invoke-AutoUpdate { $hasNote = $true } if ($Manifest.autoupdate.architecture) { - '64bit', '32bit', 'arm64' | ForEach-Object { + '64bit-v4', '64bit-v3', '64bit-v2', '64bit', '32bit', 'arm64' | ForEach-Object { if ($Manifest.autoupdate.architecture.$_.note) { $note += "`n$_-arch: $($Manifest.autoupdate.architecture.$_.note)" $hasNote = $true diff --git a/lib/core.ps1 b/lib/core.ps1 index eeaa2c9ad4..25506e7fe3 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1039,12 +1039,28 @@ function get_shim_path() { function Get-DefaultArchitecture { $arch = get_config DEFAULT_ARCHITECTURE - $system = if (${env:ProgramFiles(Arm)}) { - 'arm64' - } elseif ([System.Environment]::Is64BitOperatingSystem) { - '64bit' - } else { - '32bit' + $system = switch -Exact ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) { + 'Arm64' { return 'arm64' } + 'X64' { + $out = '64bit' + $kernel32 = Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru + return & { + # PF_AVX512F_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(41)) { + return $out += '-v4' + } + # PF_AVX2_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(40)) { + return $out += '-v3' + } + # PF_SSE4_2_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(38)) { + return $out += '-v2' + } + return $out + } + } + 'X32' { return '32bit' } } if ($null -eq $arch) { $arch = $system @@ -1065,9 +1081,12 @@ function Format-ArchitectureString($Architecture) { } $Architecture = $Architecture.ToString().ToLower() switch ($Architecture) { - { @('64bit', '64', 'x64', 'amd64', 'x86_64', 'x86-64') -contains $_ } { return '64bit' } - { @('32bit', '32', 'x86', 'i386', '386', 'i686') -contains $_ } { return '32bit' } - { @('arm64', 'arm', 'aarch64') -contains $_ } { return 'arm64' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('avx512', 'amd64-v4', 'amd64_v4', 'x64-v4', 'x64_v4', 'x86_64-v4', 'x86-64_v4')).Contains($_) } { return '64bit-v4' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('avx2', 'amd64-v3', 'amd64_v3', 'x64-v3', 'x64_v3', 'x86_64-v3', 'x86-64_v3')).Contains($_) } { return '64bit-v3' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('sse4.2', 'sse4_2', 'sse4-2', 'amd64-v2', 'amd64_v2', 'x64-v2', 'x64_v2', 'x86_64-v2', 'x86-64_v2')).Contains($_) } { return '64bit-v2' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('64bit', '64', 'x64', 'amd64', 'x86_64', 'x86-64')).Contains($_) } { return '64bit' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('32bit', '32', 'x86', 'i386', '386', 'i686')).Contains($_) } { return '32bit' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('arm64', 'arm', 'aarch64')).Contains($_) } { return 'arm64' } default { throw [System.ArgumentException] "Invalid architecture: '$Architecture'" } } } diff --git a/lib/install.ps1 b/lib/install.ps1 index 56cfdac924..4626403546 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -155,7 +155,7 @@ function Invoke-HookScript { [PSCustomObject] $Manifest, [Parameter(Mandatory = $true)] [Alias('Arch', 'Architecture')] - [ValidateSet('32bit', '64bit', 'arm64')] + [ValidateSet('32bit', '64bit-v4', '64bit-v3', '64bit-v2', '64bit', 'arm64')] [string] $ProcessorArchitecture ) diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 9ca618158b..9e613b66cb 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -111,16 +111,28 @@ function arch_specific($prop, $manifest, $architecture) { } function Get-SupportedArchitecture($manifest, $architecture) { - if ($architecture -eq 'arm64' -and ($manifest | ConvertToPrettyJson) -notmatch '[''"]arm64["'']') { - # Windows 10 enables existing unmodified x86 apps to run on Arm devices. - # Windows 11 adds the ability to run unmodified x64 Windows apps on Arm devices! - # Ref: https://learn.microsoft.com/en-us/windows/arm/overview - if ($WindowsBuild -ge 22000) { - # Windows 11 - $architecture = '64bit' - } else { - # Windows 10 - $architecture = '32bit' + if (!$manifest.architecture.$architecture) { + if ($architecture -eq 'arm64') { + # Windows 10 enables existing unmodified x86 apps to run on Arm devices. + # Windows 11 adds the ability to run unmodified x64 Windows apps on Arm devices! + # Ref: https://learn.microsoft.com/en-us/windows/arm/overview + if ($WindowsBuild -ge 22000) { + # Windows 11 + $architecture = '64bit' + } else { + # Windows 10 + $architecture = '32bit' + } + } elseif ($architecture[-3] -eq '-') { + $success = $false + for ($i = $architecture[-1] - [byte][char]'0'; $i > 1; --$i) { + $testArch = "64bit-v$i" + if ($manifest.architecture.$testArch) { + $success = $true + break + } + } + $architecture = if ($success) { $testArch } else { '64bit' } } } if (![String]::IsNullOrEmpty((arch_specific 'url' $manifest $architecture))) { diff --git a/libexec/scoop-config.ps1 b/libexec/scoop-config.ps1 index 6007bd6434..e77bbaec5d 100644 --- a/libexec/scoop-config.ps1 +++ b/libexec/scoop-config.ps1 @@ -54,7 +54,7 @@ # When a conflict is detected during updating, Scoop will auto-stash the uncommitted changes. # (Default is $false, which will abort the update) # -# default_architecture: 64bit|32bit|arm64 +# default_architecture: 32bit|64bit-v4|64bit-v3|64bit-v2|64bit|arm64 # Allow to configure preferred architecture for application installation. # If not specified, architecture is determined by system. # diff --git a/libexec/scoop-download.ps1 b/libexec/scoop-download.ps1 index f47a672e5a..1033e80663 100644 --- a/libexec/scoop-download.ps1 +++ b/libexec/scoop-download.ps1 @@ -17,7 +17,7 @@ # -f, --force Force download (overwrite cache) # -s, --skip-hash-check Skip hash verification (use with caution!) # -u, --no-update-scoop Don't update Scoop before downloading if it's outdated -# -a, --arch <32bit|64bit|arm64> Use the specified architecture, if the app supports it +# -a, --arch <32bit|64bit-v4|64bit-v3|64bit-v2|64bit|arm64> Use the specified architecture, if the app supports it . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' (indirectly) diff --git a/libexec/scoop-install.ps1 b/libexec/scoop-install.ps1 index 0fadcff09d..9e12dd8165 100644 --- a/libexec/scoop-install.ps1 +++ b/libexec/scoop-install.ps1 @@ -25,7 +25,7 @@ # -k, --no-cache Don't use the download cache # -s, --skip-hash-check Skip hash validation (use with caution!) # -u, --no-update-scoop Don't update Scoop before installing if it's outdated -# -a, --arch <32bit|64bit|arm64> Use the specified architecture, if the app supports it +# -a, --arch <32bit|64bit-v4|64bit-v3|64bit-v2|64bit|arm64> Use the specified architecture, if the app supports it . "$PSScriptRoot\..\lib\getopt.ps1" . "$PSScriptRoot\..\lib\json.ps1" # 'autoupdate.ps1' 'manifest.ps1' (indirectly) diff --git a/schema.json b/schema.json index 6c24d4da20..73f668c9eb 100644 --- a/schema.json +++ b/schema.json @@ -224,6 +224,15 @@ "64bit": { "$ref": "#/definitions/autoupdateArch" }, + "64bit-v2": { + "$ref": "#/definitions/autoupdateArch" + }, + "64bit-v3": { + "$ref": "#/definitions/autoupdateArch" + }, + "64bit-v4": { + "$ref": "#/definitions/autoupdateArch" + }, "arm64": { "$ref": "#/definitions/autoupdateArch" } @@ -542,6 +551,15 @@ "64bit": { "$ref": "#/definitions/architecture" }, + "64bit-v2": { + "$ref": "#/definitions/autoupdateArch" + }, + "64bit-v3": { + "$ref": "#/definitions/autoupdateArch" + }, + "64bit-v4": { + "$ref": "#/definitions/autoupdateArch" + }, "arm64": { "$ref": "#/definitions/architecture" } @@ -655,6 +673,21 @@ "url": false } }, + "64bit-v2": { + "properties": { + "url": false + } + }, + "64bit-v3": { + "properties": { + "url": false + } + }, + "64bit-v4": { + "properties": { + "url": false + } + }, "32bit": { "properties": { "url": false diff --git a/test/Scoop-Core.Tests.ps1 b/test/Scoop-Core.Tests.ps1 index d1cc9defe3..152993d883 100644 --- a/test/Scoop-Core.Tests.ps1 +++ b/test/Scoop-Core.Tests.ps1 @@ -367,6 +367,32 @@ Describe 'Format Architecture String' -Tag 'Scoop' { Format-ArchitectureString '386' | Should -Be '32bit' Format-ArchitectureString 'i686' | Should -Be '32bit' + Format-ArchitectureString 'avx512' | Should -Be '64bit-v4' + Format-ArchitectureString 'amd64-v4' | Should -Be '64bit-v4' + Format-ArchitectureString 'amd64_v4' | Should -Be '64bit-v4' + Format-ArchitectureString 'x64-v4' | Should -Be '64bit-v4' + Format-ArchitectureString 'x64_v4' | Should -Be '64bit-v4' + Format-ArchitectureString 'x86_64-v4' | Should -Be '64bit-v4' + Format-ArchitectureString 'x86-64_v4' | Should -Be '64bit-v4' + + Format-ArchitectureString 'avx2' | Should -Be '64bit-v3' + Format-ArchitectureString 'amd64-v3' | Should -Be '64bit-v3' + Format-ArchitectureString 'amd64_v3' | Should -Be '64bit-v3' + Format-ArchitectureString 'x64-v3' | Should -Be '64bit-v3' + Format-ArchitectureString 'x64_v3' | Should -Be '64bit-v3' + Format-ArchitectureString 'x86_64-v3' | Should -Be '64bit-v3' + Format-ArchitectureString 'x86-64_v3' | Should -Be '64bit-v3' + + Format-ArchitectureString 'sse4.2' | Should -Be '64bit-v2' + Format-ArchitectureString 'sse4_2' | Should -Be '64bit-v2' + Format-ArchitectureString 'sse4-2' | Should -Be '64bit-v2' + Format-ArchitectureString 'amd64-v2' | Should -Be '64bit-v2' + Format-ArchitectureString 'amd64_v2' | Should -Be '64bit-v2' + Format-ArchitectureString 'x64-v2' | Should -Be '64bit-v2' + Format-ArchitectureString 'x64_v2' | Should -Be '64bit-v2' + Format-ArchitectureString 'x86_64-v2' | Should -Be '64bit-v2' + Format-ArchitectureString 'x86-64_v2' | Should -Be '64bit-v2' + Format-ArchitectureString '64bit' | Should -Be '64bit' Format-ArchitectureString '64' | Should -Be '64bit' Format-ArchitectureString 'x64' | Should -Be '64bit' From f05f74e13ab5caf9b08cd90a94402e083e9646e0 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:40:53 -0400 Subject: [PATCH 2/9] Fix: Get-DefaultArchitecture function --- lib/core.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index 25506e7fe3..a0d754608a 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1047,15 +1047,15 @@ function Get-DefaultArchitecture { return & { # PF_AVX512F_INSTRUCTIONS_AVAILABLE if ($kernel32::IsProcessorFeaturePresent(41)) { - return $out += '-v4' + return $out + '-v4' } # PF_AVX2_INSTRUCTIONS_AVAILABLE if ($kernel32::IsProcessorFeaturePresent(40)) { - return $out += '-v3' + return $out + '-v3' } # PF_SSE4_2_INSTRUCTIONS_AVAILABLE if ($kernel32::IsProcessorFeaturePresent(38)) { - return $out += '-v2' + return $out + '-v2' } return $out } From fe4c3620631d99eeb875751229e2eba1cea423bc Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Sat, 1 Jun 2024 09:11:06 -0400 Subject: [PATCH 3/9] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1547a91719..1ac61580da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ ### Features +- **install:** Add support for x64 microarchitectures ([#5674](https://github.com/ScoopInstaller/Scoop/pull/5674)) - **scoop-search:** Use SQLite for caching apps to speed up local search ([#5851](https://github.com/ScoopInstaller/Scoop/issues/5851), [#5918](https://github.com/ScoopInstaller/Scoop/issues/5918), [#5946](https://github.com/ScoopInstaller/Scoop/issues/5946), [#5949](https://github.com/ScoopInstaller/Scoop/issues/5949), [#5955](https://github.com/ScoopInstaller/Scoop/issues/5955), [#5966](https://github.com/ScoopInstaller/Scoop/issues/5966), [#5967](https://github.com/ScoopInstaller/Scoop/issues/5967), [#5981](https://github.com/ScoopInstaller/Scoop/issues/5981)) - **core:** New cache filename format ([#5929](https://github.com/ScoopInstaller/Scoop/issues/5929), [#5944](https://github.com/ScoopInstaller/Scoop/issues/5944)) - **decompress:** Use innounp-unicode as default Inno Setup Unpacker ([#6028](https://github.com/ScoopInstaller/Scoop/issues/6028)) From 46e50023b65dcf1d0100934f28936009aadd5f02 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:52:22 -0400 Subject: [PATCH 4/9] Wrap `$system` switch in an anon function --- lib/core.ps1 | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index a0d754608a..f04d92efa6 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1039,28 +1039,30 @@ function get_shim_path() { function Get-DefaultArchitecture { $arch = get_config DEFAULT_ARCHITECTURE - $system = switch -Exact ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) { - 'Arm64' { return 'arm64' } - 'X64' { - $out = '64bit' - $kernel32 = Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru - return & { - # PF_AVX512F_INSTRUCTIONS_AVAILABLE - if ($kernel32::IsProcessorFeaturePresent(41)) { - return $out + '-v4' - } - # PF_AVX2_INSTRUCTIONS_AVAILABLE - if ($kernel32::IsProcessorFeaturePresent(40)) { - return $out + '-v3' - } - # PF_SSE4_2_INSTRUCTIONS_AVAILABLE - if ($kernel32::IsProcessorFeaturePresent(38)) { - return $out + '-v2' + $system = & { + switch -Exact ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture) { + 'Arm64' { return 'arm64' } + 'X64' { + $out = '64bit' + $kernel32 = Add-Type -MemberDefinition '[DllImport("kernel32.dll")] public static extern bool IsProcessorFeaturePresent(int ProcessorFeature);' -Name 'Kernel32' -Namespace 'Win32' -PassThru + return & { + # PF_AVX512F_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(41)) { + return $out + '-v4' + } + # PF_AVX2_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(40)) { + return $out + '-v3' + } + # PF_SSE4_2_INSTRUCTIONS_AVAILABLE + if ($kernel32::IsProcessorFeaturePresent(38)) { + return $out + '-v2' + } + return $out } - return $out } + 'X32' { return '32bit' } } - 'X32' { return '32bit' } } if ($null -eq $arch) { $arch = $system From 2aef8f5216ec276759a71674436582965bee2776 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Tue, 3 Oct 2023 23:17:42 -0400 Subject: [PATCH 5/9] schema: Fix bad copy/paste --- schema.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schema.json b/schema.json index 73f668c9eb..ce479d4b48 100644 --- a/schema.json +++ b/schema.json @@ -552,13 +552,13 @@ "$ref": "#/definitions/architecture" }, "64bit-v2": { - "$ref": "#/definitions/autoupdateArch" + "$ref": "#/definitions/architecture" }, "64bit-v3": { - "$ref": "#/definitions/autoupdateArch" + "$ref": "#/definitions/architecture" }, "64bit-v4": { - "$ref": "#/definitions/autoupdateArch" + "$ref": "#/definitions/architecture" }, "arm64": { "$ref": "#/definitions/architecture" From c4eb464582214751f80be4eb39fb9662c48bd6ce Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Wed, 4 Oct 2023 00:34:28 -0400 Subject: [PATCH 6/9] fix: Add actual arch name in set --- lib/core.ps1 | 6 +++--- test/Scoop-Core.Tests.ps1 | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/core.ps1 b/lib/core.ps1 index f04d92efa6..ad04e5001a 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1083,9 +1083,9 @@ function Format-ArchitectureString($Architecture) { } $Architecture = $Architecture.ToString().ToLower() switch ($Architecture) { - { ([System.Collections.Generic.HashSet[String]][string[]]@('avx512', 'amd64-v4', 'amd64_v4', 'x64-v4', 'x64_v4', 'x86_64-v4', 'x86-64_v4')).Contains($_) } { return '64bit-v4' } - { ([System.Collections.Generic.HashSet[String]][string[]]@('avx2', 'amd64-v3', 'amd64_v3', 'x64-v3', 'x64_v3', 'x86_64-v3', 'x86-64_v3')).Contains($_) } { return '64bit-v3' } - { ([System.Collections.Generic.HashSet[String]][string[]]@('sse4.2', 'sse4_2', 'sse4-2', 'amd64-v2', 'amd64_v2', 'x64-v2', 'x64_v2', 'x86_64-v2', 'x86-64_v2')).Contains($_) } { return '64bit-v2' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('64bit-v4', '64bit_v4', 'avx512', 'amd64-v4', 'amd64_v4', 'x64-v4', 'x64_v4', 'x86_64-v4', 'x86-64_v4')).Contains($_) } { return '64bit-v4' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('64bit-v3', '64bit_v3', 'avx2', 'amd64-v3', 'amd64_v3', 'x64-v3', 'x64_v3', 'x86_64-v3', 'x86-64_v3')).Contains($_) } { return '64bit-v3' } + { ([System.Collections.Generic.HashSet[String]][string[]]@('64bit-v2', '64bit_v2', 'sse4.2', 'sse4_2', 'sse4-2', 'amd64-v2', 'amd64_v2', 'x64-v2', 'x64_v2', 'x86_64-v2', 'x86-64_v2')).Contains($_) } { return '64bit-v2' } { ([System.Collections.Generic.HashSet[String]][string[]]@('64bit', '64', 'x64', 'amd64', 'x86_64', 'x86-64')).Contains($_) } { return '64bit' } { ([System.Collections.Generic.HashSet[String]][string[]]@('32bit', '32', 'x86', 'i386', '386', 'i686')).Contains($_) } { return '32bit' } { ([System.Collections.Generic.HashSet[String]][string[]]@('arm64', 'arm', 'aarch64')).Contains($_) } { return 'arm64' } diff --git a/test/Scoop-Core.Tests.ps1 b/test/Scoop-Core.Tests.ps1 index 152993d883..7ce838cee7 100644 --- a/test/Scoop-Core.Tests.ps1 +++ b/test/Scoop-Core.Tests.ps1 @@ -367,6 +367,8 @@ Describe 'Format Architecture String' -Tag 'Scoop' { Format-ArchitectureString '386' | Should -Be '32bit' Format-ArchitectureString 'i686' | Should -Be '32bit' + Format-ArchitectureString '64bit-v4' | Should -Be '64bit-v4' + Format-ArchitectureString '64bit_v4' | Should -Be '64bit-v4' Format-ArchitectureString 'avx512' | Should -Be '64bit-v4' Format-ArchitectureString 'amd64-v4' | Should -Be '64bit-v4' Format-ArchitectureString 'amd64_v4' | Should -Be '64bit-v4' @@ -375,6 +377,8 @@ Describe 'Format Architecture String' -Tag 'Scoop' { Format-ArchitectureString 'x86_64-v4' | Should -Be '64bit-v4' Format-ArchitectureString 'x86-64_v4' | Should -Be '64bit-v4' + Format-ArchitectureString '64bit_v3' | Should -Be '64bit-v3' + Format-ArchitectureString '64bit_v3' | Should -Be '64bit-v3' Format-ArchitectureString 'avx2' | Should -Be '64bit-v3' Format-ArchitectureString 'amd64-v3' | Should -Be '64bit-v3' Format-ArchitectureString 'amd64_v3' | Should -Be '64bit-v3' @@ -383,6 +387,8 @@ Describe 'Format Architecture String' -Tag 'Scoop' { Format-ArchitectureString 'x86_64-v3' | Should -Be '64bit-v3' Format-ArchitectureString 'x86-64_v3' | Should -Be '64bit-v3' + Format-ArchitectureString '64bit-v2' | Should -Be '64bit-v2' + Format-ArchitectureString '64bit_v2' | Should -Be '64bit-v2' Format-ArchitectureString 'sse4.2' | Should -Be '64bit-v2' Format-ArchitectureString 'sse4_2' | Should -Be '64bit-v2' Format-ArchitectureString 'sse4-2' | Should -Be '64bit-v2' From 6af7a93f428314e2d8a83d25979c01fa65731058 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Wed, 4 Oct 2023 01:16:58 -0400 Subject: [PATCH 7/9] fix: Wrong operator usage --- lib/manifest.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 9e613b66cb..00ac8379e6 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -125,7 +125,7 @@ function Get-SupportedArchitecture($manifest, $architecture) { } } elseif ($architecture[-3] -eq '-') { $success = $false - for ($i = $architecture[-1] - [byte][char]'0'; $i > 1; --$i) { + for ($i = $architecture[-1] - [byte][char]'0'; $i -gt 1; --$i) { $testArch = "64bit-v$i" if ($manifest.architecture.$testArch) { $success = $true From a7332cb55240c402f89ffc9975583dfc2381ad5a Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Tue, 17 Oct 2023 06:21:16 -0400 Subject: [PATCH 8/9] arm64 fallback: assign to statements --- lib/manifest.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 00ac8379e6..b8b0902c93 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -116,12 +116,12 @@ function Get-SupportedArchitecture($manifest, $architecture) { # Windows 10 enables existing unmodified x86 apps to run on Arm devices. # Windows 11 adds the ability to run unmodified x64 Windows apps on Arm devices! # Ref: https://learn.microsoft.com/en-us/windows/arm/overview - if ($WindowsBuild -ge 22000) { + $architecture = if ($WindowsBuild -ge 22000) { # Windows 11 - $architecture = '64bit' + '64bit' } else { # Windows 10 - $architecture = '32bit' + '32bit' } } elseif ($architecture[-3] -eq '-') { $success = $false From e901fd889bb2852ec37bad3ca76e4b40c426fbb7 Mon Sep 17 00:00:00 2001 From: Brian <18603393+brian6932@users.noreply.github.com> Date: Sat, 25 May 2024 23:52:50 -0400 Subject: [PATCH 9/9] missed a validation when rebasing --- lib/install.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/install.ps1 b/lib/install.ps1 index 4626403546..64de3bc541 100644 --- a/lib/install.ps1 +++ b/lib/install.ps1 @@ -95,7 +95,7 @@ function Invoke-Installer { [psobject] $Manifest, [Alias('Arch', 'Architecture')] - [ValidateSet('32bit', '64bit', 'arm64')] + [ValidateSet('32bit', '64bit-v4', '64bit-v3', '64bit-v2', '64bit', 'arm64')] [string] $ProcessorArchitecture, [string]