Evan's Blog
EvanZhu0721 / 公开仓库

SBMS

镜像已同步

SBMS complete the calculation rules for the default logical desktop topology relationship and the physical dimensions of the displays in the Windows multi-screen collaboration system.

上游 GitHub
READ-ONLY MIRROR

README、源码与 Release 已保存到本站;源码视图固定到 commit a37d6c4b。

main/ root
a37d6c4b· 固定源码快照
build-driver.ps15.3 KB
1[CmdletBinding()]
2param(
3 [string]$SigningCertificateThumbprint
4)
5
6$ErrorActionPreference = 'Stop'
7Set-StrictMode -Version Latest
8
9$repository = $PSScriptRoot
10$driver = Join-Path $repository 'driver'
11$output = Join-Path $repository 'target\driver'
12$kitsRoot = (Get-ItemProperty -LiteralPath `
13 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots').KitsRoot10
14
15$sdkVersion = Get-ChildItem -LiteralPath (Join-Path $kitsRoot 'Include') -Directory |
16 Where-Object {
17 [version]::TryParse($_.Name, [ref]([version]$null)) -and
18 (Test-Path -LiteralPath (Join-Path $_.FullName 'um\Windows.h')) -and
19 (Test-Path -LiteralPath (Join-Path $kitsRoot "Lib\$($_.Name)"))
20 } |
21 Sort-Object { [version]$_.Name } -Descending |
22 Select-Object -First 1 -ExpandProperty Name
23
24if (-not $sdkVersion) {
25 throw 'No complete Windows SDK was found.'
26}
27
28$vswhere = Join-Path ${env:ProgramFiles(x86)} `
29 'Microsoft Visual Studio\Installer\vswhere.exe'
30$installation = & $vswhere -latest -products * `
31 -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 `
32 -property installationPath
33if ($LASTEXITCODE -ne 0 -or -not $installation) {
34 throw 'Visual Studio C++ Build Tools were not found.'
35}
36
37$vcvars = Join-Path $installation 'VC\Auxiliary\Build\vcvars64.bat'
38$environmentLines = & $env:ComSpec /d /s /c `
39 "call `"$vcvars`" >nul && set"
40if ($LASTEXITCODE -ne 0) {
41 throw 'vcvars64.bat failed.'
42}
43foreach ($line in $environmentLines) {
44 $separator = $line.IndexOf('=')
45 if ($separator -gt 0) {
46 [Environment]::SetEnvironmentVariable(
47 $line.Substring(0, $separator),
48 $line.Substring($separator + 1),
49 'Process')
50 }
51}
52
53$wdfInclude = Join-Path $kitsRoot 'Include\wdf\umdf\2.25'
54$iddInclude = Join-Path $kitsRoot "Include\$sdkVersion\um\iddcx\1.4"
55$wdfLibrary = Join-Path $kitsRoot 'Lib\wdf\umdf\x64\2.25\WdfDriverStubUm.lib'
56$iddLibrary = Join-Path $kitsRoot `
57 "Lib\$sdkVersion\um\x64\iddcx\1.4\IddCxStub.lib"
58$apiValidator = Join-Path $kitsRoot "bin\$sdkVersion\x64\ApiValidator.exe"
59$apiContract = Join-Path $kitsRoot `
60 "build\$sdkVersion\universalDDIs\x64\UniversalDDIs.xml"
61$infVerifier = Join-Path $kitsRoot "Tools\$sdkVersion\x64\InfVerif.exe"
62$inf2Cat = Join-Path $kitsRoot "bin\$sdkVersion\x86\Inf2Cat.exe"
63$signTool = Join-Path $kitsRoot "bin\$sdkVersion\x64\signtool.exe"
64
65$required = @(
66 $vcvars, $wdfInclude, $iddInclude, $wdfLibrary, $iddLibrary,
67 $apiValidator, $apiContract, $infVerifier, $inf2Cat
68)
69foreach ($path in $required) {
70 if (-not (Test-Path -LiteralPath $path)) {
71 throw "Required build input is missing: $path"
72 }
73}
74if ($SigningCertificateThumbprint -and
75 -not (Test-Path -LiteralPath $signTool)) {
76 throw "Required signing tool is missing: $signTool"
77}
78
79if (Test-Path -LiteralPath $output) {
80 Remove-Item -LiteralPath $output -Recurse -Force
81}
82New-Item -ItemType Directory -Path $output | Out-Null
83
84$object = Join-Path $output 'SBMSIndirectDisplay.obj'
85$binary = Join-Path $output 'SBMSIndirectDisplay.dll'
86$inf = Join-Path $output 'SBMSIndirectDisplay.inf'
87
88$compileArguments = @(
89 '/nologo', '/c', '/std:c++17', '/EHs-c-', '/guard:cf',
90 '/W4', '/WX',
91 '/wd4005', '/wd4324',
92 '/D_WIN64', '/D_AMD64_', '/DAMD64', '/DUMDF_DRIVER',
93 '/DUMDF_VERSION_MAJOR=2', '/DUMDF_VERSION_MINOR=25',
94 '/DUMDF_MINIMUM_VERSION_REQUIRED=25', '/DUMDF_USING_NTSTATUS',
95 '/D_UNICODE', '/DUNICODE',
96 '/DIDDCX_VERSION_MAJOR=1', '/DIDDCX_VERSION_MINOR=4',
97 '/DIDDCX_MINIMUM_VERSION_REQUIRED=4',
98 "/I$wdfInclude", "/I$iddInclude",
99 "/Fo$object", (Join-Path $driver 'Driver.cpp')
100)
101& cl.exe @compileArguments
102if ($LASTEXITCODE -ne 0) {
103 throw "cl.exe failed with exit code $LASTEXITCODE"
104}
105
106$linkArguments = @(
107 '/nologo', '/DLL', '/guard:cf', '/SUBSYSTEM:WINDOWS,10.0',
108 '/OSVERSION:10.0', '/VERSION:10.0',
109 "/OUT:$binary", $object, $wdfLibrary, $iddLibrary,
110 'onecoreuap.lib', 'd3d11.lib', 'dxgi.lib', 'ntdll.lib'
111)
112& link.exe @linkArguments
113if ($LASTEXITCODE -ne 0) {
114 throw "link.exe failed with exit code $LASTEXITCODE"
115}
116
117Copy-Item -LiteralPath (Join-Path $driver 'SBMSIndirectDisplay.inf') `
118 -Destination $inf
119
120& $apiValidator "-BinaryPath:$binary" `
121 "-SupportedApiXmlFiles:$apiContract" '-StrictCompliance:true'
122if ($LASTEXITCODE -ne 0) {
123 throw "ApiValidator failed with exit code $LASTEXITCODE"
124}
125
126foreach ($mode in '/w', '/u', '/h') {
127 & $infVerifier $mode $inf
128 if ($LASTEXITCODE -ne 0) {
129 throw "InfVerif $mode failed with exit code $LASTEXITCODE"
130 }
131}
132
133& $inf2Cat "/driver:$output" /os:10_X64
134if ($LASTEXITCODE -ne 0) {
135 throw "Inf2Cat failed with exit code $LASTEXITCODE"
136}
137
138if ($SigningCertificateThumbprint) {
139 & $signTool sign /sha1 $SigningCertificateThumbprint /fd SHA256 $binary
140 if ($LASTEXITCODE -ne 0) {
141 throw "Signing the driver DLL failed with exit code $LASTEXITCODE"
142 }
143
144 $catalog = Join-Path $output 'SBMSIndirectDisplay.cat'
145 & $signTool sign /sha1 $SigningCertificateThumbprint /fd SHA256 $catalog
146 if ($LASTEXITCODE -ne 0) {
147 throw "Signing the catalog failed with exit code $LASTEXITCODE"
148 }
149
150 foreach ($file in @($binary, $catalog)) {
151 & $signTool verify /pa $file
152 if ($LASTEXITCODE -ne 0) {
153 throw "Signature verification failed for $file"
154 }
155 }
156}
157
158Write-Host "driver_package=$output"
159