forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
433 lines (345 loc) · 11.9 KB
/
build.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<#
.SYNOPSIS
This script provides helpers for building msquic.
.PARAMETER Config
The debug or release configuration to build for.
.PARAMETER Arch
The CPU architecture to build for.
.PARAMETER Platform
Specify which platform to build for
.PARAMETER Tls
The TLS library to use.
.PARAMETER ToolchainFile
Toolchain file to use (if cross)
.PARAMETER DisableLogs
Disables log collection.
.PARAMETER SanitizeAddress
Enables address sanitizer.
.PARAMETER CodeCheck
Enables static code checkers.
.PARAMETER DisableTools
Don't build the tools directory.
.PARAMETER DisableTest
Don't build the test directory.
.PARAMETER DisablePerf
Don't build the perf directory.
.PARAMETER Clean
Deletes all previous build and configuration.
.PARAMETER InstallOutput
Installs the build output to the current machine.
.PARAMETER Parallel
Enables CMake to build in parallel, where possible.
.PARAMETER DynamicCRT
Builds msquic with dynamic C runtime (Windows-only).
.PARAMETER PGO
Builds msquic with profile guided optimization support (Windows-only).
.PARAMETER Generator
Specifies a specific cmake generator (Only supported on unix)
.PARAMETER SkipPdbAltPath
Skip setting PDBALTPATH into built binaries on Windows. Without this flag, the PDB must be in the same directory as the DLL or EXE.
.PARAMETER SkipSourceLink
Skip generating sourcelink and inserting it into the PDB.
.PARAMETER Clang
Build with Clang if available
.PARAMETER UpdateClog
Build allowing clog to update the sidecar.
.PARAMETER ConfigureOnly
Run configuration only.
.PARAMETER CI
Build is occuring from CI
.PARAMETER RandomAllocFail
Enables random allocation failures.
.PARAMETER TlsSecretsSupport
Enables export of traffic secrets.
.PARAMETER EnableTelemetryAsserts
Enables telemetry asserts in release builds.
.PARAMETER UseSystemOpenSSLCrypto
Use system provided OpenSSL libcrypto rather then statically linked. Only affects OpenSSL Linux builds
.PARAMETER ExtraArtifactDir
Add an extra classifier to the artifact directory to allow publishing alternate builds of same base library
.EXAMPLE
build.ps1
.EXAMPLE
build.ps1 -Config Release
#>
param (
[Parameter(Mandatory = $false)]
[ValidateSet("Debug", "Release")]
[string]$Config = "Debug",
[Parameter(Mandatory = $false)]
[ValidateSet("x86", "x64", "arm", "arm64")]
[string]$Arch = "",
[Parameter(Mandatory = $false)]
[ValidateSet("uwp", "windows", "linux", "macos")] # For future expansion
[string]$Platform = "",
[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl", "stub", "mitls")]
[string]$Tls = "",
[Parameter(Mandatory = $false)]
[string]$ToolchainFile = "",
[Parameter(Mandatory = $false)]
[switch]$DisableLogs = $false,
[Parameter(Mandatory = $false)]
[switch]$SanitizeAddress = $false,
[Parameter(Mandatory = $false)]
[switch]$CodeCheck = $false,
[Parameter(Mandatory = $false)]
[switch]$DisableTools = $false,
[Parameter(Mandatory = $false)]
[switch]$DisableTest = $false,
[Parameter(Mandatory = $false)]
[switch]$DisablePerf = $false,
[Parameter(Mandatory = $false)]
[switch]$Clean = $false,
[Parameter(Mandatory = $false)]
[int32]$Parallel = -1,
[Parameter(Mandatory = $false)]
[switch]$DynamicCRT = $false,
[Parameter(Mandatory = $false)]
[switch]$PGO = $false,
[Parameter(Mandatory = $false)]
[string]$Generator = "",
[Parameter(Mandatory = $false)]
[switch]$SkipPdbAltPath = $false,
[Parameter(Mandatory = $false)]
[switch]$SkipSourceLink = $false,
[Parameter(Mandatory = $false)]
[switch]$Clang = $false,
[Parameter(Mandatory = $false)]
[switch]$UpdateClog = $false,
[Parameter(Mandatory = $false)]
[switch]$ConfigureOnly = $false,
[Parameter(Mandatory = $false)]
[switch]$CI = $false,
[Parameter(Mandatory = $false)]
[switch]$RandomAllocFail = $false,
[Parameter(Mandatory = $false)]
[switch]$TlsSecretsSupport = $false,
[Parameter(Mandatory = $false)]
[switch]$EnableTelemetryAsserts = $false,
[Parameter(Mandatory = $false)]
[switch]$UseSystemOpenSSLCrypto = $false,
[Parameter(Mandatory = $false)]
[string]$ExtraArtifactDir = ""
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
if ("" -eq $Arch) {
# TODO Actually detect current platform
$Arch = "x64"
}
if ($Generator -eq "") {
if ($IsWindows) {
$Generator = "Visual Studio 16 2019"
} elseif ($IsLinux) {
$Generator = "Ninja"
} else {
$Generator = "Unix Makefiles"
}
}
# Default TLS based on current platform.
if ("" -eq $Tls) {
if ($IsWindows) {
$Tls = "schannel"
} else {
$Tls = "openssl"
}
}
if ("" -eq $Platform) {
if ($IsWindows) {
$Platform = "windows"
} elseif ($IsLinux) {
$Platform = "linux"
} elseif ($IsMacOS) {
$Platform = "macos"
} else {
Write-Error "Unsupported platform type!"
}
}
if (!$IsWindows -And $Platform -eq "uwp") {
Write-Error "[$(Get-Date)] Cannot build uwp on non windows platforms"
exit
}
# Root directory of the project.
$RootDir = Split-Path $PSScriptRoot -Parent
# Important directory paths.
$BaseArtifactsDir = Join-Path $RootDir "artifacts"
$BaseBuildDir = Join-Path $RootDir "build"
$ArtifactsDir = Join-Path $BaseArtifactsDir "bin" $Platform
$BuildDir = Join-Path $BaseBuildDir $Platform
if ("" -eq $ExtraArtifactDir) {
$ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)"
} else {
$ArtifactsDir = Join-Path $ArtifactsDir "$($Arch)_$($Config)_$($Tls)_$($ExtraArtifactDir)"
}
$BuildDir = Join-Path $BuildDir "$($Arch)_$($Tls)"
if ($Clean) {
# Delete old build/config directories.
if (Test-Path $ArtifactsDir) { Remove-Item $ArtifactsDir -Recurse -Force | Out-Null }
if (Test-Path $BuildDir) { Remove-Item $BuildDir -Recurse -Force | Out-Null }
}
# Initialize directories needed for building.
if (!(Test-Path $BaseArtifactsDir)) {
New-Item -Path $BaseArtifactsDir -ItemType Directory -Force | Out-Null
}
if (!(Test-Path $BuildDir)) { New-Item -Path $BuildDir -ItemType Directory -Force | Out-Null }
if ($Clang) {
if ($IsWindows) {
Write-Error "Clang is not supported on windows currently"
}
$env:CC = 'clang'
$env:CXX = 'clang++'
}
function Log($msg) {
Write-Host "[$(Get-Date)] $msg"
}
# Executes cmake with the given arguments.
function CMake-Execute([String]$Arguments) {
Log "cmake $($Arguments)"
$process = Start-Process cmake $Arguments -PassThru -NoNewWindow -WorkingDirectory $BuildDir
$handle = $process.Handle # Magic work around. Don't remove this line.
$process.WaitForExit();
if ($process.ExitCode -ne 0) {
Write-Error "[$(Get-Date)] CMake exited with status code $($process.ExitCode)"
}
}
# Uses cmake to generate the build configuration files.
function CMake-Generate {
$Arguments = "-g"
if ($IsWindows) {
$Arguments += " '$Generator' -A "
switch ($Arch) {
"x86" { $Arguments += "Win32" }
"x64" { $Arguments += "x64" }
"arm" { $Arguments += "arm" }
"arm64" { $Arguments += "arm64" }
}
} elseif ($IsMacOS) {
$Arguments += " '$Generator'"
switch ($Arch) {
"x64" { $Arguments += " -DCMAKE_OSX_ARCHITECTURES=x86_64"}
"arm64" { $Arguments += " -DCMAKE_OSX_ARCHITECTURES=arm64"}
}
} else {
$Arguments += " '$Generator'"
}
$Arguments += " -DQUIC_TLS=" + $Tls
$Arguments += " -DQUIC_OUTPUT_DIR=" + $ArtifactsDir
if (!$DisableLogs) {
$Arguments += " -DQUIC_ENABLE_LOGGING=on"
}
if ($SanitizeAddress) {
$Arguments += " -DQUIC_ENABLE_SANITIZERS=on"
}
if ($CodeCheck) {
$Arguments += " -DQUIC_CODE_CHECK=on"
}
if ($DisableTools) {
$Arguments += " -DQUIC_BUILD_TOOLS=off"
}
if ($DisableTest) {
$Arguments += " -DQUIC_BUILD_TEST=off"
}
if ($DisablePerf) {
$Arguments += " -DQUIC_BUILD_PERF=off"
}
if (!$IsWindows) {
$Arguments += " -DCMAKE_BUILD_TYPE=" + $Config
}
if ($DynamicCRT) {
$Arguments += " -DQUIC_STATIC_LINK_CRT=off"
}
if ($PGO) {
$Arguments += " -DQUIC_PGO=on"
}
if ($Platform -eq "uwp") {
$Arguments += " -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10 -DQUIC_UWP_BUILD=on -DQUIC_STATIC_LINK_CRT=Off"
}
if ($ToolchainFile -ne "") {
$Arguments += " ""-DCMAKE_TOOLCHAIN_FILE=" + $ToolchainFile + """"
}
if ($SkipPdbAltPath) {
$Arguments += " -DQUIC_PDBALTPATH=OFF"
}
if ($SkipSourceLink) {
$Arguments += " -DQUIC_SOURCE_LINK=OFF"
}
if ($CI) {
$Arguments += " -DQUIC_CI=ON"
$Arguments += " -DQUIC_CI_CONFIG=$Config"
$Arguments += " -DQUIC_VER_BUILD_ID=$env:BUILD_BUILDID"
$Arguments += " -DQUIC_VER_SUFFIX=-official"
}
if ($RandomAllocFail) {
$Arguments += " -DQUIC_RANDOM_ALLOC_FAIL=on"
}
if ($TlsSecretsSupport) {
$Arguments += " -DQUIC_TLS_SECRETS_SUPPORT=on"
}
if ($EnableTelemetryAsserts) {
$Arguments += " -DQUIC_TELEMETRY_ASSERTS=on"
}
if ($UseSystemOpenSSLCrypto) {
$Arguments += " -DQUIC_USE_SYSTEM_LIBCRYPTO=on"
}
$Arguments += " ../../.."
CMake-Execute $Arguments
if ($PGO -and $Config -eq "Release") {
# Manually edit project file, since CMake doesn't seem to have a way to do it.
$FindText = " <PropertyGroup Label=`"UserMacros`" />"
$ReplaceText = " <PropertyGroup Label=`"UserMacros`" />`r`n <PropertyGroup><LibraryPath>`$(LibraryPath);`$(VC_LibraryPath_VC_$($Arch)_Desktop)</LibraryPath></PropertyGroup>"
$ProjectFile = Join-Path $BuildDir "src\bin\msquic.vcxproj"
(Get-Content $ProjectFile) -replace $FindText, $ReplaceText | Out-File $ProjectFile
}
}
# Uses cmake to generate the build configuration files.
function CMake-Build {
$Arguments = "--build ."
if ($Parallel -gt 0) {
$Arguments += " --parallel $($Parallel)"
} elseif ($Parallel -eq 0) {
$Arguments += " --parallel"
}
if ($IsWindows) {
$Arguments += " --config " + $Config
} else {
$Arguments += " -- VERBOSE=1"
}
CMake-Execute $Arguments
if ($IsWindows) {
Copy-Item (Join-Path $BuildDir "obj" $Config "msquic.lib") $ArtifactsDir
if ($PGO -and $Config -eq "Release") {
Install-Module VSSetup -Scope CurrentUser -Force -SkipPublisherCheck
$VSInstallationPath = Get-VSSetupInstance | Select-VSSetupInstance -Latest -Require Microsoft.VisualStudio.Component.VC.Tools.x86.x64 | Select-Object -ExpandProperty InstallationPath
$VCToolVersion = Get-Content -Path "$VSInstallationPath\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.txt"
$VCToolsPath = "$VSInstallationPath\VC\Tools\MSVC\$VCToolVersion\bin\Host$Arch\$Arch"
if (Test-Path $VCToolsPath) {
Copy-Item (Join-Path $VCToolsPath "pgort140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgodb140.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "mspdbcore.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "tbbmalloc.dll") $ArtifactsDir
Copy-Item (Join-Path $VCToolsPath "pgomgr.exe") $ArtifactsDir
} else {
Log "Failed to find VC Tools path!"
}
}
}
}
##############################################################
# Main Execution #
##############################################################
if ($UpdateClog) {
$env:CLOG_DEVELOPMENT_MODE=1
}
# Generate the build files.
Log "Generating files..."
CMake-Generate
if (!$ConfigureOnly) {
# Build the code.
Log "Building..."
CMake-Build
}
Log "Done."
if ($UpdateClog) {
$env:CLOG_DEVELOPMENT_MODE=0
}