Skip to content
Closed
Show file tree
Hide file tree
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
37 changes: 23 additions & 14 deletions .github/actions/install-winget/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,35 @@ runs:
run: |
Set-StrictMode -Version Latest

# Use Install-PSResource (PSResourceGet, built into PowerShell 7.4+) instead of the
# legacy Install-Module. PSResourceGet has its own repository system that is independent
# of the old PowerShellGet/NuGet pipeline, which avoids transient PSGallery registration
# failures on freshly provisioned runners.
# See https://github.com/actions/runner-images/issues/13758
if (-not (Get-PSResourceRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
Register-PSResourceRepository -PSGallery -Trusted
}
Comment on lines +113 to +120
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes PSResourceGet cmdlets (Get-PSResourceRepository / Find-PSResource / Install-PSResource) are available (PowerShell 7.4+ per the comment). If the runner executes this action under Windows PowerShell 5.1 or older PowerShell 7.x, the action will fail immediately. Add an explicit version/cmdlet availability check and either (a) install/enable PSResourceGet first, or (b) fall back to the previous Install-Module path when PSResourceGet isn't available.

See below for a potential fix:

        $cliVersion = (winget --version).Trim() -replace '^v', ''
        $cliMajor = ($cliVersion -split '\.')[0]
        Write-Host "WinGet CLI version: $cliVersion (major: $cliMajor)"

        # Prefer PSResourceGet (PowerShell 7.4+) when available, but fall back to
        # PowerShellGet's Install-Module on older PowerShell versions.
        if (Get-Command -Name Get-PSResourceRepository -ErrorAction SilentlyContinue) {
            Write-Host "PSResourceGet detected. Using Install-PSResource path."

            # Use Install-PSResource (PSResourceGet, built into PowerShell 7.4+) instead of the
            # legacy Install-Module. PSResourceGet has its own repository system that is independent
            # of the old PowerShellGet/NuGet pipeline, which avoids transient PSGallery registration
            # failures on freshly provisioned runners.
            # See https://github.com/actions/runner-images/issues/13758
            if (-not (Get-PSResourceRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
                Register-PSResourceRepository -PSGallery -Trusted
            }

            # Try exact match first, then best matching major version, then latest
            $found = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -ErrorAction SilentlyContinue
            if ($found) {
                Write-Host "Installing exact matching module version via PSResourceGet: $cliVersion"
                Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -TrustRepository -Quiet
            } else {
                $allVersions = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version "[$cliMajor.0.0, $([int]$cliMajor + 1).0.0)" -ErrorAction SilentlyContinue
                if ($allVersions) {
                    $best = ($allVersions | Sort-Object Version -Descending | Select-Object -First 1).Version
                    Write-Host "Exact match not found. Installing latest module with matching major version via PSResourceGet: $best"
                    Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $best -TrustRepository -Quiet
                } else {
                    Write-Warning "No module with major version $cliMajor found on PSGallery. Installing latest version via PSResourceGet."
                    Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -TrustRepository -Quiet
                }
            }
        }
        else {
            Write-Warning "PSResourceGet cmdlets not found. Falling back to PowerShellGet (Install-Module)."

            if (-not (Get-Command -Name Install-Module -ErrorAction SilentlyContinue)) {
                Write-Error "Neither PSResourceGet (Install-PSResource) nor PowerShellGet (Install-Module) is available. Cannot install Microsoft.WinGet.Client."
                exit 1
            }

            try {
                # Install latest Microsoft.WinGet.Client from PSGallery for this fallback path.
                # This mirrors the previous Install-Module-based behavior on older PowerShell versions.
                Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Scope CurrentUser -Force -AllowClobber -ErrorAction Stop
            }
            catch {
                Write-Error "Failed to install Microsoft.WinGet.Client via Install-Module: $($_.Exception.Message)"
                exit 1
            }
        }

        $module = Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1
        if (-not $module) {
            Write-Error "Microsoft.WinGet.Client module was not found after installation."
            exit 1
        }

        $moduleVersion = $module.Version.ToString()

Copilot uses AI. Check for mistakes.

$cliVersion = (winget --version).Trim() -replace '^v', ''
$cliMajor = ($cliVersion -split '\.')[0]
Write-Host "WinGet CLI version: $cliVersion (major: $cliMajor)"

# Try exact match first, then best matching major version, then latest
$matchingModule = Find-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $cliVersion -ErrorAction SilentlyContinue
if ($matchingModule) {
Write-Host "Installing exact matching module version: $cliVersion"
Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $cliVersion -Force
$found = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -ErrorAction SilentlyContinue
if ($found) {
Write-Host "Installing exact matching module version: $cliVersion"
Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -TrustRepository -Quiet
Comment on lines +127 to +130
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes PSResourceGet cmdlets (Get-PSResourceRepository / Find-PSResource / Install-PSResource) are available (PowerShell 7.4+ per the comment). If the runner executes this action under Windows PowerShell 5.1 or older PowerShell 7.x, the action will fail immediately. Add an explicit version/cmdlet availability check and either (a) install/enable PSResourceGet first, or (b) fall back to the previous Install-Module path when PSResourceGet isn't available.

See below for a potential fix:

        $psResourceGetAvailable = $false
        if (Get-Command -Name Install-PSResource -ErrorAction SilentlyContinue) {
            $psResourceGetAvailable = $true
        }

        $cliVersion = (winget --version).Trim() -replace '^v', ''
        $cliMajor = ($cliVersion -split '\.')[0]
        Write-Host "WinGet CLI version: $cliVersion (major: $cliMajor)"

        if ($psResourceGetAvailable) {
            # Use Install-PSResource (PSResourceGet, built into PowerShell 7.4+) instead of the
            # legacy Install-Module. PSResourceGet has its own repository system that is independent
            # of the old PowerShellGet/NuGet pipeline, which avoids transient PSGallery registration
            # failures on freshly provisioned runners.
            # See https://github.com/actions/runner-images/issues/13758
            if (-not (Get-PSResourceRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
                Register-PSResourceRepository -PSGallery -Trusted
            }

            # Try exact match first, then best matching major version, then latest
            $found = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -ErrorAction SilentlyContinue
            if ($found) {
                Write-Host "Installing exact matching module version via PSResourceGet: $cliVersion"
                Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $cliVersion -TrustRepository -Quiet
            } else {
                $allVersions = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version "[$cliMajor.0.0, $([int]$cliMajor + 1).0.0)" -ErrorAction SilentlyContinue
                if ($allVersions) {
                    $best = ($allVersions | Sort-Object Version -Descending | Select-Object -First 1).Version
                    Write-Host "Exact match not found. Installing latest module with matching major version via PSResourceGet: $best"
                    Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $best -TrustRepository -Quiet
                } else {
                    Write-Warning "No module with major version $cliMajor found on PSGallery. Installing latest version via PSResourceGet."
                    Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -TrustRepository -Quiet
                }
            }
        } else {
            Write-Host "PSResourceGet cmdlets not available. Falling back to PowerShellGet (Install-Module/Find-Module)."

            # Ensure PSGallery is registered and trusted for PowerShellGet
            if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
                try {
                    Register-PSRepository -Default -ErrorAction Stop
                } catch {
                    Write-Warning "Failed to register default PSGallery repository via PowerShellGet: $_"
                }
            }

            try {
                Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction SilentlyContinue
            } catch {
                Write-Warning "Failed to set PSGallery as Trusted via PowerShellGet: $_"
            }

            # Try exact match first, then best matching major version, then latest using PowerShellGet
            $found = Find-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $cliVersion -ErrorAction SilentlyContinue
            if ($found) {
                Write-Host "Installing exact matching module version via PowerShellGet: $cliVersion"
                Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $cliVersion -Scope CurrentUser -Force
            } else {
                $allVersions = Find-Module -Name Microsoft.WinGet.Client -Repository PSGallery -AllVersions -ErrorAction SilentlyContinue |
                    Where-Object { $_.Version.Major -eq [int]$cliMajor }
                if ($allVersions) {
                    $best = ($allVersions | Sort-Object Version -Descending | Select-Object -First 1).Version
                    Write-Host "Exact match not found. Installing latest module with matching major version via PowerShellGet: $best"
                    Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $best -Scope CurrentUser -Force
                } else {
                    Write-Warning "No module with major version $cliMajor found on PSGallery. Installing latest version via PowerShellGet."
                    Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Scope CurrentUser -Force
                }

Copilot uses AI. Check for mistakes.
} else {
$allVersions = Find-Module -Name Microsoft.WinGet.Client -Repository PSGallery -AllVersions -ErrorAction SilentlyContinue
$majorMatch = $allVersions | Where-Object { ($_.Version.ToString() -split '\.')[0] -eq $cliMajor } | Select-Object -First 1
if ($majorMatch) {
Write-Host "Exact match not found. Installing latest module with matching major version: $($majorMatch.Version)"
Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -RequiredVersion $majorMatch.Version -Force
} else {
Write-Warning "No module with major version $cliMajor found on PSGallery. Installing latest version."
Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
}
$allVersions = Find-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version "[$cliMajor.0.0, $([int]$cliMajor + 1).0.0)" -ErrorAction SilentlyContinue
if ($allVersions) {
$best = ($allVersions | Sort-Object Version -Descending | Select-Object -First 1).Version
Write-Host "Exact match not found. Installing latest module with matching major version: $best"
Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -Version $best -TrustRepository -Quiet
} else {
Write-Warning "No module with major version $cliMajor found on PSGallery. Installing latest version."
Install-PSResource -Name Microsoft.WinGet.Client -Repository PSGallery -TrustRepository -Quiet
}
}

$moduleVersion = (Get-InstalledModule Microsoft.WinGet.Client).Version.ToString()
$moduleVersion = (Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1).Version.ToString()
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get-Module -ListAvailable ... | Select-Object -First 1 does not guarantee you get the version that was just installed (or the highest version) because ordering is not reliable. Sort by Version descending before selecting, or query the installed resource directly (e.g., via the PSResourceGet installed-resource cmdlet) to ensure the reported version is deterministic and accurate.

Suggested change
$moduleVersion = (Get-Module -ListAvailable Microsoft.WinGet.Client | Select-Object -First 1).Version.ToString()
$moduleVersion = (Get-Module -ListAvailable Microsoft.WinGet.Client | Sort-Object Version -Descending | Select-Object -First 1).Version.ToString()

Copilot uses AI. Check for mistakes.
Write-Host "Installed module version: $moduleVersion"
3 changes: 3 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2

rust_toolchain:
- stable
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2

rust_toolchain:
- stable
Expand All @@ -56,9 +59,8 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6

- name: Install Winget PowerShell Module
shell: pwsh
run: Install-Module -Name Microsoft.WinGet.Client -Repository PSGallery -Force
- name: Install Winget
uses: ./.github/actions/install-winget

- name: Install LLVM ${{ matrix.llvm }}
uses: ./.github/actions/install-llvm
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2

rust_toolchain:
- stable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2

rust_toolchain:
- stable
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/local-development-makefile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2

runs-on: ${{ matrix.runner.name }}

Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:

llvm:
- 17.0.6
- 19.1.7
- 20.1.8
- 21.1.2
Comment on lines 34 to +38
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same LLVM version list is duplicated across multiple workflows (test, build, lint, docs, codeql, local-development-makefile). This increases the chance of workflows drifting out of sync. Consider centralizing the LLVM version matrix (e.g., via a reusable workflow invoked by each job, or by defining a single JSON list in one place and using fromJSON(...) in each workflow) so updates happen once.

Copilot uses AI. Check for mistakes.

rust_toolchain:
- stable
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ This project was built with support of WDM, KMDF, and UMDF drivers in mind, as w
### Build Requirements

* Binding generation via `bindgen` requires `libclang`. The easiest way to acquire this is via `winget`
* `winget install -i LLVM.LLVM --version 17.0.6 --force`
* `winget install -i LLVM.LLVM`
* Ensure you select the GUI option to add LLVM to the PATH
* LLVM 18 has a bug that causes bindings to fail to generate for ARM64. Continue using LLVM 17 until LLVM 19 comes out with [the fix](https://github.com/llvm/llvm-project/pull/93235). See [this](https://github.com/rust-lang/rust-bindgen/issues/2842) for more details.
* See list of [tested/supported versions](https://github.com/microsoft/windows-drivers-rs/blob/main/.github/workflows/build.yaml#L39) in the [CI workflow](./.github/workflows/build.yaml)
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README links to a specific line number in build.yaml (#L39), which is brittle and will easily drift as the workflow changes. Prefer linking to the file without a line anchor (or to a stable section/README that enumerates supported LLVM versions) so the documentation stays accurate over time.

Suggested change
* See list of [tested/supported versions](https://github.com/microsoft/windows-drivers-rs/blob/main/.github/workflows/build.yaml#L39) in the [CI workflow](./.github/workflows/build.yaml)
* See list of [tested/supported versions](https://github.com/microsoft/windows-drivers-rs/blob/main/.github/workflows/build.yaml) in the [CI workflow](./.github/workflows/build.yaml)

Copilot uses AI. Check for mistakes.
* To execute post-build tasks (ie. `inf2cat`, `infverif`, etc.), `cargo make` is used
* `cargo install --locked cargo-make --no-default-features --features tls-native`

Expand Down
Loading