From f796a8dac07c4ab4009ab40b6218d89e35d20685 Mon Sep 17 00:00:00 2001 From: Pascal Berrang Date: Sun, 8 Mar 2026 09:41:57 +0000 Subject: [PATCH] Make wasmworker-proc-macro available as a feature dependency Add a `macros` feature that re-exports wasmworker-proc-macro, so users can depend on just `wasmworker = { features = ["macros"] }` instead of adding both crates separately. Closes #8 --- .github/workflows/test.yml | 2 +- Cargo.lock | 2 -- Cargo.toml | 7 ++++++- README.md | 19 ++++++++----------- demo/Cargo.toml | 1 - demo/src/lib.rs | 2 +- src/lib.rs | 3 +++ test/Cargo.toml | 1 - test/src/channel.rs | 2 +- test/src/convert.rs | 2 +- test/src/raw.rs | 2 +- 11 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7222ddb..ade05d5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@v2 - name: Run doctest - run: cargo test --doc + run: cargo test --doc --all-features test: runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 17cfeff..8faf616 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -556,7 +556,6 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "wasmworker", - "wasmworker-proc-macro", "web-sys", ] @@ -578,7 +577,6 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "wasmworker", - "wasmworker-proc-macro", "web-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 6c998e6..6b4ca57 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["webworker", "parallelism", "wasm"] [workspace.dependencies] -wasmworker = { version = "0.2", path = ".", features = ["serde"] } +wasmworker = { version = "0.2", path = ".", features = ["serde", "macros"] } wasmworker-proc-macro = { version = "0.2", path = "proc-macro" } [package] @@ -65,3 +65,8 @@ wasmworker-proc-macro = { workspace = true } [features] default = ["serde"] serde = [] +macros = ["wasmworker-proc-macro"] + +[dependencies.wasmworker-proc-macro] +workspace = true +optional = true diff --git a/README.md b/README.md index 6c0e3e1..9e37e43 100644 --- a/README.md +++ b/README.md @@ -13,17 +13,14 @@ In contrast to many other libraries like [wasm-bindgen-rayon](https://github.com - [FAQ](#faq) ## Usage -The library consists of two crates: -- `wasmworker`: The main crate that also offers access to the webworker, as well as the worker pool and iterator extensions. -- `wasmworker-proc-macro`: This crate is needed to expose functions towards the web workers via the `#[webworker_fn]` macro. ### Setting up -To use this library, include both dependencies to your `Cargo.toml`. +To use this library, add the following dependency to your `Cargo.toml`. +Enable the `macros` feature to get access to the `#[webworker_fn]` and `#[webworker_channel_fn]` attribute macros. ```toml [dependencies] -wasmworker = "0.2" -wasmworker-proc-macro = "0.2" +wasmworker = { version = "0.2", features = ["macros"] } ``` The `wasmworker` crate comes with a default feature called `serde`, which allows running any function on a web worker under the following two conditions: @@ -59,7 +56,7 @@ This macro ensures that the functions are available to the web worker instances: ```rust,no_run use serde::{Deserialize, Serialize}; -use wasmworker_proc_macro::webworker_fn; +use wasmworker::webworker_fn; /// An arbitrary type that is (de)serializable. #[derive(Serialize, Deserialize)] @@ -79,7 +76,7 @@ This object describes the function to the worker and can be safely obtained via ```rust,no_run # use serde::{Deserialize, Serialize}; -# use wasmworker_proc_macro::webworker_fn; +# use wasmworker::webworker_fn; # #[derive(Serialize, Deserialize)] # pub struct VecType(Vec); # #[webworker_fn] @@ -95,7 +92,7 @@ let ww_sort = webworker!(sort_vec); We can instantiate our own workers and run functions on them: ```rust,no_run # use serde::{Deserialize, Serialize}; -# use wasmworker_proc_macro::webworker_fn; +# use wasmworker::webworker_fn; # #[derive(Serialize, Deserialize, PartialEq, Debug)] # pub struct VecType(Vec); # #[webworker_fn] @@ -117,7 +114,7 @@ It uses a round-robin scheduler (with the second option being a load based sched ```rust,no_run # use serde::{Deserialize, Serialize}; -# use wasmworker_proc_macro::webworker_fn; +# use wasmworker::webworker_fn; # #[derive(Serialize, Deserialize, PartialEq, Debug)] # pub struct VecType(Vec); # #[webworker_fn] @@ -153,7 +150,7 @@ First, define an async function with the `#[webworker_channel_fn]` macro: ```rust,ignore use wasmworker::Channel; -use wasmworker_proc_macro::webworker_channel_fn; +use wasmworker::webworker_channel_fn; #[derive(Serialize, Deserialize)] pub struct Progress { pub percent: u8 } diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 1d6b3ee..2462e4a 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -26,7 +26,6 @@ tokio = { version = "1.43", features = ["sync"] } wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" wasmworker = { workspace = true } -wasmworker-proc-macro = { workspace = true } [dependencies.web-sys] features = [ diff --git a/demo/src/lib.rs b/demo/src/lib.rs index 755ffc1..f238542 100644 --- a/demo/src/lib.rs +++ b/demo/src/lib.rs @@ -2,8 +2,8 @@ use send_wrapper::SendWrapper; use serde::{Deserialize, Serialize}; use tokio::sync::OnceCell; use wasm_bindgen::{prelude::wasm_bindgen, JsCast, UnwrapThrowExt}; +use wasmworker::webworker_fn; use wasmworker::{iter_ext::IteratorExt, webworker, worker_pool, WebWorker}; -use wasmworker_proc_macro::webworker_fn; use web_sys::{HtmlElement, HtmlInputElement}; /// A wrapper type to demonstrate serde functionality. diff --git a/src/lib.rs b/src/lib.rs index 971f6df..13ba511 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,9 @@ pub use web_sys::MessagePort; // Re-export WebWorkerPool from pool module pub use pool::WebWorkerPool; +#[cfg(feature = "macros")] +pub use wasmworker_proc_macro::*; + mod channel; mod channel_task; pub mod convert; diff --git a/test/Cargo.toml b/test/Cargo.toml index 55e2987..65414ea 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -22,4 +22,3 @@ wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" web-sys = { version = "0.3", features = ["MessagePort"] } wasmworker = { workspace = true } -wasmworker-proc-macro = { workspace = true } diff --git a/test/src/channel.rs b/test/src/channel.rs index 58a56c3..8b42883 100644 --- a/test/src/channel.rs +++ b/test/src/channel.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; +use wasmworker::webworker_channel_fn; use wasmworker::{webworker_channel, worker_pool, Channel, WebWorker}; -use wasmworker_proc_macro::webworker_channel_fn; use crate::js_assert_eq; diff --git a/test/src/convert.rs b/test/src/convert.rs index 5480710..428b767 100644 --- a/test/src/convert.rs +++ b/test/src/convert.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; +use wasmworker::webworker_fn; use wasmworker::{has_worker_pool, iter_ext::IteratorExt, webworker, worker_pool, WebWorker}; -use wasmworker_proc_macro::webworker_fn; use crate::js_assert_eq; diff --git a/test/src/raw.rs b/test/src/raw.rs index 38751ef..db0ec9a 100644 --- a/test/src/raw.rs +++ b/test/src/raw.rs @@ -1,8 +1,8 @@ use wasm_bindgen::throw_str; +use wasmworker::webworker_fn; use wasmworker::{ error::InitError, webworker, worker_pool, WebWorker, WebWorkerPool, WorkerPoolOptions, }; -use wasmworker_proc_macro::webworker_fn; use crate::js_assert_eq;