forked from microsoft/msquic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
254 lines (208 loc) · 7.49 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
<#
.SYNOPSIS
This script provides helpers for building msquic.
.PARAMETER InstallDependencies
Installs any necessary dependencies.
.PARAMETER InstallAzureDependencies
Installs any necessary Azure Pipelines dependencies.
.PARAMETER Config
The debug or release build configuration to use.
.PARAMETER Tls
The TLS library to use.
.PARAMETER DisableLogs
Disables log collection.
.PARAMETER SanitizeAddress
Enables address sanitizer.
.PARAMETER DisableTools
Don't build the tools directory.
.PARAMETER DisableTest
Don't build the test directory.
.PARAMETER Clean
Deletes all previous build and configuration.
.PARAMETER InstallOutput
Installs the build output to the current machine.
.EXAMPLE
build.ps1 -InstallDependencies
.EXAMPLE
build.ps1
.EXAMPLE
build.ps1 -Config Release
#>
param (
[Parameter(Mandatory = $false)]
[switch]$InstallDependencies = $false,
[Parameter(Mandatory = $false)]
[switch]$InstallAzureDependencies = $false,
[Parameter(Mandatory = $false)]
[ValidateSet("Debug", "Release")]
[string]$Config = "Debug",
[Parameter(Mandatory = $false)]
[ValidateSet("schannel", "openssl", "stub", "mitls")]
[string]$Tls = "",
[Parameter(Mandatory = $false)]
[switch]$DisableLogs = $false,
[Parameter(Mandatory = $false)]
[switch]$SanitizeAddress = $false,
[Parameter(Mandatory = $false)]
[switch]$DisableTools = $false,
[Parameter(Mandatory = $false)]
[switch]$DisableTest = $false,
[Parameter(Mandatory = $false)]
[switch]$Clean = $false,
[Parameter(Mandatory = $false)]
[switch]$InstallOutput = $false
)
Set-StrictMode -Version 'Latest'
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
# Important directory paths.
$BaseArtifactsDir = Join-Path $PSScriptRoot "artifacts"
$BaseBuildDir = Join-Path $PSScriptRoot "bld"
$SrcDir = Join-Path $PSScriptRoot "src"
$ArtifactsDir = $null
$BuildDir = $null
if ($IsWindows) {
$ArtifactsDir = Join-Path $BaseArtifactsDir "windows"
$BuildDir = Join-Path $BaseBuildDir "windows"
} else {
$ArtifactsDir = Join-Path $BaseArtifactsDir "linux"
$BuildDir = Join-Path $BaseBuildDir "linux"
}
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)) {
mkdir $BaseArtifactsDir | Out-Null
# Build up the artifacts (upload) ignore file.
".artifactignore`n*.ilk`n*-results.xml" > (Join-Path $BaseArtifactsDir ".artifactignore")
}
if (!(Test-Path $BaseBuildDir)) { mkdir $BaseBuildDir | Out-Null }
if (!(Test-Path $BuildDir)) { mkdir $BuildDir | Out-Null }
function Log($msg) {
Write-Host "[$(Get-Date)] $msg"
}
# Installs procdump if not already. Windows specific.
function Install-ProcDump {
if (!(Test-Path bld)) { mkdir bld | Out-Null }
if (!(Test-Path bld\windows)) { mkdir bld\windows | Out-Null }
if (!(Test-Path .\bld\windows\procdump)) {
Log "Installing procdump..."
# Download the zip file.
Invoke-WebRequest -Uri https://download.sysinternals.com/files/Procdump.zip -OutFile bld\windows\procdump.zip
# Extract the zip file.
Expand-Archive -Path bld\windows\procdump.zip .\bld\windows\procdump
# Delete the zip file.
Remove-Item -Path bld\windows\procdump.zip
}
}
# Installs just the Azure Pipelines dependencies.
function Install-Azure-Dependencies {
if ($IsWindows) {
# Enable SChannel TLS 1.3 (client and server).
$TlsServerKeyPath = "HKLM\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Server"
reg.exe add $TlsServerKeyPath /v DisabledByDefault /t REG_DWORD /d 1 /f | Out-Null
reg.exe add $TlsServerKeyPath /v Enabled /t REG_DWORD /d 1 /f | Out-Null
$TlsClientKeyPath = "HKLM\System\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.3\Client"
reg.exe add $TlsClientKeyPath /v DisabledByDefault /t REG_DWORD /d 1 /f | Out-Null
reg.exe add $TlsClientKeyPath /v Enabled /t REG_DWORD /d 1 /f | Out-Null
# Make sure procdump is installed
Install-ProcDump
} else {
sudo apt-get install liblttng-ust-dev
sudo apt-get install lttng-tools
}
}
# Installs all the dependencies.
function Install-Dependencies {
if ($IsWindows) {
# TODO - Anything else?
} else {
sudo apt-get install cmake
sudo apt-get install build-essentials
}
Install-Azure-Dependencies
}
# Executes msquictext with the given arguments.
function CMake-Execute([String]$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 += " 'Visual Studio 16 2019' -A x64"
} else {
$Arguments += " 'Linux Makefiles'"
}
switch ($Tls) {
"schannel" { $Arguments += " -DQUIC_TLS=schannel" }
"openssl" { $Arguments += " -DQUIC_TLS=openssl" }
"stub" { $Arguments += " -DQUIC_TLS=stub" }
"mitls" { $Arguments += " -DQUIC_TLS=mitls" }
"" { }
}
if ($DisableLogs) {
$Arguments += " -DQUIC_ENABLE_LOGGING=off"
}
if ($SanitizeAddress) {
$Arguments += " -DQUIC_SANITIZE_ADDRESS=on"
}
if ($DisableTools) {
$Arguments += " -DQUIC_BUILD_TOOLS=off"
}
if ($DisableTest) {
$Arguments += " -DQUIC_BUILD_TEST=off"
}
$Arguments += " ../.."
CMake-Execute $Arguments
}
# Uses cmake to generate the build configuration files.
function CMake-Build {
$Arguments = "--build ."
switch ($Config) {
"Debug" { $Arguments += " --config DEBUG" }
"Release" { $Arguments += " --config RELEASE" }
}
CMake-Execute $Arguments
}
# Installs all the build output.
function Install-Output {
if ($IsWindows) {
# Import the ETW manifest.
$ManifestDir = Join-Path $SrcDir "manifest"
$ManifestPath = Join-Path $ManifestDir "MsQuicEtw.man"
$MsQuicDllPath = Join-Path $ArtifactsDir "bin" $Config "msquic.dll"
Log "Installing ETW manifest..."
wevtutil.exe im $ManifestPath /rf:$MsQuicDllPath /mf:$MsQuicDllPath
} else {
# TODO - Anything?
}
}
##############################################################
# Main Execution #
##############################################################
if ($InstallDependencies) {
Log "Installing dependencies..."
Install-Dependencies
} elseif ($InstallAzureDependencies) {
Log "Installing Azure Pipelines dependencies..."
Install-Azure-Dependencies
}
# Generate the build files.
Log "Generating files..."
CMake-Generate
# Build the code.
Log "Building..."
CMake-Build
if ($InstallOutput) {
# Install the build output.
Install-Output
}
Log "Done."