From 916ce1334be39bef4fccfd04e142dfbcab9f007f Mon Sep 17 00:00:00 2001 From: locphamtran Date: Tue, 11 Aug 2026 18:48:06 +0700 Subject: [PATCH] build: bundle native_host bridges + fluidsynth runtime vao installer (build_windows.ps1 [4b/6], SF_RESOURCE_DIR fallback, tauri resources native_host) --- .gitignore | 2 ++ app/core/native_audio_service.py | 8 +++++-- app/core/soundfont_converter.py | 6 ++++- build_windows.ps1 | 28 ++++++++++++++++++++++++ src-tauri/resources/native_host/.gitkeep | 0 src-tauri/src/lib.rs | 1 + src-tauri/src/vst_gui.rs | 1 + src-tauri/tauri.conf.json | 3 ++- 8 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 src-tauri/resources/native_host/.gitkeep diff --git a/.gitignore b/.gitignore index a04a398..7ce5928 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,8 @@ node_modules src-tauri/target/ src-tauri/binaries/ src-tauri/resources/daw_engine/ +src-tauri/resources/native_host/* +!src-tauri/resources/native_host/.gitkeep src-tauri/vc_redist.x64.exe app/storage/plugin_dirs.json app/storage/sf_scan_state.json.bak-root diff --git a/app/core/native_audio_service.py b/app/core/native_audio_service.py index d8a6b4e..420f0a2 100644 --- a/app/core/native_audio_service.py +++ b/app/core/native_audio_service.py @@ -23,8 +23,12 @@ import numpy as np from app.config import settings -_NATIVE_DIR = os.getenv("SONICFORGE_NATIVE_DIR") or os.path.join( - settings.BASE_DIR, "native_host", "build", "Release") +_RES_DIR = os.getenv("SF_RESOURCE_DIR") +_NATIVE_DIR = ( + os.getenv("SONICFORGE_NATIVE_DIR") + or (os.path.join(_RES_DIR, "native_host") if _RES_DIR else None) + or os.path.join(settings.BASE_DIR, "native_host", "build", "Release") +) _ERR = None _LOCK = threading.Lock() diff --git a/app/core/soundfont_converter.py b/app/core/soundfont_converter.py index 9ef2ce9..5eaf323 100644 --- a/app/core/soundfont_converter.py +++ b/app/core/soundfont_converter.py @@ -11,7 +11,11 @@ def _ensure_fluidsynth_runtime() -> None: if os.name != "nt": return root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - candidates = [ + candidates = [] + res_dir = os.getenv("SF_RESOURCE_DIR") + if res_dir: + candidates.append(os.path.join(res_dir, "native_host", "fluidsynth_runtime")) + candidates += [ os.path.join(root, "native_host", "build", "Release", "fluidsynth_runtime"), os.path.join(root, "native_host", "fluidsynth_runtime"), ] diff --git a/build_windows.ps1 b/build_windows.ps1 index a989c9e..070af68 100644 --- a/build_windows.ps1 +++ b/build_windows.ps1 @@ -64,6 +64,34 @@ 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. +if (-not (Test-Path "native_host\build\CMakeCache.txt")) { + if (-not $env:VST3_SDK_ROOT) { + Write-Host "ERROR: can VST3_SDK_ROOT env (duong dan VST3 SDK) khi chua co native_host\build" -ForegroundColor Red + 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 } + +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 } +} + +if (Test-Path "src-tauri\resources\native_host") { + Remove-Item -Recurse -Force "src-tauri\resources\native_host" +} +New-Item -ItemType Directory -Force "src-tauri\resources\native_host" | Out-Null +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\" +Copy-Item "native_host\fluidsynth_runtime" "src-tauri\resources\native_host\fluidsynth_runtime" -Recurse -Force + 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 diff --git a/src-tauri/resources/native_host/.gitkeep b/src-tauri/resources/native_host/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 95e496c..9b5871c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -138,6 +138,7 @@ pub fn run() { .shell() .command(&engine_exe) .env("SF_PARENT_PID", std::process::id().to_string()) + .env("SF_RESOURCE_DIR", res_dir.to_string_lossy().to_string()) .spawn() { Ok((_rx, child)) => { diff --git a/src-tauri/src/vst_gui.rs b/src-tauri/src/vst_gui.rs index 1409e5e..c010a54 100644 --- a/src-tauri/src/vst_gui.rs +++ b/src-tauri/src/vst_gui.rs @@ -93,6 +93,7 @@ mod native { if let Ok(res) = app.path().resource_dir() { candidates.push(res.join(name)); candidates.push(res.join("native").join(name)); + candidates.push(res.join("native_host").join(name)); } if let Ok(exe) = std::env::current_exe() { if let Some(dir) = exe.parent() { diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index c2a21b8..604eb78 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -33,7 +33,8 @@ "icons/favicon.ico" ], "resources": { - "resources/daw_engine": "daw_engine/" + "resources/daw_engine": "daw_engine/", + "resources/native_host": "native_host/" }, "externalBin": [], "windows": {