Skip to content

Commit bf6e56d

Browse files
committed
fix(desktop): initialize ONNX runtime path
1 parent 8882632 commit bf6e56d

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

apps/desktop/src-tauri/src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt};
99
const TOKIO_WORKER_THREAD_STACK_SIZE: usize = 16 * 1024 * 1024;
1010

1111
fn main() {
12+
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
13+
if std::env::var_os("ORT_DYLIB_PATH").is_none()
14+
&& let Some(path) = cap_camera_effects::onnx_runtime_library_path()
15+
{
16+
unsafe {
17+
std::env::set_var("ORT_DYLIB_PATH", path);
18+
}
19+
}
20+
1221
#[cfg(debug_assertions)]
1322
unsafe {
1423
std::env::set_var("RUST_LOG", "trace");

crates/camera-effects/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ use std::time::{Duration, Instant};
88
use blur_pipeline::{BlurPassInputs, BlurPipeline, CompositePipeline};
99
use segmentation::SegmentationModel;
1010

11+
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
12+
pub fn onnx_runtime_library_path() -> Option<std::path::PathBuf> {
13+
segmentation::onnx_runtime_library_path()
14+
}
15+
1116
static BLUR_DISABLED: AtomicBool = AtomicBool::new(false);
1217
static BLUR_SESSION_OBSERVER: OnceLock<fn(bool)> = OnceLock::new();
1318

crates/camera-effects/src/segmentation.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,7 @@ fn create_session() -> anyhow::Result<Session> {
9494

9595
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
9696
fn init_runtime() -> anyhow::Result<()> {
97-
let path = std::env::var_os("ORT_DYLIB_PATH")
98-
.map(PathBuf::from)
99-
.or_else(|| {
100-
onnx_runtime_candidates()
101-
.into_iter()
102-
.find(|path| path.exists())
103-
})
104-
.context("Failed to find ONNX Runtime library")?;
97+
let path = onnx_runtime_library_path().context("Failed to find ONNX Runtime library")?;
10598

10699
let _ = ort::init_from(&path)
107100
.with_context(|| format!("Failed to load ONNX Runtime from {}", path.display()))?
@@ -110,6 +103,17 @@ fn init_runtime() -> anyhow::Result<()> {
110103
Ok(())
111104
}
112105

106+
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
107+
pub(crate) fn onnx_runtime_library_path() -> Option<PathBuf> {
108+
std::env::var_os("ORT_DYLIB_PATH")
109+
.map(PathBuf::from)
110+
.or_else(|| {
111+
onnx_runtime_candidates()
112+
.into_iter()
113+
.find(|path| path.exists())
114+
})
115+
}
116+
113117
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
114118
fn init_runtime() -> anyhow::Result<()> {
115119
Ok(())

0 commit comments

Comments
 (0)