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.
This commit is contained in:
1 parent
d48d01a73b
commit
c9f0147c0d
1 file changed
+18
-3
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user