From c9f0147c0d40fd7ff3e13620a57a3236cd05d095 Mon Sep 17 00:00:00 2001 From: Evandro Date: Thu, 11 Jun 2026 14:59:37 -0300 Subject: [PATCH] fix: ensure Windows finds sidecar DLLs by setting PATH and CWD The sidecar was crashing (exitCode: null) when invoked from Tauri because Windows couldn't locate onnxruntime.dll in the sidecar directory. Added setup_cmd() helper that: - Adds the sidecar directory to the child process PATH - Sets the child process CWD to the sidecar directory This ensures Windows can find all required DLLs when Tauri invokes the sidecar, matching the behavior of manual command-line execution. --- src-tauri/src/transcription/sherpa_onnx.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/transcription/sherpa_onnx.rs b/src-tauri/src/transcription/sherpa_onnx.rs index 72cc36b..049c13c 100644 --- a/src-tauri/src/transcription/sherpa_onnx.rs +++ b/src-tauri/src/transcription/sherpa_onnx.rs @@ -132,8 +132,19 @@ impl Transcriber for SherpaOnnxTranscriber { /// `CARGO_MANIFEST_DIR` (produção empacotado e dev) /// 3. nome nu `sherpa-onnx-offline` (PATH do sistema, dev, CI) fn locate_sidecar(sidecar_name: &str, manifest_dir: &str) -> Command { + fn setup_cmd(cmd: &mut Command, exe_path: &std::path::Path) { + if let Some(exe_dir) = exe_path.parent() { + if let Ok(current_path) = std::env::var("PATH") { + cmd.env("PATH", format!("{};{}", exe_dir.display(), current_path)); + } + cmd.current_dir(exe_dir); + } + } + if let Ok(path) = std::env::var("SHERPA_ONNX_SIDECAR") { - return Command::new(path); + let mut cmd = Command::new(&path); + setup_cmd(&mut cmd, std::path::Path::new(&path)); + return cmd; } let manifest_path = std::path::Path::new(manifest_dir); if let Some(parent) = manifest_path.parent() { @@ -143,7 +154,9 @@ fn locate_sidecar(sidecar_name: &str, manifest_dir: &str) -> Command { ]; for candidate in candidates { if candidate.exists() { - return Command::new(candidate); + let mut cmd = Command::new(&candidate); + setup_cmd(&mut cmd, &candidate); + return cmd; } } } @@ -155,7 +168,9 @@ fn locate_sidecar(sidecar_name: &str, manifest_dir: &str) -> Command { ]; for candidate in manifest_candidates { if candidate.exists() { - return Command::new(candidate); + let mut cmd = Command::new(&candidate); + setup_cmd(&mut cmd, &candidate); + return cmd; } } Command::new(sidecar_name)