mirror of
https://github.com/Kudaes/Puzzle
synced 2026-06-06 16:04:33 +00:00
71 lines
1.6 KiB
PowerShell
71 lines
1.6 KiB
PowerShell
param(
|
|
[ValidateSet("menu","build","clean")]
|
|
[string]$Action = "menu",
|
|
|
|
[ValidateSet("debug","release")]
|
|
[string]$Mode = "debug"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
function Get-Projects {
|
|
Get-ChildItem -Directory |
|
|
Where-Object { Test-Path (Join-Path $_.FullName "Cargo.toml") }
|
|
}
|
|
|
|
function Run-ForAllProjects([ScriptBlock]$Cmd) {
|
|
$projects = Get-Projects
|
|
if (-not $projects) {
|
|
Write-Host "No Rust projects (Cargo.toml) found in direct subfolders."
|
|
exit 1
|
|
}
|
|
|
|
foreach ($p in $projects) {
|
|
$manifest = Join-Path $p.FullName "Cargo.toml"
|
|
Write-Host "`n==> $($p.Name)"
|
|
& $Cmd $manifest
|
|
}
|
|
|
|
Write-Host "`nDone. Processed $($projects.Count) projects."
|
|
}
|
|
|
|
function Do-Build([string]$mode) {
|
|
Run-ForAllProjects {
|
|
param($manifest)
|
|
if ($mode -eq "release") {
|
|
cargo build --manifest-path $manifest --release
|
|
} else {
|
|
cargo build --manifest-path $manifest
|
|
}
|
|
if ($LASTEXITCODE -ne 0) { throw "Build failed." }
|
|
}
|
|
}
|
|
|
|
function Do-Clean {
|
|
Run-ForAllProjects {
|
|
param($manifest)
|
|
cargo clean --manifest-path $manifest
|
|
if ($LASTEXITCODE -ne 0) { throw "Clean failed." }
|
|
}
|
|
}
|
|
|
|
if ($Action -eq "menu") {
|
|
Write-Host "Choose an action:"
|
|
Write-Host " 1) Build (debug)"
|
|
Write-Host " 2) Build (release)"
|
|
Write-Host " 3) Clean"
|
|
Write-Host " 4) Exit"
|
|
$choice = Read-Host "Selection"
|
|
|
|
switch ($choice) {
|
|
"1" { Do-Build "debug" }
|
|
"2" { Do-Build "release" }
|
|
"3" { Do-Clean }
|
|
default { Write-Host "Bye."; exit 0 }
|
|
}
|
|
} elseif ($Action -eq "build") {
|
|
Do-Build $Mode
|
|
} elseif ($Action -eq "clean") {
|
|
Do-Clean
|
|
}
|