summaryrefslogtreecommitdiff
path: root/windows/build.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'windows/build.ps1')
-rw-r--r--windows/build.ps1204
1 files changed, 204 insertions, 0 deletions
diff --git a/windows/build.ps1 b/windows/build.ps1
new file mode 100644
index 0000000..aaa848d
--- /dev/null
+++ b/windows/build.ps1
@@ -0,0 +1,204 @@
1param(
2 [string]$CMakePath = "C:\Program Files\CMake\bin\cmake.exe",
3 [string]$GitPath = "C:\Program Files\Git\bin\git.exe",
4 [string]$SevenZPath = "C:\Program Files\7-Zip\7z.exe",
5 [string]$GPGPath = "C:\Program Files (x86)\GnuPG\bin\gpg.exe"
6)
7
8$ErrorActionPreference = "Continue"
9
10[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
11
12# LibreSSL coordinates.
13New-Variable -Name 'LIBRESSL_URL' `
14 -Value 'https://ftp.openbsd.org/pub/OpenBSD/LibreSSL' -Option Constant
15New-Variable -Name 'LIBRESSL' -Value 'libressl-3.0.2' -Option Constant
16
17# libcbor coordinates.
18New-Variable -Name 'LIBCBOR' -Value 'libcbor-0.5.0' -Option Constant
19New-Variable -Name 'LIBCBOR_BRANCH' -Value 'v0.5.0' -Option Constant
20New-Variable -Name 'LIBCBOR_GIT' -Value 'https://github.com/pjk/libcbor' `
21 -Option Constant
22
23# Work directories.
24New-Variable -Name 'BUILD' -Value "$PSScriptRoot\..\build" -Option Constant
25New-Variable -Name 'OUTPUT' -Value "$PSScriptRoot\..\output" -Option Constant
26
27# Find CMake.
28$CMake = $(Get-Command cmake -ErrorAction Ignore | Select-Object -ExpandProperty Source)
29if([string]::IsNullOrEmpty($CMake)) {
30 $CMake = $CMakePath
31}
32
33# Find Git.
34$Git = $(Get-Command git -ErrorAction Ignore | Select-Object -ExpandProperty Source)
35if([string]::IsNullOrEmpty($Git)) {
36 $Git = $GitPath
37}
38
39# Find 7z.
40$SevenZ = $(Get-Command 7z -ErrorAction Ignore | Select-Object -ExpandProperty Source)
41if([string]::IsNullOrEmpty($SevenZ)) {
42 $SevenZ = $SevenZPath
43}
44
45# Find GPG.
46$GPG = $(Get-Command gpg -ErrorAction Ignore | Select-Object -ExpandProperty Source)
47if([string]::IsNullOrEmpty($GPG)) {
48 $GPG = $GPGPath
49}
50
51if(-Not (Test-Path $CMake)) {
52 throw "Unable to find CMake at $CMake"
53}
54
55if(-Not (Test-Path $Git)) {
56 throw "Unable to find Git at $Git"
57}
58
59if(-Not (Test-Path $SevenZ)) {
60 throw "Unable to find 7z at $SevenZ"
61}
62
63if(-Not (Test-Path $GPG)) {
64 throw "Unable to find GPG at $GPG"
65}
66
67Write-Host "Git: $Git"
68Write-Host "CMake: $CMake"
69Write-Host "7z: $SevenZ"
70Write-Host "GPG: $GPG"
71
72New-Item -Type Directory ${BUILD}
73New-Item -Type Directory ${BUILD}\32
74New-Item -Type Directory ${BUILD}\64
75New-Item -Type Directory ${OUTPUT}
76New-Item -Type Directory ${OUTPUT}\pkg\Win64\Release\v142\dynamic
77New-Item -Type Directory ${OUTPUT}\pkg\Win32\Release\v142\dynamic
78
79Push-Location ${BUILD}
80
81try {
82 if (Test-Path .\${LIBRESSL}) {
83 Remove-Item .\${LIBRESSL} -Recurse -ErrorAction Stop
84 }
85
86 if(-Not (Test-Path .\${LIBRESSL}.tar.gz -PathType leaf)) {
87 Invoke-WebRequest ${LIBRESSL_URL}/${LIBRESSL}.tar.gz `
88 -OutFile .\${LIBRESSL}.tar.gz
89 }
90 if(-Not (Test-Path .\${LIBRESSL}.tar.gz.asc -PathType leaf)) {
91 Invoke-WebRequest ${LIBRESSL_URL}/${LIBRESSL}.tar.gz.asc `
92 -OutFile .\${LIBRESSL}.tar.gz.asc
93 }
94
95 Copy-Item "$PSScriptRoot\libressl.gpg" -Destination "${BUILD}"
96 & $GPG --list-keys
97 & $GPG -v --no-default-keyring --keyring ./libressl.gpg `
98 --verify .\${LIBRESSL}.tar.gz.asc .\${LIBRESSL}.tar.gz
99 if ($LastExitCode -ne 0) {
100 throw "GPG signature verification failed"
101 }
102
103 & $SevenZ e .\${LIBRESSL}.tar.gz
104 & $SevenZ x .\${LIBRESSL}.tar
105 Remove-Item -Force .\${LIBRESSL}.tar
106
107 if(-Not (Test-Path .\${LIBCBOR})) {
108 Write-Host "Cloning ${LIBCBOR}..."
109 & $Git clone --branch ${LIBCBOR_BRANCH} ${LIBCBOR_GIT} `
110 .\${LIBCBOR}
111 }
112} catch {
113 throw "Failed to fetch and verify dependencies"
114} finally {
115 Pop-Location
116}
117
118Function Build(${OUTPUT}, ${GENERATOR}, ${ARCH}) {
119 if(-Not (Test-Path .\${LIBRESSL})) {
120 New-Item -Type Directory .\${LIBRESSL} -ErrorAction Stop
121 }
122
123 Push-Location .\${LIBRESSL}
124 & $CMake ..\..\${LIBRESSL} -G "${GENERATOR}" -A "${ARCH}" `
125 -DCMAKE_C_FLAGS_RELEASE="/Zi" `
126 -DCMAKE_INSTALL_PREFIX="${OUTPUT}" -DBUILD_SHARED_LIBS=ON `
127 -DLIBRESSL_TESTS=OFF
128 & $CMake --build . --config Release
129 & $CMake --build . --config Release --target install
130 Pop-Location
131
132 if(-Not (Test-Path .\${LIBCBOR})) {
133 New-Item -Type Directory .\${LIBCBOR} -ErrorAction Stop
134 }
135
136 Push-Location .\${LIBCBOR}
137 & $CMake ..\..\${LIBCBOR} -G "${GENERATOR}" -A "${ARCH}" `
138 -DCMAKE_C_FLAGS_RELEASE="/Zi" `
139 -DCMAKE_INSTALL_PREFIX="${OUTPUT}"
140 & $CMake --build . --config Release
141 & $CMake --build . --config Release --target install
142 Pop-Location
143
144 & $CMake ..\.. -G "${GENERATOR}" -A "${ARCH}" `
145 -DCBOR_INCLUDE_DIRS="${OUTPUT}\include" `
146 -DCBOR_LIBRARY_DIRS="${OUTPUT}\lib" `
147 -DCRYPTO_INCLUDE_DIRS="${OUTPUT}\include" `
148 -DCRYPTO_LIBRARY_DIRS="${OUTPUT}\lib" `
149 -DCMAKE_INSTALL_PREFIX="${OUTPUT}"
150 & $CMake --build . --config Release
151 & $CMake --build . --config Release --target install
152 "cbor.dll", "crypto-45.dll" | %{ Copy-Item "${OUTPUT}\bin\$_" `
153 -Destination "examples\Release" }
154}
155
156Function Package-Headers() {
157 Copy-Item "${OUTPUT}\64\include" -Destination "${OUTPUT}\pkg" `
158 -Recurse -ErrorAction Stop
159}
160
161Function Package-Libraries(${SRC}, ${DEST}) {
162 Copy-Item "${SRC}\bin\cbor.dll" "${DEST}" -ErrorAction Stop
163 Copy-Item "${SRC}\lib\cbor.lib" "${DEST}" -ErrorAction Stop
164 Copy-Item "${SRC}\bin\crypto-45.dll" "${DEST}" -ErrorAction Stop
165 Copy-Item "${SRC}\lib\crypto-45.lib" "${DEST}" -ErrorAction Stop
166 Copy-Item "${SRC}\lib\fido2.dll" "${DEST}" -ErrorAction Stop
167 Copy-Item "${SRC}\lib\fido2.lib" "${DEST}" -ErrorAction Stop
168}
169
170Function Package-PDBs(${SRC}, ${DEST}) {
171 Copy-Item "${SRC}\${LIBRESSL}\crypto\crypto.dir\Release\vc142.pdb" `
172 "${DEST}\crypto-45.pdb" -ErrorAction Stop
173 Copy-Item "${SRC}\${LIBCBOR}\src\cbor_shared.dir\Release\vc142.pdb" `
174 "${DEST}\cbor.pdb" -ErrorAction Stop
175 Copy-Item "${SRC}\src\fido2_shared.dir\Release\vc142.pdb" `
176 "${DEST}\fido2.pdb" -ErrorAction Stop
177}
178
179Function Package-Tools(${SRC}, ${DEST}) {
180 Copy-Item "${SRC}\tools\Release\fido2-assert.exe" `
181 "${DEST}\fido2-assert.exe" -ErrorAction stop
182 Copy-Item "${SRC}\tools\Release\fido2-cred.exe" `
183 "${DEST}\fido2-cred.exe" -ErrorAction stop
184 Copy-Item "${SRC}\tools\Release\fido2-token.exe" `
185 "${DEST}\fido2-token.exe" -ErrorAction stop
186}
187
188Push-Location ${BUILD}\64
189Build ${OUTPUT}\64 "Visual Studio 16 2019" "x64"
190Pop-Location
191
192Push-Location ${BUILD}\32
193Build ${OUTPUT}\32 "Visual Studio 16 2019" "Win32"
194Pop-Location
195
196Package-Headers
197
198Package-Libraries ${OUTPUT}\64 ${OUTPUT}\pkg\Win64\Release\v142\dynamic
199Package-PDBs ${BUILD}\64 ${OUTPUT}\pkg\Win64\Release\v142\dynamic
200Package-Tools ${BUILD}\64 ${OUTPUT}\pkg\Win64\Release\v142\dynamic
201
202Package-Libraries ${OUTPUT}\32 ${OUTPUT}\pkg\Win32\Release\v142\dynamic
203Package-PDBs ${BUILD}\32 ${OUTPUT}\pkg\Win32\Release\v142\dynamic
204Package-Tools ${BUILD}\32 ${OUTPUT}\pkg\Win32\Release\v142\dynamic