-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-module.ps1
More file actions
198 lines (167 loc) · 4.68 KB
/
build-module.ps1
File metadata and controls
198 lines (167 loc) · 4.68 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
<#
.SYNOPSIS
Unified build script for compiling C# Binary Module (AOT and Managed)
.DESCRIPTION
Easily build both/AOT/managed versions of the C# Binary Module
#>
param(
[ValidateSet('aot', 'managed', 'both')]
[Alias('t')]
[string]$Type = 'both',
[Alias('c')]
[switch]$Clean,
[switch]$Help
)
function Show-Help
{
Write-Host "Usage: ./build-module.ps1 [OPTIONS]"
Write-Host ""
Write-Host "Options:"
Write-Host " -Type, -t <string> Build type: aot, managed, or both (default: both)"
Write-Host " -Clean, -c Clean build artifacts before building"
Write-Host " -Help Show this help message"
Write-Host ""
Write-Host "Examples:"
Write-Host " ./build-module.ps1 # Build both AOT and managed"
Write-Host " ./build-module.ps1 -t aot # Build only AOT version"
Write-Host " ./build-module.ps1 -Type managed # Build only managed version"
Write-Host " ./build-module.ps1 -c # Clean only"
Write-Host " ./build-module.ps1 -t AOT -c # Clean then build AOT (case-insensitive)"
}
function Clean-BuildArtifacts
{
Write-Host "Cleaning build artifacts..." -ForegroundColor Yellow
# Clean bin directories
if (Test-Path "bin")
{
Remove-Item -Recurse -Force "bin"
}
if (Test-Path "dnGLua.BinaryModule\bin")
{
Remove-Item -Recurse -Force "dnGLua.BinaryModule\bin"
}
# Clean output directories created by build script
if (Test-Path "bin-aot")
{
Remove-Item -Recurse -Force "bin-aot"
}
if (Test-Path "bin-managed")
{
Remove-Item -Recurse -Force "bin-managed"
}
# Clean obj directories
if (Test-Path "dnGLua.BinaryModule\obj")
{
Remove-Item -Recurse -Force "dnGLua.BinaryModule\obj"
}
Write-Host "Clean completed" -ForegroundColor Green
}
function Build-AotModule
{
Write-Host "Building AOT module..." -ForegroundColor Cyan
#Push-Location "dnGLua.BinaryModule"
try
{
# Update NuGet
#& nuget update -self
#if ($LASTEXITCODE -ne 0) {
# Write-Host "Warning: NuGet update failed, continuing..." -ForegroundColor Yellow
#}
# Try NuGet restore (may fail)
#& nuget restore
#if ($LASTEXITCODE -ne 0) {
# Write-Host "NuGet restore not applicable, using dotnet restore..." -ForegroundColor Yellow
#}
# Force restore
& dotnet restore --force
if ($LASTEXITCODE -ne 0)
{
throw "dotnet restore failed"
}
# Build AOT binary module for current platform
& dotnet publish -c Release /p:PublishAot=true -v detailed -o bin-aot
if ($LASTEXITCODE -ne 0)
{
throw "AOT build failed"
}
Write-Host "AOT build completed successfully" -ForegroundColor Green
}
finally
{
#Pop-Location
}
}
function Build-ManagedModule
{
Write-Host "Building managed module..." -ForegroundColor Cyan
#Push-Location "dnGLua.BinaryModule"
try
{
# Update NuGet
#& nuget update -self
#if ($LASTEXITCODE -ne 0) {
# Write-Host "Warning: NuGet update failed, continuing..." -ForegroundColor Yellow
#}
# Try NuGet restore (may fail)
#& nuget restore
#if ($LASTEXITCODE -ne 0) {
# Write-Host "NuGet restore not applicable, using dotnet restore..." -ForegroundColor Yellow
#}
# Force restore
& dotnet restore --force
if ($LASTEXITCODE -ne 0)
{
throw "dotnet restore failed"
}
# Build managed binary module
& dotnet build -c Release --no-restore --no-incremental -v detailed -o bin-managed
if ($LASTEXITCODE -ne 0)
{
throw "Managed build failed"
}
Write-Host "Managed build completed successfully" -ForegroundColor Green
}
finally
{
#Pop-Location
}
}
# Main execution
if ($Help)
{
Show-Help
exit 0
}
# Make Type parameter case-insensitive
$Type = $Type.ToLowerInvariant()
# Check if we're in the right directory
if (-not (Test-Path "dnGLua.BinaryModule\dnGLua.BinaryModule.csproj"))
{
Write-Host "Error: dnGLua.BinaryModule.csproj not found!" -ForegroundColor Red
Write-Host "Please run this script from the project root directory." -ForegroundColor Red
exit 1
}
# Clean if requested
if ($Clean)
{
Clean-BuildArtifacts
# If only -Clean was specified (no -Type), exit after cleaning
if ($Type -eq 'both' -and -not $PSBoundParameters.ContainsKey('Type'))
{
Write-Host "Clean completed. No build specified." -ForegroundColor Green
exit 0
}
}
# Build based on type
$buildAot = $Type -eq 'aot' -or $Type -eq 'both'
$buildManaged = $Type -eq 'managed' -or $Type -eq 'both'
Write-Host "Building: $Type" -ForegroundColor Cyan
if ($buildAot)
{
Build-AotModule
}
if ($buildManaged)
{
Build-ManagedModule
}
Write-Host "All builds completed successfully!" -ForegroundColor Green