forked from Geenz/EntropyCore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-cmd.ps1
More file actions
185 lines (155 loc) · 6.43 KB
/
Copy pathbuild-cmd.ps1
File metadata and controls
185 lines (155 loc) · 6.43 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
183
184
185
# PowerShell build script for Windows
# This is the Windows-native equivalent of build-cmd.sh
param(
[string]$Configuration = "Release",
[string]$Platform = "x64"
)
# Enable strict error handling
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
# Get script directory
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
Push-Location $scriptDir
try {
# Set up paths
$top = Get-Location
$stage = Join-Path $top "stage"
# Extract version from vcpkg.json
$vcpkgJson = Get-Content "vcpkg.json" | ConvertFrom-Json
$ENTROPYCORE_VERSION = $vcpkgJson.version
# Get build ID from environment or default to 0
$build = if ($env:AUTOBUILD_BUILD_ID) { $env:AUTOBUILD_BUILD_ID } else { "0" }
Write-Host "Building EntropyCore version $ENTROPYCORE_VERSION.$build" -ForegroundColor Green
# Prepare staging directories
$directories = @(
"$stage\LICENSES",
"$stage\include\EntropyCore",
"$stage\include\EntropyCore\Core",
"$stage\include\EntropyCore\Concurrency",
"$stage\include\EntropyCore\Debug",
"$stage\include\EntropyCore\Graph",
"$stage\include\EntropyCore\Logging",
"$stage\include\EntropyCore\TypeSystem",
"$stage\lib\release"
)
foreach ($dir in $directories) {
New-Item -ItemType Directory -Force -Path $dir | Out-Null
}
# Bootstrap vcpkg if not present
$VCPKG_ROOT = if ($env:VCPKG_ROOT) { $env:VCPKG_ROOT } else { Join-Path $top "vcpkg" }
if (-not (Test-Path $VCPKG_ROOT)) {
Write-Host "Bootstrapping vcpkg..." -ForegroundColor Yellow
git clone https://github.com/Microsoft/vcpkg.git $VCPKG_ROOT
& "$VCPKG_ROOT\bootstrap-vcpkg.bat" -disableMetrics
if ($LASTEXITCODE -ne 0) {
throw "Failed to bootstrap vcpkg"
}
}
# Set up build directory
$BUILD_DIR = Join-Path $top "build_autobuild"
New-Item -ItemType Directory -Force -Path $BUILD_DIR | Out-Null
# Find Visual Studio installation
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if (Test-Path $vsWhere) {
$vsPath = & $vsWhere -latest -property installationPath
$vcVarsPath = Join-Path $vsPath "VC\Auxiliary\Build\vcvars64.bat"
if (Test-Path $vcVarsPath) {
Write-Host "Found Visual Studio at: $vsPath" -ForegroundColor Green
}
}
# Configure with CMake
Write-Host "Configuring with CMake..." -ForegroundColor Yellow
$cmakeArgs = @(
"-S", $top,
"-B", $BUILD_DIR,
"-G", "Visual Studio 17 2022",
"-A", $Platform,
"-DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT\scripts\buildsystems\vcpkg.cmake",
"-DVCPKG_TARGET_TRIPLET=$Platform-windows-static",
"-DCMAKE_BUILD_TYPE=$Configuration",
"-DBUILD_SHARED_LIBS=OFF",
"-DENTROPY_BUILD_TESTS=OFF",
"-DCMAKE_INSTALL_PREFIX=$stage"
)
& cmake $cmakeArgs
if ($LASTEXITCODE -ne 0) {
throw "CMake configuration failed"
}
# Build the project
Write-Host "Building EntropyCore..." -ForegroundColor Yellow
& cmake --build $BUILD_DIR --config $Configuration --parallel
if ($LASTEXITCODE -ne 0) {
throw "Build failed"
}
# Install to staging directory
Write-Host "Installing to staging directory..." -ForegroundColor Yellow
& cmake --install $BUILD_DIR --config $Configuration
if ($LASTEXITCODE -ne 0) {
throw "Installation failed"
}
# Move installed files to expected locations for autobuild
Write-Host "Reorganizing installed files for autobuild..." -ForegroundColor Yellow
# Ensure lib/release directory exists
New-Item -ItemType Directory -Force -Path "$stage\lib\release" | Out-Null
# Move the static library to release folder
$libSource = Join-Path $stage "lib\EntropyCore.lib"
if (Test-Path $libSource) {
Move-Item $libSource "$stage\lib\release\" -Force
Write-Host "Moved EntropyCore.lib to lib/release" -ForegroundColor Green
} else {
throw "EntropyCore.lib not found at $libSource"
}
# Move headers to EntropyCore subdirectory
if (Test-Path "$stage\include") {
$entropyInclude = "$stage\include\EntropyCore"
# If EntropyCore directory already exists (from previous runs), clear it
if (Test-Path $entropyInclude) {
Remove-Item $entropyInclude -Recurse -Force
}
New-Item -ItemType Directory -Force -Path $entropyInclude | Out-Null
# Move subdirectory headers
$headerDirs = @("Core", "Concurrency", "Debug", "Graph", "Logging", "TypeSystem")
foreach ($dir in $headerDirs) {
$sourcePath = Join-Path $stage "include\$dir"
$destPath = Join-Path $entropyInclude $dir
if (Test-Path $sourcePath) {
Move-Item $sourcePath $destPath -Force
}
}
# Move root headers
$mainHeaders = @("EntropyCore.h", "CoreCommon.h", "ServiceLocator.h")
foreach ($header in $mainHeaders) {
$headerPath = Join-Path $stage "include\$header"
$destPath = Join-Path $entropyInclude $header
if (Test-Path $headerPath) {
Move-Item $headerPath $destPath -Force
}
}
}
# Clean up cmake files that aren't needed for autobuild
$cmakeDir = Join-Path $stage "lib\cmake"
if (Test-Path $cmakeDir) {
Remove-Item $cmakeDir -Recurse -Force
Write-Host "Cleaned up cmake config files" -ForegroundColor Gray
}
# Create VERSION.txt
"$ENTROPYCORE_VERSION.$build" | Out-File -FilePath "$stage\VERSION.txt" -Encoding ASCII -NoNewline
# Copy license files - both to LICENSES directory and root for autobuild package
Copy-Item "$top\LICENSE.md" "$stage\LICENSES\EntropyCore.txt" -Force
Copy-Item "$top\LICENSE.md" "$stage\LICENSE.md" -Force
Write-Host "Build completed successfully!" -ForegroundColor Green
Write-Host "Artifacts staged in: $stage" -ForegroundColor Cyan
# List what was staged
Write-Host "`nStaged files:" -ForegroundColor Yellow
Get-ChildItem -Path $stage -Recurse -File | ForEach-Object {
$relativePath = $_.FullName.Substring($stage.Length + 1)
Write-Host " $relativePath" -ForegroundColor Gray
}
}
catch {
Write-Error "Build failed: $_"
exit 1
}
finally {
Pop-Location
}