yandex-music-rs/packaging/build-windows-installer.ps1
2026-11-29 02:28:03 +03:00

66 lines
2.3 KiB
PowerShell

$ErrorActionPreference = "Stop"
$RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
$CargoToml = Get-Content (Join-Path $RepoRoot "Cargo.toml") -Raw
if ($CargoToml -match '(?m)^version\s*=\s*"([^"]+)"') {
$Version = $Matches[1]
} else {
throw "Could not parse version from Cargo.toml"
}
$AppExe = Join-Path $RepoRoot "target\release\yandex-music-rs.exe"
$CargoArgs = @("build", "--release", "--bin", "yandex-music-rs")
$RunningLocked = Get-Process -Name "yandex-music-rs" -ErrorAction SilentlyContinue |
Where-Object { $_.Path -eq $AppExe }
if ($RunningLocked) {
$StageTarget = Join-Path $RepoRoot "target\installer-stage"
Write-Host " (target\release\yandex-music-rs.exe is running; staging into target\installer-stage)" -ForegroundColor DarkGray
$CargoArgs += @("--target-dir", $StageTarget)
$AppExe = Join-Path $StageTarget "release\yandex-music-rs.exe"
}
Write-Host "==> Building yandex-music-rs v$Version (release)..." -ForegroundColor Yellow
Push-Location $RepoRoot
try {
& cargo @CargoArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally {
Pop-Location
}
if (-not (Test-Path $AppExe)) {
throw "Expected app binary not found: $AppExe"
}
Write-Host "==> Building Windows GUI installer (yandex-music-rs-setup.exe)..." -ForegroundColor Yellow
$InstallerDir = Join-Path $RepoRoot "packaging\windows\installer"
$env:YM_PAYLOAD_EXE = $AppExe
Push-Location $InstallerDir
try {
& cargo build --release
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
} finally {
Pop-Location
}
$SetupExe = Join-Path $InstallerDir "target\release\yandex-music-rs-setup.exe"
if (-not (Test-Path $SetupExe)) {
throw "Expected installer binary not found: $SetupExe"
}
$DistDir = Join-Path $RepoRoot "target\release-dist-v$Version"
New-Item -ItemType Directory -Force -Path $DistDir | Out-Null
$OutPortable = Join-Path $DistDir "yandex-music-rs-v$Version-windows-x86_64.exe"
$OutSetup = Join-Path $DistDir "yandex-music-rs-v$Version-windows-x86_64-setup.exe"
Copy-Item -Force $AppExe $OutPortable
Copy-Item -Force $SetupExe $OutSetup
$pSize = [math]::Round((Get-Item $OutPortable).Length / 1MB, 2)
$sSize = [math]::Round((Get-Item $OutSetup).Length / 1MB, 2)
Write-Host ""
Write-Host "Done!" -ForegroundColor Green
Write-Host " Portable : $OutPortable ($pSize MB)"
Write-Host " Installer: $OutSetup ($sSize MB)"