diff --git a/Cargo.toml b/Cargo.toml index 951b1371..3c9f4dfa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,13 +32,15 @@ futures = "0.3" # so the doctest for wrap_stream is nice pretty_assertions = "1.4.0" [target.'cfg(target_arch = "wasm32")'.dependencies] -web-time = "1.1.0" +web-time = { version = "1.1.0", optional = true } [features] -default = ["unicode-width", "console/unicode-width"] -improved_unicode = ["unicode-segmentation", "unicode-width", "console/unicode-width"] +default = ["unicode-width", "wasmbind"] +unicode-width = ["dep:unicode-width", "console/unicode-width"] +improved_unicode = ["unicode-segmentation", "unicode-width"] in_memory = ["vt100"] futures = ["dep:futures-core"] +wasmbind = ["dep:web-time"] [package.metadata.docs.rs] all-features = true diff --git a/src/draw_target.rs b/src/draw_target.rs index df7ae03e..a905bc03 100644 --- a/src/draw_target.rs +++ b/src/draw_target.rs @@ -8,7 +8,7 @@ use std::time::Duration; use std::time::Instant; use console::{Term, TermTarget}; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] use web_time::Instant; use crate::multi::{MultiProgressAlignment, MultiState}; diff --git a/src/lib.rs b/src/lib.rs index 578c39c6..0378f091 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -244,6 +244,9 @@ #![cfg_attr(docsrs, feature(doc_cfg))] #![warn(unreachable_pub)] +#[cfg(all(target_arch = "wasm32", not(feature = "wasmbind")))] +compile_error!("The 'wasmbind' feature must be enabled when compiling for wasm32."); + mod draw_target; mod format; #[cfg(feature = "in_memory")] diff --git a/src/multi.rs b/src/multi.rs index e2f64bc6..195c9f9d 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -10,7 +10,7 @@ use crate::draw_target::{ VisualLines, }; use crate::progress_bar::ProgressBar; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] use web_time::Instant; /// Manages multiple progress bars from different threads diff --git a/src/progress_bar.rs b/src/progress_bar.rs index 692798c7..61a5990e 100644 --- a/src/progress_bar.rs +++ b/src/progress_bar.rs @@ -9,7 +9,7 @@ use std::{fmt, io, thread}; #[cfg(test)] use once_cell::sync::Lazy; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] use web_time::Instant; use crate::draw_target::ProgressDrawTarget; diff --git a/src/state.rs b/src/state.rs index bfe19a12..92bac64c 100644 --- a/src/state.rs +++ b/src/state.rs @@ -6,7 +6,7 @@ use std::time::Duration; use std::time::Instant; use portable_atomic::{AtomicU64, AtomicU8, Ordering}; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] use web_time::Instant; use crate::draw_target::{LineType, ProgressDrawTarget}; diff --git a/src/style.rs b/src/style.rs index 292f095e..939fa4e6 100644 --- a/src/style.rs +++ b/src/style.rs @@ -9,7 +9,7 @@ use unicode_width::UnicodeWidthChar; use console::{measure_text_width, AnsiCodeIterator, Style}; #[cfg(feature = "unicode-segmentation")] use unicode_segmentation::UnicodeSegmentation; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", feature = "wasmbind"))] use web_time::Instant; use crate::draw_target::LineType;