diff --git a/Cargo.toml b/Cargo.toml index 10583fd..56ac8cc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,9 +17,9 @@ path = "src/platform/os/main.rs" required-features = [ "os-target" ] [features] -os-target = [ "clap", "home", "daemonize", "nix", "toml", "serde_json", "sysinfo", "ciborium/default", "tracing-subscriber", "async", "tracing-subscriber/env-filter"] -async = ["tokio/net", "tokio", "tokio/rt-multi-thread", "tokio/io-util"] +os-target = [ "clap", "home", "daemonize", "nix", "toml", "sysinfo", "ciborium/default", "tracing-subscriber", "async", "tracing-subscriber/env-filter"] wasm-target = [ "wasm-bindgen", "console_error_panic_hook", "wasm-bindgen-cli" ] +async = ["tokio/net", "tokio", "tokio/rt-multi-thread", "tokio/io-util"] [dependencies] @@ -30,6 +30,8 @@ ciborium = { version = "0.2.2", default-features = false } serde = "1.0.203" interner = { git = "https://github.com/c2vi/interner" } tracing = "0.1.40" +serde_json = { version = "1.0.117", optional = false } +crossbeam = "0.8.4" # wasm dependencies wasm-bindgen = { version = "0.2.84", optional = true } @@ -42,7 +44,6 @@ home = { version = "0.5.9", optional = true } daemonize = { version = "0.5.0", optional = true } nix = { version = "0.27.1", features = ["signal"], optional = true } toml = { version = "0.8.13", features = ["parse"], optional = true } -serde_json = { version = "1.0.117", optional = true } sysinfo = { version = "0.30.12", optional = true } tracing-subscriber = { version = "0.3.18", optional = true } tokio = { version = "1.21.0", features = ["sync"], optional = true } @@ -53,7 +54,6 @@ tokio = { version = "1.21.0", features = ["sync"], optional = true } axum = { version = "0.6.1", features = ["ws", "headers"], optional = true } axum-extra = { version = "0.4.2", features = ["spa"], optional = true } axum-macros = { version = "0.3.0", optional = true } -crossbeam = "0.8.4" dyn-clone = "1.0.17" tokio-core = "0.1.18" tokio-io = "0.1.13" diff --git a/src/core/instance/mod.rs b/src/core/instance/mod.rs index 205ff2a..f294b89 100644 --- a/src/core/instance/mod.rs +++ b/src/core/instance/mod.rs @@ -1,7 +1,6 @@ use core::fmt; use std::collections::HashMap; use std::fs::create_dir; -use std::thread::JoinHandle; use std::{thread, vec}; use crossbeam::channel::{self, bounded, Receiver, Sender}; use std::sync::{Arc, Mutex}; @@ -23,20 +22,24 @@ use crate::memstore::MemStore; use crate::instance::updater::Operation; use crate::mize_err; use crate::proto::MizeMessage; -use tokio::runtime::Handle; use self::connection::{ConnListener, Connection}; use self::updater::handle_operation; #[cfg(feature = "async")] use tokio::runtime::Runtime; +#[cfg(feature = "async")] +use tokio::runtime::Handle; + use core::future::Future; +use std::thread::JoinHandle; pub mod connection; pub mod store; pub mod subscription; pub mod updater; pub mod msg_thread; +pub mod module; static MSG_CHANNEL_SIZE: usize = 200; @@ -136,9 +139,7 @@ impl Instance { fn init(&mut self) -> MizeResult<()> { // platform specific init code - if cfg!(feature = "os-target") { // on os platforms - crate::platform::os::os_instance_init(self)? - } + crate::platform::any::instance_init(self); // end of platform specific init code diff --git a/src/core/instance/module.rs b/src/core/instance/module.rs new file mode 100644 index 0000000..6830ff0 --- /dev/null +++ b/src/core/instance/module.rs @@ -0,0 +1,6 @@ + + +// https://users.rust-lang.org/t/casting-between-trait-object-types/97220/2 + +pub trait Module { +} diff --git a/src/core/item.rs b/src/core/item.rs index 576c601..879b2c1 100644 --- a/src/core/item.rs +++ b/src/core/item.rs @@ -5,7 +5,6 @@ use std::fmt::Debug; use std::{i128, string}; use std::{collections::HashMap, path::PathBuf, io::Cursor, fmt::Display}; use std::fs::File; -use tokio::sync::Mutex; use std::rc::Rc; use colored::Colorize; use std::io; diff --git a/src/core/proto/mod.rs b/src/core/proto/mod.rs index d0e48c4..e7e6d0a 100644 --- a/src/core/proto/mod.rs +++ b/src/core/proto/mod.rs @@ -1,6 +1,5 @@ use core::fmt; use std::io; -use nix::libc::CTRL_CMD_UNSPEC; use serde::Serialize; use ciborium::{value::Integer, Value as CborValue}; diff --git a/src/lib.rs b/src/lib.rs index b220ed8..73ae77d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,8 +22,16 @@ pub mod platform { #[cfg(feature = "wasm-target")] pub mod wasm; - //#[cfg(feature = "os-target")] + #[cfg(feature = "os-target")] pub mod os; + + pub mod any { + #[cfg(feature = "wasm-target")] + pub use super::wasm::wasm_instance_init as instance_init; + + #[cfg(feature = "os-target")] + pub use super::os::os_instance_init as instance_init; + } } diff --git a/src/platform/os/logging.rs b/src/platform/os/logging.rs index 3290050..8056a38 100644 --- a/src/platform/os/logging.rs +++ b/src/platform/os/logging.rs @@ -316,7 +316,7 @@ impl MinimalTracer { pub fn register() -> Result<(), tracing::subscriber::SetGlobalDefaultError> { let mut enabled = true; let mut span_names_to_enable = Vec::new(); - let mut my_level = Level::INFO; + let mut my_level = Level::ERROR; let mut filters: Vec = Vec::with_capacity(10); if let Ok(env_value) = env::var("RUST_LOG") { diff --git a/src/platform/wasm/mod.rs b/src/platform/wasm/mod.rs index 0241800..6310cfe 100644 --- a/src/platform/wasm/mod.rs +++ b/src/platform/wasm/mod.rs @@ -2,6 +2,9 @@ mod utils; use wasm_bindgen::prelude::*; +use crate::instance::Instance; +use crate::error::MizeResult; + // When the `wee_alloc` feature is enabled, use `wee_alloc` as the global // allocator. #[cfg(feature = "wee_alloc")] @@ -17,3 +20,10 @@ extern { pub fn greet() { alert("Hello, wasm-game-of-life!"); } + +pub fn wasm_instance_init(instance: &mut Instance) -> MizeResult<()> { + println!("Hello world from wasm_instance_init!!!!!!!!!!"); + alert("Hello world from wasm_instance_init!!!!!!!!!!"); + + Ok(()) +}