[CmdletBinding()]
param([string]$OutputDirectory = (Join-Path $PSScriptRoot '..\artifacts\driver-umdf'))
$ErrorActionPreference = 'Stop'
$output = [IO.Path]::GetFullPath($OutputDirectory)
$obj = Join-Path $output 'obj'
$null = New-Item -ItemType Directory -Path $obj -Force
dotnet restore (Join-Path $PSScriptRoot 'BuildTools.csproj') --verbosity quiet
if ($LASTEXITCODE) { throw 'WDK restore failed.' }
$assets = Get-Content -LiteralPath (Join-Path $PSScriptRoot 'obj\project.assets.json') -Raw | ConvertFrom-Json
function PackagePath([string]$id, [string]$version) {
foreach ($folder in $assets.packageFolders.PSObject.Properties.Name) {
$candidate = Join-Path $folder "$id\$version\c"
if (Test-Path -LiteralPath $candidate) { return $candidate }
}
throw "Package missing: $id $version"
}
$wdk = PackagePath 'microsoft.windows.wdk.x64' '10.0.26100.6584'
$sdk = PackagePath 'microsoft.windows.sdk.cpp' '10.0.26100.1'
$sdk64 = PackagePath 'microsoft.windows.sdk.cpp.x64' '10.0.26100.1'
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
$vs = & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (!$vs) { throw 'Install Visual Studio Desktop development with C++ build tools.' }
$vcVersion = (Get-Content -LiteralPath (Join-Path $vs 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')).Trim()
$vc = Join-Path $vs "VC\Tools\MSVC\$vcVersion"
$compiler = Join-Path $vc 'bin\Hostx64\x64\cl.exe'
$kit = '10.0.26100.0'
$env:PATH = "$sdk\bin\$kit\x64;$vc\bin\Hostx64\x64;$env:PATH"
$includes = @("/I$PSScriptRoot", "/external:I$vc\include", "/external:I$sdk\Include\$kit\shared",
"/external:I$sdk\Include\$kit\ucrt", "/external:I$sdk\Include\$kit\um")
$driverIncludes = $includes + @("/external:I$wdk\Include\$kit\km", "/external:I$wdk\Include\$kit\um",
"/external:I$wdk\Include\wdf\umdf\2.15")
$libraries = @("/LIBPATH:$vc\lib\x64", "/LIBPATH:$sdk64\um\x64", "/LIBPATH:$sdk64\ucrt\x64")
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /Zi /LD /utf-8 @driverIncludes `
/DUMDF_VERSION_MAJOR=2 /DUMDF_VERSION_MINOR=15 /DUMDF_USING_NTSTATUS /D_UNICODE /DUNICODE `
/D_WIN32_WINNT=0x0A00 "/Fo$obj\\" "/Fd$obj\Driver.pdb" "/Fe$output\XfeInputDriver.dll" `
(Join-Path $PSScriptRoot 'Driver.c') (Join-Path $PSScriptRoot 'Reports.c') (Join-Path $PSScriptRoot 'HidControl.c') `
/link @libraries "/LIBPATH:$wdk\Lib\wdf\umdf\x64\2.15" WdfDriverStubUm.lib ntdll.lib mincore.lib `
/DEBUG:FULL /OPT:REF /OPT:ICF /DYNAMICBASE /NXCOMPAT /GUARD:CF "/PDB:$output\XfeInputDriver.pdb" '/PDBALTPATH:%_PDB%'
if ($LASTEXITCODE) { throw 'UMDF driver build failed.' }
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /utf-8 @includes "/Fo$obj\Setup.obj" "/Fe$output\XfeInputSetup.exe" `
(Join-Path $PSScriptRoot 'Setup.c') /link @libraries setupapi.lib newdev.lib advapi32.lib crypt32.lib wintrust.lib user32.lib `
/DYNAMICBASE /NXCOMPAT /MANIFEST:EMBED "/MANIFESTUAC:level='requireAdministrator' uiAccess='false'"
if ($LASTEXITCODE) { throw 'Setup helper build failed.' }
foreach ($test in @('ReportsTests', 'ControlTests')) {
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /utf-8 @includes "/Fo$obj\\" "/Fe$obj\$test.exe" `
(Join-Path $PSScriptRoot 'Reports.c') (Join-Path $PSScriptRoot 'HidControl.c') `
(Join-Path $PSScriptRoot "tests\$test.c") /link @libraries
if ($LASTEXITCODE) { throw "Native test build failed: $test" }
& (Join-Path $obj "$test.exe")
if ($LASTEXITCODE) { throw "Native test failed: $test" }
}
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'XfeInput.inf') -Destination $output -Force
& (Join-Path $wdk "tools\$kit\x64\infverif.exe") /w (Join-Path $output 'XfeInput.inf')
if ($LASTEXITCODE) { throw 'INF verification failed.' }
$inf2cat = Get-ChildItem -LiteralPath $wdk -Filter inf2cat.exe -Recurse | Select-Object -First 1 -ExpandProperty FullName
& $inf2cat "/driver:$output" /os:10_CO_X64 /uselocaltime
if ($LASTEXITCODE) { throw 'Catalog generation failed.' }
Write-Host "Unsigned UMDF driver package built: $output"
[CmdletBinding()]
param([string]$OutputDirectory = (Join-Path $PSScriptRoot '..\artifacts\driver-umdf'))
$ErrorActionPreference = 'Stop'
$output = [IO.Path]::GetFullPath($OutputDirectory)
$obj = Join-Path $output 'obj'
$null = New-Item -ItemType Directory -Path $obj -Force
dotnet restore (Join-Path $PSScriptRoot 'BuildTools.csproj') --verbosity quiet
if ($LASTEXITCODE) { throw 'WDK restore failed.' }
$assets = Get-Content -LiteralPath (Join-Path $PSScriptRoot 'obj\project.assets.json') -Raw | ConvertFrom-Json
function PackagePath([string]$id, [string]$version) {
foreach ($folder in $assets.packageFolders.PSObject.Properties.Name) {
$candidate = Join-Path $folder "$id\$version\c"
if (Test-Path -LiteralPath $candidate) { return $candidate }
}
throw "Package missing: $id $version"
}
$wdk = PackagePath 'microsoft.windows.wdk.x64' '10.0.26100.6584'
$sdk = PackagePath 'microsoft.windows.sdk.cpp' '10.0.26100.1'
$sdk64 = PackagePath 'microsoft.windows.sdk.cpp.x64' '10.0.26100.1'
$vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
$vs = & $vswhere -latest -products '*' -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
if (!$vs) { throw 'Install Visual Studio Desktop development with C++ build tools.' }
$vcVersion = (Get-Content -LiteralPath (Join-Path $vs 'VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt')).Trim()
$vc = Join-Path $vs "VC\Tools\MSVC\$vcVersion"
$compiler = Join-Path $vc 'bin\Hostx64\x64\cl.exe'
$kit = '10.0.26100.0'
$env:PATH = "$sdk\bin\$kit\x64;$vc\bin\Hostx64\x64;$env:PATH"
$includes = @("/I$PSScriptRoot", "/external:I$vc\include", "/external:I$sdk\Include\$kit\shared",
"/external:I$sdk\Include\$kit\ucrt", "/external:I$sdk\Include\$kit\um")
$driverIncludes = $includes + @("/external:I$wdk\Include\$kit\km", "/external:I$wdk\Include\$kit\um",
"/external:I$wdk\Include\wdf\umdf\2.15")
$libraries = @("/LIBPATH:$vc\lib\x64", "/LIBPATH:$sdk64\um\x64", "/LIBPATH:$sdk64\ucrt\x64")
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /Zi /LD /utf-8 @driverIncludes `
/DUMDF_VERSION_MAJOR=2 /DUMDF_VERSION_MINOR=15 /DUMDF_USING_NTSTATUS /D_UNICODE /DUNICODE `
/D_WIN32_WINNT=0x0A00 "/Fo$obj\\" "/Fd$obj\Driver.pdb" "/Fe$output\XfeInputDriver.dll" `
(Join-Path $PSScriptRoot 'Driver.c') (Join-Path $PSScriptRoot 'Reports.c') (Join-Path $PSScriptRoot 'HidControl.c') `
/link @libraries "/LIBPATH:$wdk\Lib\wdf\umdf\x64\2.15" WdfDriverStubUm.lib ntdll.lib mincore.lib `
/DEBUG:FULL /OPT:REF /OPT:ICF /DYNAMICBASE /NXCOMPAT /GUARD:CF "/PDB:$output\XfeInputDriver.pdb" '/PDBALTPATH:%_PDB%'
if ($LASTEXITCODE) { throw 'UMDF driver build failed.' }
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /utf-8 @includes "/Fo$obj\Setup.obj" "/Fe$output\XfeInputSetup.exe" `
(Join-Path $PSScriptRoot 'Setup.c') /link @libraries setupapi.lib newdev.lib advapi32.lib crypt32.lib wintrust.lib user32.lib `
/DYNAMICBASE /NXCOMPAT /MANIFEST:EMBED "/MANIFESTUAC:level='requireAdministrator' uiAccess='false'"
if ($LASTEXITCODE) { throw 'Setup helper build failed.' }
foreach ($test in @('ReportsTests', 'ControlTests')) {
& $compiler /nologo /TC /W4 /WX /external:W0 /MT /O2 /utf-8 @includes "/Fo$obj\\" "/Fe$obj\$test.exe" `
(Join-Path $PSScriptRoot 'Reports.c') (Join-Path $PSScriptRoot 'HidControl.c') `
(Join-Path $PSScriptRoot "tests\$test.c") /link @libraries
if ($LASTEXITCODE) { throw "Native test build failed: $test" }
& (Join-Path $obj "$test.exe")
if ($LASTEXITCODE) { throw "Native test failed: $test" }
}
Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'XfeInput.inf') -Destination $output -Force
& (Join-Path $wdk "tools\$kit\x64\infverif.exe") /w (Join-Path $output 'XfeInput.inf')
if ($LASTEXITCODE) { throw 'INF verification failed.' }
$inf2cat = Get-ChildItem -LiteralPath $wdk -Filter inf2cat.exe -Recurse | Select-Object -First 1 -ExpandProperty FullName
& $inf2cat "/driver:$output" /os:10_CO_X64 /uselocaltime
if ($LASTEXITCODE) { throw 'Catalog generation failed.' }
Write-Host "Unsigned UMDF driver package built: $output"