Skip to content

Commit

Permalink
host_wasmtime: make device implementations optional
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Dec 15, 2023
1 parent aeb7e69 commit c7ee371
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
20 changes: 13 additions & 7 deletions host_wasmtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
6 changes: 6 additions & 0 deletions host_wasmtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -190,10 +194,12 @@ impl<T: WasiSensorView> wasi::sensor::sensor::HostDevice for T {
{
trace!("opening a device {}", device_name);
let device_impl: Box<dyn SensorDevice + Send + Sync> = 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,
Expand Down

0 comments on commit c7ee371

Please sign in to comment.