Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(desktop): initialize ONNX runtime path

Richie McIlroybf6e56d3e880
diff --git a/apps/desktop/src-tauri/src/main.rs b/apps/desktop/src-tauri/src/main.rs
index 7b896c771..ab1dc76e7 100644
--- a/apps/desktop/src-tauri/src/main.rs
+++ b/apps/desktop/src-tauri/src/main.rs
@@ -9,6 +9,15 @@ use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt};
const TOKIO_WORKER_THREAD_STACK_SIZE: usize = 16 * 1024 * 1024;
fn main() {
+ #[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
+ if std::env::var_os("ORT_DYLIB_PATH").is_none()
+ && let Some(path) = cap_camera_effects::onnx_runtime_library_path()
+ {
+ unsafe {
+ std::env::set_var("ORT_DYLIB_PATH", path);
+ }
+ }
+
#[cfg(debug_assertions)]
unsafe {
std::env::set_var("RUST_LOG", "trace");
diff --git a/crates/camera-effects/src/lib.rs b/crates/camera-effects/src/lib.rs
index de5992f11..d5355dab1 100644
--- a/crates/camera-effects/src/lib.rs
+++ b/crates/camera-effects/src/lib.rs
@@ -8,6 +8,11 @@ use std::time::{Duration, Instant};
use blur_pipeline::{BlurPassInputs, BlurPipeline, CompositePipeline};
use segmentation::SegmentationModel;
+#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
+pub fn onnx_runtime_library_path() -> Option<std::path::PathBuf> {
+ segmentation::onnx_runtime_library_path()
+}
+
static BLUR_DISABLED: AtomicBool = AtomicBool::new(false);
static BLUR_SESSION_OBSERVER: OnceLock<fn(bool)> = OnceLock::new();
diff --git a/crates/camera-effects/src/segmentation.rs b/crates/camera-effects/src/segmentation.rs
index a74ec1bd3..5305ef958 100644
--- a/crates/camera-effects/src/segmentation.rs
+++ b/crates/camera-effects/src/segmentation.rs
@@ -94,14 +94,7 @@ fn create_session() -> anyhow::Result<Session> {
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
fn init_runtime() -> anyhow::Result<()> {
- let path = std::env::var_os("ORT_DYLIB_PATH")
- .map(PathBuf::from)
- .or_else(|| {
- onnx_runtime_candidates()
- .into_iter()
- .find(|path| path.exists())
- })
- .context("Failed to find ONNX Runtime library")?;
+ let path = onnx_runtime_library_path().context("Failed to find ONNX Runtime library")?;
let _ = ort::init_from(&path)
.with_context(|| format!("Failed to load ONNX Runtime from {}", path.display()))?
@@ -110,6 +103,17 @@ fn init_runtime() -> anyhow::Result<()> {
Ok(())
}
+#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
+pub(crate) fn onnx_runtime_library_path() -> Option<PathBuf> {
+ std::env::var_os("ORT_DYLIB_PATH")
+ .map(PathBuf::from)
+ .or_else(|| {
+ onnx_runtime_candidates()
+ .into_iter()
+ .find(|path| path.exists())
+ })
+}
+
#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
fn init_runtime() -> anyhow::Result<()> {
Ok(())