-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ps1
220 lines (180 loc) · 7.82 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
function Check-RequiredTargets {
$requiredTargets = @("x86_64-pc-windows-msvc", "x86_64-unknown-linux-musl", "x86_64-apple-darwin")
$missingTargets = @()
foreach ($target in $requiredTargets) {
$installed = rustup target list | Select-String "^$target" | Select-String "installed"
if (-not $installed) {
$missingTargets += $target
}
}
if ($missingTargets.Count -gt 0) {
Write-Host "❌ Missing required targets:" -ForegroundColor Red
$missingTargets | ForEach-Object { Write-Host " - $_" -ForegroundColor Yellow }
Write-Host "`nPlease run install-targets.ps1 first to install missing targets." -ForegroundColor Cyan
return $false
}
return $true
}
# Check targets before continuing
if (-not (Check-RequiredTargets)) {
exit 1
}
function Create-ReleaseFolder {
$releasePath = "release"
if (Test-Path $releasePath) {
Remove-Item -Path $releasePath -Recurse -Force
}
New-Item -Path $releasePath -ItemType Directory | Out-Null
Write-Host "📁 Release folder created" -ForegroundColor Green
}
function Build-UI {
Write-Host "`n🎨 Building UI..." -ForegroundColor Cyan
$targets = @("x86_64-pc-windows-msvc", "x86_64-unknown-linux-musl", "x86_64-apple-darwin")
$progress = 0
$totalTargets = $targets.Count
foreach ($target in $targets) {
$progress++
$percent = [math]::Round(($progress / $totalTargets) * 100)
Write-Progress -Activity "Building UI" -Status "Target: $target" -PercentComplete $percent
Write-Host " 🔨 Building for $target..." -ForegroundColor Yellow
$buildResult = cargo build --release --target $target -p hot-reload-ui
if ($LASTEXITCODE -ne 0) {
Write-Host " ❌ Build failed for $target" -ForegroundColor Red
continue
}
$binName = if ($target -like "*windows*") { "hot-reload-ui.exe" } else { "hot-reload-ui" }
$sourcePath = "target/$target/release/$binName"
if (Test-Path $sourcePath) {
$zipName = "release/hot-reload-ui_$target.zip"
Compress-Archive -Path $sourcePath -DestinationPath $zipName -Force
Write-Host " ✅ Created $zipName" -ForegroundColor Green
} else {
Write-Host " ❌ Binary not found: $sourcePath" -ForegroundColor Red
}
}
Write-Progress -Activity "Building UI" -Completed
}
function Install-CrossIfNeeded {
if (-not (Get-Command "cross" -ErrorAction SilentlyContinue)) {
Write-Host "📥 Installing cross-rs..." -ForegroundColor Yellow
# Vérifier si Docker est installé
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
Write-Host "❌ Docker is required but not installed." -ForegroundColor Red
Write-Host "Please install Docker Desktop from: https://www.docker.com/products/docker-desktop" -ForegroundColor Yellow
return $false
}
# Installer cross
cargo install cross
if ($LASTEXITCODE -ne 0) {
Write-Host "❌ Failed to install cross" -ForegroundColor Red
return $false
}
Write-Host "✅ cross-rs installed successfully" -ForegroundColor Green
}
return $true
}
function Build-Watcher {
Write-Host "`n👀 Building Watcher..." -ForegroundColor Cyan
#Configurer l'environnement pour MUSL
$muslPath = "C:\musl\tools\bin"
if (Test-Path $muslPath) {
$env:PATH = "$muslPath;$env:PATH"
$env:CC_x86_64_unknown_linux_musl = "x86_64-linux-musl-gcc"
$env:CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "x86_64-linux-musl-gcc"
}
$targets = @("x86_64-pc-windows-msvc", "x86_64-unknown-linux-musl")
$progress = 0
$totalTargets = $targets.Count
foreach ($target in $targets) {
$progress++
$percent = [math]::Round(($progress / $totalTargets) * 100)
Write-Progress -Activity "Building Watcher" -Status "Target: $target" -PercentComplete $percent
Write-Host " 🔨 Building for $target..." -ForegroundColor Yellow
# Utiliser cross pour Linux
if ($target -eq "x86_64-unknown-linux-musl") {
# Vérifier/Installer cross si nécessaire
if (-not (Install-CrossIfNeeded)) {
Write-Host " ❌ Build failed for $target : cross-rs not available" -ForegroundColor Red
continue
}
# Utiliser le chemin complet de cross
$crossPath = Join-Path $env:USERPROFILE ".cargo\bin\cross.exe"
$buildResult = & $crossPath build --release --target $target -p hot-reload-watcher
} else {
$buildResult = cargo build --release --target $target -p hot-reload-watcher
}
if ($LASTEXITCODE -ne 0) {
Write-Host " ❌ Build failed for $target" -ForegroundColor Red
continue
}
$binName = if ($target -like "*windows*") { "hot-reload-watcher.exe" } else { "hot-reload-watcher" }
$sourcePath = "target/$target/release/$binName"
if (Test-Path $sourcePath) {
$tempDir = "temp_watcher"
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
Copy-Item $sourcePath -Destination $tempDir
Copy-Item "config.json" -Destination $tempDir -ErrorAction SilentlyContinue
$zipName = "release/hot-reload-watcher_$target.zip"
Compress-Archive -Path "$tempDir/*" -DestinationPath $zipName -Force
Remove-Item -Path $tempDir -Recurse -Force
Write-Host " ✅ Created $zipName" -ForegroundColor Green
}
}
Write-Progress -Activity "Building Watcher" -Completed
}
function Build-FXServer {
Write-Host "`n🎮 Building FX Server Resource..." -ForegroundColor Cyan
Write-Progress -Activity "Building FX Server" -Status "Running pnpm build" -PercentComplete 25
Push-Location resources/hot-reload
$buildResult = pnpm build
if ($LASTEXITCODE -ne 0) {
Write-Host " ❌ FX Server build failed" -ForegroundColor Red
Pop-Location
Write-Progress -Activity "Building FX Server" -Completed
return
}
Pop-Location
Write-Progress -Activity "Building FX Server" -Status "Creating archive" -PercentComplete 75
$tempDir = "temp_fxserver/hot-reload"
New-Item -Path $tempDir -ItemType Directory -Force | Out-Null
Copy-Item "resources/hot-reload/dist" -Destination $tempDir -Recurse
Copy-Item "resources/hot-reload/fxmanifest.lua" -Destination $tempDir
Compress-Archive -Path "temp_fxserver/*" -DestinationPath "release/hot-reload-fxserver.zip" -Force
Remove-Item -Path "temp_fxserver" -Recurse -Force
Write-Host " ✅ Created hot-reload-fxserver.zip" -ForegroundColor Green
Write-Progress -Activity "Building FX Server" -Completed
}
function Show-Menu {
Write-Host "`n🚀 Hot Reload Builder" -ForegroundColor Magenta
Write-Host "------------------------"
Write-Host "1. UI (Windows, Linux, MacOS)"
Write-Host "2. Watcher (Windows, Linux)"
Write-Host "3. FX Server Resource"
Write-Host "4. All"
Write-Host "5. Quit"
Write-Host "------------------------"
}
# Main
Create-ReleaseFolder
do {
Show-Menu
$choice = Read-Host "Choose an option"
switch ($choice) {
"1" { Build-UI }
"2" { Build-Watcher }
"3" { Build-FXServer }
"4" {
Build-UI
Build-Watcher
Build-FXServer
}
"5" {
Write-Host "`n👋 Bye!" -ForegroundColor Cyan
exit
}
default { Write-Host "`n❌ Invalid option" -ForegroundColor Red }
}
Write-Host "`nPress a key to continue..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Clear-Host
} while ($true)