141 lines
7.5 KiB
PowerShell
141 lines
7.5 KiB
PowerShell
# build_windows.ps1 - ONE-COMMAND build: daw_engine.exe (PyInstaller) + Tauri v2 (NSIS + MSI)
|
|
# Chay tren Windows: powershell -ExecutionPolicy Bypass -File build_windows.ps1
|
|
# LUU Y: file nay chi dung ky tu ASCII (khong dau, khong em-dash) - PowerShell 5.1
|
|
# doc .ps1 khong BOM theo ANSI, ky tu Unicode bi hong -> "String is missing terminator".
|
|
$ErrorActionPreference = "Stop"
|
|
Set-Location $PSScriptRoot
|
|
|
|
# Kill moi daw_engine con song tu build/truoc (windowed, khong console ->
|
|
# de quen -> file exe dang chay bi khoa -> Tauri build loi PermissionDenied
|
|
# khi doc externalBin). Stop-Process im lang neu khong co tien trinh nao.
|
|
Write-Host "== [0/6] Kill daw_engine.exe cu (neu dang chay) =="
|
|
Get-Process -Name "daw_engine" -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
|
|
Start-Sleep -Milliseconds 500
|
|
|
|
Write-Host "== [1/6] Python dependencies =="
|
|
python -m pip install --upgrade pip
|
|
python -m pip install -r requirements.txt pyinstaller pywin32
|
|
|
|
Write-Host "== [2/6] Frontend bundle (app.jsx -> app.precompiled.js) =="
|
|
npm install
|
|
# Dam bao @babel/standalone co (build.mjs import truc tiep - da gap
|
|
# ERR_MODULE_NOT_FOUND tren may Windows khi package.json cu thieu dep).
|
|
if (-not (Test-Path "node_modules\@babel\standalone")) {
|
|
Write-Host "Thieu @babel/standalone - dang cai them..."
|
|
npm install @babel/standalone --no-audit --no-fund
|
|
}
|
|
if (-not (Test-Path "node_modules\@babel\standalone")) {
|
|
Write-Host "ERROR: Khong cai duoc @babel/standalone. Kiem tra ket noi npm!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
node build.mjs # @babel/standalone; thay cho 'npm run build' (Babel 8 ESM-only CLI conflict)
|
|
|
|
Write-Host "== [3/6] Build daw_engine.exe (PyInstaller) =="
|
|
pyinstaller engine.spec --clean --noconfirm
|
|
|
|
Write-Host "== [3.5/6] Verify bundle contents (app/static, app/templates phai co) =="
|
|
# Bat loi bundle NGAY tai build (da gap 2 lan: chay pyinstaller tu noi khac
|
|
# -> static/templates thieu -> exe crash 'Directory ...\app\static does not exist').
|
|
# Dung tools/verify_bundle.py (parse TOC bang ast, chap nhan ca / va \) thay
|
|
# vi regex thong thuong (TOC Windows co the dung backslash -> false positive).
|
|
# Truoc tien kiem tra engine.spec phai la ban moi (collect_data_files).
|
|
$specContent = Get-Content "engine.spec" -Raw -ErrorAction SilentlyContinue
|
|
if ($specContent -notmatch "collect_data_files\('app'") {
|
|
Write-Host "ERROR: engine.spec CU (thieu collect_data_files('app')). Pull code moi truoc khi build!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
python tools\verify_bundle.py
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Host "ERROR: Bundle thieu asset - dung build, kiem tra engine.spec datas!" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
|
|
Write-Host "== [4/6] ONEDIR engine -> src-tauri/resources/daw_engine (Tauri resources) =="
|
|
# ONEDIR: copy ca thu muc dist\daw_engine\ (exe + _internal) vao resources.
|
|
# Tauri bundle resources -> resource_dir()/daw_engine/daw_engine.exe luc runtime.
|
|
if (-not (Test-Path "dist\daw_engine\daw_engine.exe")) {
|
|
Write-Host "ERROR: dist\daw_engine\daw_engine.exe khong ton tai (onedir build loi?)" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
if (Test-Path "src-tauri\resources\daw_engine") {
|
|
Remove-Item -Recurse -Force "src-tauri\resources\daw_engine"
|
|
}
|
|
New-Item -ItemType Directory -Force "src-tauri\resources\daw_engine" | Out-Null
|
|
Copy-Item "dist\daw_engine\*" "src-tauri\resources\daw_engine\" -Recurse -Force
|
|
Write-Host "Copied onedir engine -> src-tauri\resources\daw_engine"
|
|
|
|
Write-Host "== [4b/6] Native host bridges (CMake/MSVC) + FluidSynth runtime =="
|
|
# T8-T16: vst2/vst3/sf_host_bridge DLL + fluidsynth_runtime (22 DLL) phai nam
|
|
# trong resources/native_host/ de exe tim thay luc runtime (Rust: resource_dir/
|
|
# native_host; Python: SF_RESOURCE_DIR/native_host). Thieu -> native audio /
|
|
# VST GUI khong chay tren may cai sach.
|
|
#
|
|
# Prebuilt: 3 bridge DLL (~175KB) DUOC COMMIT vao src-tauri/resources/native_host/
|
|
# (.gitignore cho phep *.dll) de nguoi dung clone moi KHONG can VST3 SDK
|
|
# (Steinberg SDK ban quyen) + khong can MSVC/cmake. Chi build tu source khi
|
|
# ca 3 DLL deu thieu (may dev tu build bridge moi).
|
|
$bridgeDlls = @("sf_host_bridge.dll","vst2_host_bridge.dll","vst3_host_bridge.dll")
|
|
$havePrebuilt = $true
|
|
foreach ($dllName in $bridgeDlls) {
|
|
if (-not (Test-Path "src-tauri\resources\native_host\$dllName")) { $havePrebuilt = $false }
|
|
}
|
|
if ($havePrebuilt) {
|
|
Write-Host "Dung prebuilt bridge DLL (resources/native_host) - skip cmake build, khong can VST3 SDK."
|
|
} else {
|
|
if (-not (Test-Path "native_host\build\CMakeCache.txt")) {
|
|
if (-not $env:VST3_SDK_ROOT) {
|
|
Write-Host "ERROR: thieu prebuilt bridge DLL + khong co native_host\build + VST3_SDK_ROOT chua set." -ForegroundColor Red
|
|
Write-Host " Cach 1 (khuyen nghi): git pull lai de co src-tauri/resources/native_host/*.dll (prebuilt)." -ForegroundColor Yellow
|
|
Write-Host " Cach 2 (dev): set env VST3_SDK_ROOT tro den VST3 SDK roi build lai native_host." -ForegroundColor Yellow
|
|
exit 1
|
|
}
|
|
& cmake -S native_host -B native_host\build -A x64 -DVST3_SDK_ROOT="$env:VST3_SDK_ROOT"
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: cmake configure native_host that bai" -ForegroundColor Red; exit 1 }
|
|
}
|
|
& cmake --build native_host\build --config Release
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: cmake build native_host that bai" -ForegroundColor Red; exit 1 }
|
|
Copy-Item "native_host\build\Release\vst2_host_bridge.dll","native_host\build\Release\vst3_host_bridge.dll","native_host\build\Release\sf_host_bridge.dll" "src-tauri\resources\native_host\"
|
|
}
|
|
|
|
# fluidsynth_runtime (14.8MB, gitignore) - khong commit; tu dong tai neu thieu.
|
|
if (-not (Test-Path "src-tauri\resources\native_host\fluidsynth_runtime\libfluidsynth-3.dll")) {
|
|
if (-not (Test-Path "native_host\fluidsynth_runtime\libfluidsynth-3.dll")) {
|
|
python native_host\scripts\dl_fluidsynth_runtime.py
|
|
if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: dl_fluidsynth_runtime that bai" -ForegroundColor Red; exit 1 }
|
|
}
|
|
New-Item -ItemType Directory -Force "src-tauri\resources\native_host\fluidsynth_runtime" | Out-Null
|
|
Copy-Item "native_host\fluidsynth_runtime\*" "src-tauri\resources\native_host\fluidsynth_runtime\" -Recurse -Force
|
|
} else {
|
|
Write-Host "Da co fluidsynth_runtime trong resources/native_host."
|
|
}
|
|
|
|
Write-Host "== [5/6] VC++ Redistributable cho hooks.nsh =="
|
|
if (-not (Test-Path src-tauri\vc_redist.x64.exe)) {
|
|
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile src-tauri\vc_redist.x64.exe
|
|
}
|
|
|
|
Write-Host "== [6/6] Tauri build (NSIS .exe + MSI) =="
|
|
# Guard: resources/daw_engine PHAI co exe + _internal truoc khi tauri build
|
|
# (glob trong tauri.conf.json fail ngay "path not found" neu thieu).
|
|
if (-not (Test-Path "src-tauri\resources\daw_engine\daw_engine.exe")) {
|
|
Write-Host "ERROR: src-tauri\resources\daw_engine\daw_engine.exe khong co - buoc [4/6] that bai?" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
if (-not (Test-Path "src-tauri\resources\daw_engine\_internal")) {
|
|
Write-Host "ERROR: thieu src-tauri\resources\daw_engine\_internal (onedir khong day du)" -ForegroundColor Red
|
|
exit 1
|
|
}
|
|
npm install -D @tauri-apps/cli
|
|
npx tauri build
|
|
|
|
Write-Host ""
|
|
Write-Host "== DONE =="
|
|
Write-Host " NSIS: src-tauri\target\release\bundle\nsis\SonicForgeDAW_1.0.0_x64-setup.exe"
|
|
Write-Host " MSI : src-tauri\target\release\bundle\msi\SonicForgeDAW_1.0.0_x64_en-US.msi"
|
|
Write-Host ""
|
|
Write-Host "== XAC MINH SAU KHI CAI DAT (quan trong) =="
|
|
Write-Host " Mo %APPDATA%\SonicForgeDAW\logs\spawn.log - phai thay:"
|
|
Write-Host " [resource_dir/daw_engine (map layout)] ...exists=True"
|
|
Write-Host " Neu exists=False: bundle resources KHONG vao installer (chay lai buoc [4/6])."
|
|
Write-Host " Engine phai nam o: <thu muc cai dat>\daw_engine\daw_engine.exe"
|