-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_nvapi.ps1
More file actions
272 lines (238 loc) · 10.3 KB
/
build_nvapi.ps1
File metadata and controls
272 lines (238 loc) · 10.3 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
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
#!/usr/bin/env pwsh
# rebuild_nvapi.ps1 - Rebuilds NVAPI C# Wrapper and runs tests
#
# NVAPIWrapper Build Script (PowerShell)
# Builds the ClangSharp-based C# wrapper for NVAPI
#
# Get the directory where this script is located
$scriptRoot = $PSScriptRoot
if (-not $scriptRoot) {
$scriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
}
# Change to script directory
Set-Location $scriptRoot
Write-Host "Working directory: $scriptRoot" -ForegroundColor Cyan
Write-Host ""
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host "NVAPIWrapper Rebuild Script (ClangSharp Implementation)" -ForegroundColor Cyan
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host ""
# ============================================================================
# Read version from VERSION file and calculate build number from git commits
# ============================================================================
Write-Host "Determining version number..." -ForegroundColor Yellow
$versionFile = Join-Path $scriptRoot "VERSION"
if (-not (Test-Path $versionFile)) {
Write-Host "ERROR: VERSION file not found: $versionFile" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
# Read MAJOR and MINOR from VERSION file
$versionContent = Get-Content $versionFile
$major = "1"
$minor = "0"
foreach ($line in $versionContent) {
if ($line -match "^MAJOR=(\d+)") {
$major = $matches[1]
}
elseif ($line -match "^MINOR=(\d+)") {
$minor = $matches[1]
}
}
# Get git commit count for PATCH/build number
$patch = "0"
try {
# Check if git is available
$gitPath = Get-Command git -ErrorAction SilentlyContinue
if ($gitPath) {
# Get the commit count
$commitCount = & git rev-list --count HEAD 2>&1
if ($LASTEXITCODE -eq 0 -and $commitCount -match "^\d+$") {
$patch = $commitCount
}
else {
Write-Host "Warning: Could not get git commit count, using 0" -ForegroundColor Yellow
}
}
else {
Write-Host "Warning: git not found in PATH, using PATCH=0" -ForegroundColor Yellow
}
}
catch {
Write-Host "Warning: Error reading git commit count: $_" -ForegroundColor Yellow
Write-Host "Using PATCH=0" -ForegroundColor Yellow
}
$version = "$major.$minor.$patch"
Write-Host "Version: $version" -ForegroundColor Green
Write-Host " MAJOR: $major (from VERSION file)" -ForegroundColor Gray
Write-Host " MINOR: $minor (from VERSION file)" -ForegroundColor Gray
Write-Host " PATCH: $patch (git commit count)" -ForegroundColor Gray
Write-Host ""
# ============================================================================
# Verify dotnet CLI is available
# ============================================================================
Write-Host "Checking for .NET CLI..." -ForegroundColor Yellow
try {
$dotnetPath = Get-Command dotnet -ErrorAction Stop
$dotnetVersion = & dotnet --version 2>&1
Write-Host ".NET CLI found: $($dotnetPath.Source)" -ForegroundColor Green
Write-Host ".NET version: $dotnetVersion" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host ""
Write-Host "ERROR: dotnet CLI not found in PATH" -ForegroundColor Red
Write-Host ""
Write-Host "Please ensure .NET 10.0 SDK is installed" -ForegroundColor Yellow
Write-Host "Download from: https://dotnet.microsoft.com/download/dotnet/10.0" -ForegroundColor Cyan
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
# ============================================================================
# Check .NET 10.0 SDK availability
# ============================================================================
Write-Host "Checking for .NET 10.0 SDK..." -ForegroundColor Yellow
try {
$sdks = & dotnet --list-sdks 2>&1
$net9Sdk = $sdks | Where-Object { $_ -match "10\.0\." }
if ($net9Sdk) {
Write-Host ".NET 10.0 SDK found:" -ForegroundColor Green
$net9Sdk | ForEach-Object { Write-Host " $_" -ForegroundColor Green }
Write-Host ""
} else {
Write-Host ""
Write-Host "ERROR: .NET 10.0 SDK not found" -ForegroundColor Red
Write-Host ""
Write-Host "Available SDKs:" -ForegroundColor Yellow
$sdks | ForEach-Object { Write-Host " $_" -ForegroundColor Gray }
Write-Host ""
Write-Host "Please install .NET 10.0 SDK from: https://dotnet.microsoft.com/download/dotnet/10.0" -ForegroundColor Cyan
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
} catch {
Write-Host ""
Write-Host "ERROR: Failed to check .NET SDK version: $_" -ForegroundColor Red
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "Checking for NVIDIA NVAPI SDK..." -ForegroundColor Yellow
# Check if NVAPI SDK headers are present
$nvapiHeaderPath = "nvapi\\nvapi.h"
if (-not (Test-Path $nvapiHeaderPath)) {
Write-Host "Warning: NVAPI SDK headers not found at $nvapiHeaderPath" -ForegroundColor Yellow
Write-Host "Please run prepare_nvapi.ps1 first to download the NVAPI SDK." -ForegroundColor Yellow
Read-Host "Press Enter to exit"
exit 1
}
Write-Host "NVIDIA NVAPI SDK found" -ForegroundColor Gray
# ============================================================================
# Restore NuGet packages
# ============================================================================
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host "Restoring NuGet packages..." -ForegroundColor Cyan
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host ""
$solutionPath = Join-Path $scriptRoot "NVAPIWrapper.sln"
if (-not (Test-Path $solutionPath)) {
Write-Host "ERROR: Solution file not found: $solutionPath" -ForegroundColor Red
Read-Host "Press Enter to exit"
exit 1
}
try {
& dotnet restore $solutionPath
if ($LASTEXITCODE -ne 0) {
throw "Restore failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-Host "NuGet packages restored successfully!" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host ""
Write-Host "ERROR: Failed to restore NuGet packages!" -ForegroundColor Red
Write-Host "Error: $_" -ForegroundColor Yellow
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
# ============================================================================
# Clean the solution
# ============================================================================
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host "Cleaning NVAPIWrapper solution..." -ForegroundColor Cyan
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host ""
try {
Write-Host "dotnet clean $solutionPath"
dotnet clean $solutionPath
if ($LASTEXITCODE -ne 0) {
throw "Clean failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-Host "Clean completed successfully!" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host ""
Write-Host "ERROR: Clean failed!" -ForegroundColor Red
Write-Host "Error: $_" -ForegroundColor Yellow
Write-Host ""
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host " - Ensure all NuGet packages are restored" -ForegroundColor Gray
Write-Host " - Verify .NET 10.0 SDK is installed" -ForegroundColor Gray
Write-Host " - Check project files for errors" -ForegroundColor Gray
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
# ============================================================================
# Rebuild the solution
# ============================================================================
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host "Rebuilding NVAPIWrapper solution..." -ForegroundColor Cyan
Write-Host "============================================================================" -ForegroundColor Cyan
Write-Host ""
# Build the C# wrapper project (ClangSharp will generate P/Invoke bindings during build)
Write-Host "`nBuilding NVAPIWrapper C# project..." -ForegroundColor Cyan
try
{
Write-Host "dotnet build $solutionPath --configuration Debug --no-restore /p:Version=$version /p:AssemblyVersion=$version /p:FileVersion=$version"
dotnet build $solutionPath --configuration Debug --no-restore /p:Version=$version /p:AssemblyVersion=$version /p:FileVersion=$version
#& dotnet build NVAPIWrapper\NVAPIWrapper.csproj -c Debug
if ($LASTEXITCODE -ne 0) {
throw "Rebuild failed with exit code $LASTEXITCODE"
}
Write-Host ""
Write-Host "Rebuild completed successfully!" -ForegroundColor Green
Write-Host ""
} catch {
Write-Host ""
Write-Host "ERROR: Rebuild failed!" -ForegroundColor Red
Write-Host "Error: $_" -ForegroundColor Yellow
Write-Host ""
Write-Host "Troubleshooting:" -ForegroundColor Yellow
Write-Host " - Ensure all NuGet packages are restored" -ForegroundColor Gray
Write-Host " - Verify .NET 10.0 SDK is installed" -ForegroundColor Gray
Write-Host " - Check project files for errors" -ForegroundColor Gray
Write-Host ""
Read-Host "Press Enter to exit"
exit 1
}
# ============================================================================
# Success summary
# ============================================================================
Write-Host "============================================================================" -ForegroundColor Green
Write-Host "*** REBUILD SUCCESSFUL! ***" -ForegroundColor Green
Write-Host "============================================================================" -ForegroundColor Green
Write-Host ""
Write-Host "Projects built:" -ForegroundColor Cyan
Write-Host " - NVAPIWrapper (ClangSharp-based wrapper)" -ForegroundColor Green
Write-Host " - NVAPIWrapper.Tests (Test suite)" -ForegroundColor Green
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Cyan
Write-Host " - Run tests: .\test_nvapi.ps1" -ForegroundColor Gray
Write-Host " - Use in your project: Add reference to NVAPIWrapper\NVAPIWrapper.csproj" -ForegroundColor Gray
Write-Host ""
Write-Host "Press Enter to exit..."
Read-Host