Mulberry/packaging/windows/build-windows.ps1
Jacob Ward 623ced06b7 Build scripts: Windows (PowerShell) and Linux from source
packaging/windows/build-windows.ps1 makes the portable zip and the installer;
packaging/linux/build-linux.sh makes the tarball and the AppImage. Both follow
the steps of the CI workflow.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 01:05:23 -05:00

74 lines
3.7 KiB
PowerShell

# Builds Mulberry for Windows from source: the app folder, a portable zip and the installer.
# Same steps as the "windows" job in .github/workflows/build.yml.
#
# Needs: Python 3.11+ (python.org, with the "py" launcher), internet for the first run.
# Optional: Inno Setup 6 or 7 (for Mulberry-Windows-Setup.exe), 7-Zip (to unpack libmpv; tar is tried otherwise).
#
# Run from anywhere:
# powershell -ExecutionPolicy Bypass -File packaging\windows\build-windows.ps1
# Output: dist\Mulberry-Windows-Portable.zip and dist\Mulberry-Windows-Setup.exe
$ErrorActionPreference = "Stop"
$root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
Set-Location $root
$version = (Select-String -Path mulberry\config.py -Pattern 'VERSION = "(.+?)"').Matches[0].Groups[1].Value
Write-Host "== Mulberry $version"
# ---- Python environment (.venv in the repo)
if (-not (Test-Path .venv\Scripts\python.exe)) {
Write-Host "== Creating .venv"
if (Get-Command py -ErrorAction SilentlyContinue) { py -3 -m venv .venv } else { python -m venv .venv }
}
$py = Join-Path $root ".venv\Scripts\python.exe"
& $py -m pip install --upgrade pip
& $py -m pip install -r requirements.txt pyinstaller
if ($LASTEXITCODE -ne 0) { throw "pip install failed" }
# ---- Icons
& $py packaging\make_icons.py
if ($LASTEXITCODE -ne 0) { throw "make_icons.py failed" }
# ---- libmpv (gapless, EQ, CD playback). Skipped with a warning if it can't be fetched.
$mpvDir = "packaging\windows\mpv"
if (-not (Test-Path "$mpvDir\libmpv-2.dll")) {
try {
Write-Host "== Downloading libmpv"
$rel = Invoke-RestMethod "https://api.github.com/repos/shinchiro/mpv-winbuild-cmake/releases/latest"
$asset = $rel.assets | Where-Object { $_.name -match '^mpv-dev-x86_64-\d{8}-git-[0-9a-f]+\.7z$' } | Select-Object -First 1
if (-not $asset) { throw "libmpv asset not found" }
New-Item -ItemType Directory -Force build | Out-Null
Invoke-WebRequest $asset.browser_download_url -OutFile build\mpv-dev.7z
New-Item -ItemType Directory -Force build\mpv-dev, $mpvDir | Out-Null
$sevenZip = @("$env:ProgramFiles\7-Zip\7z.exe", "${env:ProgramFiles(x86)}\7-Zip\7z.exe") | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($sevenZip) { & $sevenZip x build\mpv-dev.7z -obuild\mpv-dev -y | Out-Null }
else { tar -xf build\mpv-dev.7z -C build\mpv-dev }
Copy-Item build\mpv-dev\libmpv-2.dll $mpvDir\
} catch {
Write-Warning "No libmpv ($_). The app still works, but without gapless/EQ/CD. Install 7-Zip and run again to include it."
}
}
# ---- PyInstaller
Write-Host "== PyInstaller"
& $py -m PyInstaller packaging\mulberry.spec --noconfirm --distpath build\dist --workpath build\work
if ($LASTEXITCODE -ne 0) { throw "PyInstaller failed" }
# ---- Portable zip
New-Item -ItemType Directory -Force dist | Out-Null
Remove-Item dist\Mulberry-Windows-Portable.zip -ErrorAction SilentlyContinue
Compress-Archive -Path build\dist\Mulberry -DestinationPath dist\Mulberry-Windows-Portable.zip
Write-Host "== dist\Mulberry-Windows-Portable.zip"
# ---- Installer (Inno Setup)
$iscc = @("${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe", "${env:ProgramFiles(x86)}\Inno Setup 7\ISCC.exe",
"$env:ProgramFiles\Inno Setup 6\ISCC.exe", "$env:ProgramFiles\Inno Setup 7\ISCC.exe",
"$env:LOCALAPPDATA\Programs\Inno Setup 6\ISCC.exe", "$env:LOCALAPPDATA\Programs\Inno Setup 7\ISCC.exe") |
Where-Object { Test-Path $_ } | Select-Object -First 1
if ($iscc) {
& $iscc "/DAppVersion=$version" packaging\windows\mulberry.iss
if ($LASTEXITCODE -ne 0) { throw "Inno Setup failed" }
Write-Host "== dist\Mulberry-Windows-Setup.exe"
} else {
Write-Warning "Inno Setup not found, so no installer was made (https://jrsoftware.org/isdl.php). The portable zip is ready."
}