From c7ee3715736d63b3abd15cd5eb5b3c1d143fb96a Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 12 Dec 2023 20:34:55 +0900 Subject: [PATCH] host_wasmtime: make device implementations optional --- host_wasmtime/Cargo.toml | 20 +++++++++++++------- host_wasmtime/src/main.rs | 6 ++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/host_wasmtime/Cargo.toml b/host_wasmtime/Cargo.toml index 345f6a9..df92dbd 100644 --- a/host_wasmtime/Cargo.toml +++ b/host_wasmtime/Cargo.toml @@ -5,20 +5,26 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +default = ["nokhwa", "dummy"] +nokhwa = ["dep:nokhwa"] +dummy = ["dep:fraction", "dep:image"] + [dependencies] +# released versions of nokhwa is a bit broken for avfoundation. +# https://github.com/l1npengtul/nokhwa/pull/151 +# https://github.com/l1npengtul/nokhwa/pull/152 +nokhwa = {git = "https://github.com/yamt/nokhwa", rev = "0.10+fixes", features = ["input-native", "output-threaded"], optional = true} + +fraction = { version = "0.14", optional = true } +image = { version = "0.24.7", default-features = false, optional = true } + anyhow = "1.0.75" -fraction = "0.14" tracing = { version = "0.1.40", features = ["max_level_trace"] } tracing-subscriber = "0.3.18" -image = { version = "0.24.7", default-features = false } async-trait = "0.1.74" tokio = { version = "1.35.0", default-features = false } -# released versions of nokhwa is a bit broken for avfoundation. -# https://github.com/l1npengtul/nokhwa/pull/151 -# https://github.com/l1npengtul/nokhwa/pull/152 -nokhwa = {git = "https://github.com/yamt/nokhwa", rev = "0.10+fixes", features = ["input-native", "output-threaded"]} - # preview2 and component-model are still moving targets. wasmtime = { version = "15.0.1", default-features = false, features = ["component-model", "cranelift"]} wasmtime-wasi = { version = "15.0.1", default-features = false, features = ["preview2", "sync"] } diff --git a/host_wasmtime/src/main.rs b/host_wasmtime/src/main.rs index 7066013..044c871 100644 --- a/host_wasmtime/src/main.rs +++ b/host_wasmtime/src/main.rs @@ -18,12 +18,16 @@ use wasmtime_wasi::preview2::WasiCtxBuilder; use wasmtime_wasi::preview2::WasiView; use wasmtime_wasi::Dir; +#[cfg(feature = "dummy")] mod dummy_device; +#[cfg(feature = "nokhwa")] mod nokhwa; mod pool; mod traits; +#[cfg(feature = "dummy")] use dummy_device::DummyDevice; +#[cfg(feature = "nokhwa")] use nokhwa::NokhwaDevice; use pool::SimplePool; use traits::SensorDevice; @@ -190,10 +194,12 @@ impl wasi::sensor::sensor::HostDevice for T { { trace!("opening a device {}", device_name); let device_impl: Box = match &*device_name { + #[cfg(feature = "dummy")] "dummy" => Box::new(match DummyDevice::new() { Err(e) => return Ok(Err(e)), Ok(i) => i, }), + #[cfg(feature = "nokhwa")] "nokhwa" => Box::new(match NokhwaDevice::new() { Err(e) => return Ok(Err(e)), Ok(i) => i,