-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ps1
More file actions
182 lines (163 loc) · 6.34 KB
/
Copy pathbuild.ps1
File metadata and controls
182 lines (163 loc) · 6.34 KB
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
# ============================================================================
# intertwine_cpp_framework — Windows PowerShell build script (equivalent to build.sh)
#
# Usage:
# .\build.ps1
# .\build.ps1 -VcpkgRoot D:\vcpkg
# .\build.ps1 -InstallDir D:\out\intertwine_cpp_framework_install
# .\build.ps1 -Test
# .\build.ps1 -Clean
#
# Stages:
# [1/4] Prepare vcpkg and install dependencies (Boost / OpenSSL / spdlog / json)
# [2/4] Build libhv (requires OpenSSL)
# [3/4] Build the framework (requires libhv and Boost)
# [4/4] Install to -InstallDir or run tests
#
# Prerequisites:
# - cmake, ninja, and git must be on PATH.
# - MinGW: gcc and g++ must be on PATH (MSYS2 mingw64 is recommended).
# - MSVC: start pwsh from an "x64 Native Tools" environment.
# ============================================================================
[CmdletBinding()]
param(
[string]$VcpkgRoot = '',
[string]$VcpkgInstalledDir = '',
[string]$InstallDir = '',
[ValidateSet('x64-mingw-dynamic', 'x64-mingw-static', 'x64-windows', 'x64-windows-static')]
[string]$Triplet = 'x64-mingw-dynamic',
[string]$Generator = 'Ninja',
[switch]$Test,
[switch]$Clean
)
$ErrorActionPreference = 'Stop'
$FwDir = $PSScriptRoot
$BuildDir = Join-Path $FwDir 'build'
$LibhvInstall = Join-Path $FwDir 'build_cache\libhv_install'
if (-not $InstallDir) {
$projectRoot = Resolve-Path (Join-Path $FwDir '..\..')
$InstallDir = Join-Path $projectRoot.Path 'build_cache\intertwine_cpp_framework_install'
}
Write-Host '================================================'
Write-Host ' Building intertwine_cpp_framework (Windows)'
Write-Host '================================================'
# ── [1/4] Prepare vcpkg ──
if ($VcpkgRoot) {
$VcpkgDir = $VcpkgRoot
if (-not (Test-Path (Join-Path $VcpkgDir 'scripts\buildsystems\vcpkg.cmake'))) {
Write-Error "Invalid -VcpkgRoot path: $VcpkgDir"
exit 1
}
Write-Host "[1/4] Reusing vcpkg: $VcpkgDir"
} else {
$VcpkgDir = Join-Path $FwDir 'vcpkg'
if (-not (Test-Path (Join-Path $VcpkgDir 'scripts\buildsystems\vcpkg.cmake'))) {
Write-Host "[1/4] vcpkg not found; cloning to $VcpkgDir..."
& git clone https://github.com/microsoft/vcpkg.git $VcpkgDir
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& (Join-Path $VcpkgDir 'bootstrap-vcpkg.bat') -disableMetrics
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
}
$VcpkgToolchain = Join-Path $VcpkgDir 'scripts\buildsystems\vcpkg.cmake'
$VcpkgExe = Join-Path $VcpkgDir 'vcpkg.exe'
if (-not $VcpkgInstalledDir) {
$VcpkgInstalledDir = Join-Path $BuildDir 'vcpkg_installed'
}
$OpensslRoot = Join-Path $VcpkgInstalledDir $Triplet
# Check for OpenSSL; library names vary by triplet.
$opensslMarker = @(
(Join-Path $OpensslRoot 'lib\libssl.a'),
(Join-Path $OpensslRoot 'lib\libssl.lib'),
(Join-Path $OpensslRoot 'lib\ssl.lib')
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $opensslMarker) {
Write-Host ' Installing vcpkg dependencies...'
& $VcpkgExe install `
--triplet=$Triplet `
--x-install-root=$VcpkgInstalledDir `
--x-manifest-root=$FwDir
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
$opensslMarker = @(
(Join-Path $OpensslRoot 'lib\libssl.a'),
(Join-Path $OpensslRoot 'lib\libssl.lib'),
(Join-Path $OpensslRoot 'lib\ssl.lib')
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $opensslMarker) {
Write-Error 'OpenSSL installation failed; check the vcpkg logs.'
exit 1
}
Write-Host ' vcpkg dependencies are ready'
# ── [2/4] Build libhv ──
$libhvLib = @(
(Join-Path $LibhvInstall 'lib\libhv_static.a'),
(Join-Path $LibhvInstall 'lib\libhv.a'),
(Join-Path $LibhvInstall 'lib\hv_static.lib'),
(Join-Path $LibhvInstall 'lib\hv.lib')
) | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $libhvLib) {
Write-Host '[2/4] Building libhv...'
& (Join-Path $FwDir 'build-libhv.ps1') -OpensslRoot $OpensslRoot -Generator $Generator
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$libhvLib = @(
(Join-Path $LibhvInstall 'lib\libhv_static.a'),
(Join-Path $LibhvInstall 'lib\libhv.a'),
(Join-Path $LibhvInstall 'lib\hv_static.lib'),
(Join-Path $LibhvInstall 'lib\hv.lib')
) | Where-Object { Test-Path $_ } | Select-Object -First 1
} else {
Write-Host '[2/4] Reusing cached libhv'
}
if (-not $libhvLib) { Write-Error 'libhv build failed'; exit 1 }
Write-Host " libhv is ready: $libhvLib"
# ── [3/4] Build the framework ──
Write-Host '[3/4] Building the framework...'
if ($Clean -and (Test-Path $BuildDir)) {
Remove-Item $BuildDir -Recurse -Force
}
$cmakeArgs = @(
"-B", $BuildDir,
"-S", $FwDir,
"-G", $Generator,
"-DCMAKE_TOOLCHAIN_FILE=$VcpkgToolchain",
"-DVCPKG_INSTALLED_DIR=$VcpkgInstalledDir",
"-DVCPKG_TARGET_TRIPLET=$Triplet",
"-DVCPKG_INSTALL_OPTIONS=--no-print-usage",
"--log-level=NOTICE",
"-DLIBHV_INCLUDE_DIR=$(Join-Path $LibhvInstall 'include')",
"-DLIBHV_LIB=$libhvLib",
"-DCMAKE_INSTALL_PREFIX=$InstallDir"
)
if ($Test -and $env:GTEST_PREFIX) {
$cmakeArgs += "-DCMAKE_PREFIX_PATH=$env:GTEST_PREFIX"
}
# Skip configuration for an incremental build when the installation prefix matches.
$needConfigure = $true
$cacheFile = Join-Path $BuildDir 'CMakeCache.txt'
if ((Test-Path $cacheFile) -and -not $Clean) {
$cachedPrefix = (Select-String -Path $cacheFile -Pattern '^CMAKE_INSTALL_PREFIX:PATH=(.*)$' |
Select-Object -First 1).Matches.Groups[1].Value
if ($cachedPrefix -eq $InstallDir) { $needConfigure = $false }
}
if ($needConfigure) {
& cmake @cmakeArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
& cmake --build $BuildDir --config Release -j ([Environment]::ProcessorCount)
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
# ── [4/4] Install or test ──
if ($Test) {
Write-Host '[4/4] Running tests...'
Push-Location $BuildDir
try {
& ctest --output-on-failure
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally { Pop-Location }
} else {
Write-Host "[4/4] Installing to $InstallDir..."
& cmake --install $BuildDir --config Release
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
Write-Host ''
Write-Host "Installation complete: $InstallDir"