From 1db5b004ff2b01b6fcae9a7a9880a6bd6124ac06 Mon Sep 17 00:00:00 2001 From: Pascal Berrang Date: Sun, 8 Mar 2026 22:12:50 +0000 Subject: [PATCH 1/2] Rename misleading `serde` feature to `iter-ext` The `serde` feature flag was misleading: the serde crate is an unconditional dependency, and the feature only gated the `iter_ext` module (par_map/try_par_map). Rename it to `iter-ext` to accurately reflect what it controls. Also fix inaccurate doc comments on run_bytes/try_run_bytes that referenced the non-existent serde feature gate. --- .github/workflows/test.yml | 4 ++-- Cargo.toml | 6 +++--- README.md | 10 ++++------ src/func.rs | 1 + src/lib.rs | 2 +- src/pool/mod.rs | 2 +- src/webworker/worker.rs | 4 ++-- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ff2af0b..2019762 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,7 +17,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - features: ["--all-features", "--no-default-features --features serde,codec-pot"] + features: ["--all-features", "--no-default-features --features iter-ext,codec-pot"] steps: - uses: actions/checkout@v4 @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - features: ["--all-features", "--no-default-features --features serde,macros,codec-pot"] + features: ["--all-features", "--no-default-features --features iter-ext,macros,codec-pot"] steps: - uses: actions/checkout@v4 diff --git a/Cargo.toml b/Cargo.toml index 5f312e4..2f05e99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["webworker", "parallelism", "wasm"] [workspace.dependencies] -wasmworker = { version = "0.3", path = ".", features = ["serde", "macros"] } +wasmworker = { version = "0.3", path = ".", features = ["iter-ext", "macros"] } wasmworker-proc-macro = { version = "0.3", path = "proc-macro" } [package] @@ -64,8 +64,8 @@ version = "0.3" wasmworker-proc-macro = { workspace = true } [features] -default = ["serde", "codec-postcard"] -serde = [] +default = ["iter-ext", "codec-postcard"] +iter-ext = [] codec-postcard = ["dep:postcard"] codec-pot = ["dep:pot"] macros = ["wasmworker-proc-macro"] diff --git a/README.md b/README.md index e83fc98..cc87c43 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,10 @@ Enable the `macros` feature to get access to the `#[webworker_fn]` and `#[webwor wasmworker = { version = "0.3", 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: -1. The function takes a single argument, which implements `serde::Serialize + serde::Deserialize<'de>`. -2. The return type implements `serde::Serialize + serde::Deserialize<'de>`. +Function arguments and return types must implement `serde::Serialize + serde::Deserialize<'de>`. +Alternatively, functions with the type `fn(Box<[u8]>) -> Box<[u8]>` can be used via `run_bytes()` for manual serialization. -Without the `serde` feature, only functions with the type `fn(Box<[u8]>) -> Box<[u8]>` can be run on a worker. -This is useful for users that do not want a direct serde dependency. Internally, the library always uses serde, though. +The `iter-ext` feature (enabled by default) adds the `par_map` and `try_par_map` iterator extensions for convenient parallel map operations on the default worker pool. #### Serialization codec By default, `wasmworker` uses [postcard](https://crates.io/crates/postcard) for internal serialization. @@ -48,7 +46,7 @@ Note that pot has significantly higher serialization overhead and larger output ```toml [dependencies] -wasmworker = { version = "0.3", default-features = false, features = ["serde", "macros", "codec-pot"] } +wasmworker = { version = "0.3", default-features = false, features = ["iter-ext", "macros", "codec-pot"] } ``` You can then start using the library without further setup. diff --git a/src/func.rs b/src/func.rs index 53355b8..02e8b99 100644 --- a/src/func.rs +++ b/src/func.rs @@ -13,6 +13,7 @@ pub struct WebWorkerFn { /// The worker will automatically add the `__webworker_` prefix. pub(crate) name: &'static str, /// The original function, which can be used as a fallback. + #[cfg_attr(not(feature = "iter-ext"), allow(dead_code))] pub(crate) func: fn(T) -> R, } diff --git a/src/lib.rs b/src/lib.rs index 2b765c0..8365d04 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,7 +118,7 @@ pub mod convert; pub mod error; pub mod func; mod global; -#[cfg(feature = "serde")] +#[cfg(feature = "iter-ext")] pub mod iter_ext; pub mod pool; mod webworker; diff --git a/src/pool/mod.rs b/src/pool/mod.rs index bea81cd..d2675a7 100644 --- a/src/pool/mod.rs +++ b/src/pool/mod.rs @@ -318,7 +318,7 @@ impl WebWorkerPool { /// This function can outsource a task on a [`WebWorkerPool`] which has `Box<[u8]>` both as input and output. /// (De)serialization of values needs to be handled by the caller. - /// For more convenient access, make sure the `serde` feature is enabled and use [`WebWorkerPool::run`]. + /// For more convenient access, use [`WebWorkerPool::run`] instead. /// /// The `func`: [`WebWorkerFn`] argument should normally be instantiated using the [`crate::webworker!`] macro. /// This ensures type safety and that the function is correctly exposed to the worker. diff --git a/src/webworker/worker.rs b/src/webworker/worker.rs index 2a1dee6..0258010 100644 --- a/src/webworker/worker.rs +++ b/src/webworker/worker.rs @@ -295,7 +295,7 @@ impl WebWorker { /// This function can outsource a task on a [`WebWorker`] which has `Box<[u8]>` both as input and output. /// (De)serialization of values needs to be handled by the caller. - /// For more convenient access, make sure the `serde` feature is enabled and use [`WebWorker::run`]. + /// For more convenient access, use [`WebWorker::run`] instead. /// /// The `func`: [`WebWorkerFn`] argument should normally be instantiated using the [`crate::webworker!`] macro. /// This ensures type safety and that the function is correctly exposed to the worker. @@ -318,7 +318,7 @@ impl WebWorker { /// This function differs from [`WebWorker::run_bytes`] by returning early if the given task limit is reached. /// In this case a [`Full`] error is returned. /// (De)serialization of values needs to be handled by the caller. - /// For more convenient access, make sure the `serde` feature is enabled and use [`WebWorker::try_run`]. + /// For more convenient access, use [`WebWorker::try_run`] instead. /// /// The `func`: [`WebWorkerFn`] argument should normally be instantiated using the [`crate::webworker!`] macro. /// This ensures type safety and that the function is correctly exposed to the worker. From 428ef534807242de6352ec73521bb642baa343aa Mon Sep 17 00:00:00 2001 From: Pascal Berrang Date: Sun, 8 Mar 2026 22:40:14 +0000 Subject: [PATCH 2/2] Improve CI: readable job names, codec matrix for all jobs, fix duplicate runs - Use matrix include with named codec variants (postcard/pot) for readable job names instead of raw cargo flags - Add codec matrix to integration tests via npm scripts (test:pot) - Set workspace dep to default-features = false so test crate can switch codecs independently - Only trigger on push to main + all PRs (avoids duplicate runs) --- .github/workflows/test.yml | 29 +++++++++++++++++++++++++---- Cargo.toml | 2 +- demo/Cargo.toml | 2 +- test/Cargo.toml | 5 +++++ test/package.json | 6 +++++- 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2019762..5ef020a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,9 @@ name: Test -on: [push, pull_request] +on: + push: + branches: [main] + pull_request: jobs: rustfmt: @@ -17,7 +20,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - features: ["--all-features", "--no-default-features --features iter-ext,codec-pot"] + include: + - codec: postcard + features: "--all-features" + - codec: pot + features: "--no-default-features --features iter-ext,codec-pot" + name: clippy (${{ matrix.codec }}) steps: - uses: actions/checkout@v4 @@ -31,7 +39,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - features: ["--all-features", "--no-default-features --features iter-ext,macros,codec-pot"] + include: + - codec: postcard + features: "--all-features" + - codec: pot + features: "--no-default-features --features iter-ext,macros,codec-pot" + name: doc-test (${{ matrix.codec }}) steps: - uses: actions/checkout@v4 @@ -42,6 +55,14 @@ jobs: test: runs-on: ubuntu-latest + strategy: + matrix: + include: + - codec: postcard + script: "npm test" + - codec: pot + script: "npm run test:pot" + name: test (${{ matrix.codec }}) steps: - uses: actions/checkout@v4 @@ -52,4 +73,4 @@ jobs: run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh - name: Run tests working-directory: ./test - run: npm test + run: ${{ matrix.script }} diff --git a/Cargo.toml b/Cargo.toml index 2f05e99..011bc6f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ readme = "README.md" keywords = ["webworker", "parallelism", "wasm"] [workspace.dependencies] -wasmworker = { version = "0.3", path = ".", features = ["iter-ext", "macros"] } +wasmworker = { version = "0.3", path = ".", default-features = false, features = ["iter-ext", "macros"] } wasmworker-proc-macro = { version = "0.3", path = "proc-macro" } [package] diff --git a/demo/Cargo.toml b/demo/Cargo.toml index 2462e4a..5289223 100644 --- a/demo/Cargo.toml +++ b/demo/Cargo.toml @@ -25,7 +25,7 @@ serde = { version = "1.0", features = ["derive"] } tokio = { version = "1.43", features = ["sync"] } wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" -wasmworker = { workspace = true } +wasmworker = { workspace = true, features = ["codec-postcard"] } [dependencies.web-sys] features = [ diff --git a/test/Cargo.toml b/test/Cargo.toml index 1c1f437..accfcca 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -23,3 +23,8 @@ js-sys = "0.3" wasm-bindgen-futures = "0.4" web-sys = { version = "0.3", features = ["MessagePort", "Window"] } wasmworker = { workspace = true } + +[features] +default = ["codec-postcard"] +codec-postcard = ["wasmworker/codec-postcard"] +codec-pot = ["wasmworker/codec-pot"] diff --git a/test/package.json b/test/package.json index e5eebec..d759c62 100644 --- a/test/package.json +++ b/test/package.json @@ -3,9 +3,13 @@ "scripts": { "postinstall": "playwright install chromium firefox", "build:web": "wasm-pack build --target web --out-name test --out-dir out/web/pkg && shx cp index.* out/web", + "build:web:pot": "wasm-pack build --target web --out-name test --out-dir out/web/pkg -- --no-default-features --features codec-pot && shx cp index.* out/web", "build:vite": "wasm-pack build --target web --out-name test --out-dir vite-app/pkg && cd vite-app && npx vite build --outDir ../out/vite", + "build:vite:pot": "wasm-pack build --target web --out-name test --out-dir vite-app/pkg -- --no-default-features --features codec-pot && cd vite-app && npx vite build --outDir ../out/vite", "pretest": "npm run build:web && npm run build:vite", - "test": "playwright test" + "test": "playwright test", + "pretest:pot": "npm run build:web:pot && npm run build:vite:pot", + "test:pot": "playwright test" }, "devDependencies": { "@playwright/test": "^1.49.0",