diff --git a/.github/scripts/nuget-install-wdk.ps1 b/.github/scripts/nuget-install-wdk.ps1 new file mode 100644 index 00000000..0b32da60 --- /dev/null +++ b/.github/scripts/nuget-install-wdk.ps1 @@ -0,0 +1,121 @@ +param ( + [string]$wdkVersion +) + +# Extract the first three parts of the version +$majorVersionNum = ($wdkVersion -split '\.')[0..2] -join '.' + +Write-Host "Installing WDK version $wdkVersion" +Write-Host "Major version number: $majorVersionNum" + +# Update the packages.config file with the version passed as parameter +$packagesConfigPath = ".\packages.config" + +if (Test-Path $packagesConfigPath) { + [xml]$packagesConfig = Get-Content $packagesConfigPath + + foreach ($package in $packagesConfig.packages.package) { + if ($package.id -like "Microsoft.Windows.*") { + $package.version = $wdkVersion + } + } + + $packagesConfig.Save($packagesConfigPath) + Write-Host "Updated packages.config with version $wdkVersion" +} else { + Write-Error "packages.config file not found" +} + +# Install WDK using NuGet +try { + nuget restore .\packages.config -PackagesDirectory C:\WDK + Write-Host "WDK installed at C:\WDK" +} catch { + Write-Error "Failed to restore packages using NuGet. Error: $_" + exit 1 +} + +$folders = @( + "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion", + "C:\WDK\Microsoft.Windows.SDK.CPP.x64.$wdkVersion", + "C:\WDK\Microsoft.Windows.SDK.CPP.arm64.$wdkVersion", + "C:\WDK\Microsoft.Windows.WDK.ARM64.$wdkVersion", + "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion" +) +foreach ($folder in $folders) { +if (-Not (Test-Path $folder)) { + Write-Error "Required folder $folder is missing." + exit 1 + } +} +function Copy-File { + param ( + [string]$sourcePath, + [string]$destinationPath, + [string]$fileName + ) + + if (Test-Path $sourcePath) { + Copy-Item -Path $sourcePath -Destination $destinationPath -Force + Write-Host "Copied $fileName to $destinationPath" + } else { + Write-Error "$fileName not found at $sourcePath" + } +} + +# Copying signtool to WDK bin folder +$signtoolx64 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x64\signtool.exe" +$signtoolX86 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x86\signtool.exe" +$destinationx64 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x64" +$destinationX86 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x86" + +Copy-File -sourcePath $signtoolX64 -destinationPath $destinationX64 -fileName "signtool.exe" +Copy-File -sourcePath $signtoolX86 -destinationPath $destinationX86 -fileName "signtool.exe" + +# Copying certmgr to WDK bin folder +$certmgrx86 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x86\certmgr.exe" +$certmgrX64 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x64\certmgr.exe" +$certmgrARM64 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\arm64\certmgr.exe" +$destinationx86 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x86" +$destinationx64 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x64" +$destinationARM64 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\ARM64" + +Copy-File -sourcePath $certmgrx86 -destinationPath $destinationx86 -fileName "certmgr.exe" +Copy-File -sourcePath $certmgrX64 -destinationPath $destinationx64 -fileName "certmgr.exe" +Copy-File -sourcePath $certmgrARM64 -destinationPath $destinationARM64 -fileName "certmgr.exe" + +# Copying makecert to WDK bin folder +$makecertx86 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x86\MakeCert.exe" +$makecertX64 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\x64\MakeCert.exe" +$makecertARM64 = "C:\WDK\Microsoft.Windows.SDK.CPP.$wdkVersion\c\bin\$majorVersionNum.0\arm64\MakeCert.exe" +$destinationx86 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x86" +$destinationx64 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\x64" +$destinationARM64 = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\bin\$majorVersionNum.0\ARM64" + +Copy-File -sourcePath $makecertx86 -destinationPath $destinationx86 -fileName "MakeCert.exe" +Copy-File -sourcePath $makecertX64 -destinationPath $destinationx64 -fileName "MakeCert.exe" +Copy-File -sourcePath $makecertARM64 -destinationPath $destinationARM64 -fileName "MakeCert.exe" + +function Copy-Folder { + param ( + [string]$sourceFolder, + [string]$destinationFolder + ) + + if (Test-Path $sourceFolder) { + Copy-Item -Path $sourceFolder -Destination $destinationFolder -Recurse -Force + Write-Host "Copied $sourceFolder to $destinationFolder" + } else { + Write-Error "Source folder $sourceFolder not found" + } +} + +# Copying km, um, kmdf, umdf ARM64 headers to x64 folders +Copy-Folder -sourceFolder "C:\WDK\Microsoft.Windows.WDK.ARM64.$wdkVersion\c\Lib\$majorVersionNum.0\km\arm64" -destinationFolder "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\Lib\$majorVersionNum.0\km" +Copy-Folder -sourceFolder "C:\WDK\Microsoft.Windows.WDK.ARM64.$wdkVersion\c\Lib\$majorVersionNum.0\um\arm64" -destinationFolder "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\Lib\$majorVersionNum.0\um" +Copy-Folder -sourceFolder "C:\WDK\Microsoft.Windows.WDK.ARM64.$wdkVersion\c\Lib\wdf\kmdf\ARM64" -destinationFolder "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\Lib\wdf\kmdf" +Copy-Folder -sourceFolder "C:\WDK\Microsoft.Windows.WDK.ARM64.$wdkVersion\c\Lib\wdf\umdf\ARM64" -destinationFolder "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c\Lib\wdf\umdf" + +# Set WDKContentRoot environment variable +$NugetWdkContentRoot = "C:\WDK\Microsoft.Windows.WDK.x64.$wdkVersion\c" +Write-Output "WDKContentRoot=$NugetWdkContentRoot" >> $env:GITHUB_ENV \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3c916bf9..7f3a3f55 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,6 +20,10 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + # Use versions numbers for NuGet WDK packages + # - 10.0.26100.1882 + # - 10.0.26100.1591 + - 10.0.26100.1 llvm: - 17.0.6 @@ -57,6 +61,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -65,6 +70,17 @@ jobs: Write-Host "Installing ${{ matrix.wdk }}..." Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) uses: dtolnay/rust-toolchain@master diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index f7b28a66..38fe7fd3 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -18,6 +18,7 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + - 10.0.26100.1 llvm: - 17.0.6 @@ -59,6 +60,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -68,6 +70,17 @@ jobs: Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } + - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index 56f9412b..d85b30ff 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -18,6 +18,7 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + - 10.0.26100.1 llvm: - 17.0.6 @@ -55,6 +56,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -64,6 +66,17 @@ jobs: Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } + - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 6bef9782..2c4eff73 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -17,6 +17,7 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + - 10.0.26100.1 llvm: - 17.0.6 @@ -54,6 +55,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -63,6 +65,17 @@ jobs: Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } + - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) uses: dtolnay/rust-toolchain@master with: diff --git a/.github/workflows/local-development-makefile.yaml b/.github/workflows/local-development-makefile.yaml index 79cf5bad..377eef39 100644 --- a/.github/workflows/local-development-makefile.yaml +++ b/.github/workflows/local-development-makefile.yaml @@ -18,6 +18,7 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + - 10.0.26100.1 llvm: - 17.0.6 @@ -46,6 +47,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -55,6 +57,16 @@ jobs: Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } - name: Install Nightly Rust Toolchain (${{ matrix.target_triple }}) uses: dtolnay/rust-toolchain@nightly with: diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2f63b1e1..d9e78685 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,6 +15,7 @@ jobs: matrix: wdk: - Microsoft.WindowsWDK.10.0.22621 # NI WDK + - 10.0.26100.1 llvm: - 17.0.6 @@ -52,6 +53,7 @@ jobs: clang --version - name: Install WDK (${{ matrix.wdk }}) + if: matrix.wdk == 'Microsoft.WindowsWDK.10.0.22621' run: | if ((Get-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals).Id -eq '${{ matrix.wdk }}') { Write-Host "${{ matrix.wdk }} is already installed. Attempting to update..." @@ -61,6 +63,17 @@ jobs: Install-WinGetPackage -Id ${{ matrix.wdk }} -Source winget -MatchOption Equals -Mode Silent -Force } + - name: Install ${{ matrix.wdk }} (NuGet) + if: startsWith(matrix.wdk, '10.0.') + run: | + $wdk = '${{ matrix.wdk }}' + if ($wdk -match '^10\.0\.\d{5}\.\d{1,4}$') { + ./.github/scripts/nuget-install-wdk.ps1 -wdkVersion $wdk + } else { + Write-Host "WDK version $wdk does not match the required format 10.0.{5 digit number}.{1 to 4 digit number}" + exit 1 + } + - name: Install Rust Toolchain (${{ matrix.rust_toolchain }}) uses: dtolnay/rust-toolchain@master with: diff --git a/crates/wdk-build/src/cargo_make.rs b/crates/wdk-build/src/cargo_make.rs index 26be9942..884af8da 100644 --- a/crates/wdk-build/src/cargo_make.rs +++ b/crates/wdk-build/src/cargo_make.rs @@ -516,7 +516,9 @@ pub fn setup_path() -> Result, ConfigError> { let Some(wdk_content_root) = detect_wdk_content_root() else { return Err(ConfigError::WdkContentRootDetectionError); }; + let version = get_latest_windows_sdk_version(&wdk_content_root.join("Lib"))?; + let host_arch = CpuArchitecture::try_from_cargo_str(env::consts::ARCH) .expect("The rust standard library should always set env::consts::ARCH"); @@ -524,6 +526,7 @@ pub fn setup_path() -> Result, ConfigError> { .join(format!("bin/{version}")) .canonicalize()? .strip_extended_length_path_prefix()?; + let host_windows_sdk_ver_bin_path = match host_arch { CpuArchitecture::Amd64 => wdk_bin_root .join(host_arch.as_windows_str()) diff --git a/packages.config b/packages.config new file mode 100644 index 00000000..2a84a878 --- /dev/null +++ b/packages.config @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs index c7053e02..1a6b0475 100644 --- a/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs +++ b/tests/mixed-package-kmdf-workspace/crates/driver/src/lib.rs @@ -19,20 +19,7 @@ use wdk::println; #[cfg(not(test))] use wdk_alloc::WdkAllocator; use wdk_sys::{ - call_unsafe_wdf_function_binding, - ntddk::DbgPrint, - DRIVER_OBJECT, - NTSTATUS, - PCUNICODE_STRING, - ULONG, - UNICODE_STRING, - WCHAR, - WDFDEVICE, - WDFDEVICE_INIT, - WDFDRIVER, - WDF_DRIVER_CONFIG, - WDF_NO_HANDLE, - WDF_NO_OBJECT_ATTRIBUTES, + call_unsafe_wdf_function_binding, ntddk::DbgPrint, DRIVER_OBJECT, NTSTATUS, PCUNICODE_STRING, PDRIVER_OBJECT, ULONG, UNICODE_STRING, WCHAR, WDFDEVICE, WDFDEVICE_INIT, WDFDRIVER, WDF_DRIVER_CONFIG, WDF_NO_HANDLE, WDF_NO_OBJECT_ATTRIBUTES }; #[cfg(not(test))]