<#
    Rust 项目一键构建所有 Features
    适配你的全部 feature 列表
    每个 feature 独立编译，不叠加
#>

$ErrorActionPreference = "Stop"

# 你的所有 feature 列表（完整复制）
$features = @(
    "sys_random",
    "process",
    "ctf",
    "httprs",
    "json",
    "clip",
    "xlsx",
    "docx",
    "date",
    "mouse",
    "keyboard",
    "kcm",
    "screenshot",
    "images",
    "crypto",
    "asyncrs",
    "logger",
    "ip_addr",
    "sqlserver",
    "axumserver",
    "exiftool",
    "full"
)

Clear-Host
Write-Host "=============================================" -ForegroundColor Cyan
Write-Host "  一键构建所有 Rust Feature (独立编译)" -ForegroundColor Green
Write-Host "=============================================" -ForegroundColor Cyan

# 遍历构建
foreach ($feat in $features) {
    Write-Host "`n==================================================" -ForegroundColor Blue
    Write-Host "  正在构建：--features $feat" -ForegroundColor Green
    Write-Host "==================================================" -ForegroundColor Blue
    if ($feat -eq "full") {
        cargo clean
        cargo build --features "$feat"
        continue
    }
    
    # 核心：每次只启用当前 feature
    cargo build --features "$feat"

    # 出错自动停止
    if ($LASTEXITCODE -ne 0) {
        Write-Error "构建失败：$feat"
        exit 1
    }
}

Write-Host "`n=============================================" -ForegroundColor Green
Write-Host "✅ 所有 Feature 构建完成！" -ForegroundColor Green
Write-Host "📦 输出目录：.\target\release\" -ForegroundColor White
Write-Host "=============================================`n" -ForegroundColor Green