Fix #178: Use web_time::Instant for wasm32 target#179
Merged
Conversation
Signed-off-by: Vlad-Sebastian Cretu <vlad.sebastian.cretu.dev@gmail.com>
…anic The previous commit swapped `Instant` to `web_time::Instant` on wasm32 but tied `web-time` to the `wasm` feature, while the import is gated only on `target_arch`. CI's `wasm-check` job builds wasm32 WITHOUT the feature (`cargo check --target wasm32-unknown-unknown -p office2pdf`), and since `mod pipeline` is compiled unconditionally, that build failed with E0432 "unresolved module or unlinked crate `web_time`". Move `web-time` into `[target.'cfg(target_arch = "wasm32")'.dependencies]` so it is always present on wasm32 regardless of the `wasm` feature (and a zero-cost std re-export on every other target), mirroring the existing `getrandom` setup. This also covers wasm32-wasi consumers. Also swap the unconditional `SystemTime::now()` in render/pdf.rs (`current_utc_datetime`, used for PDF/A and PDF/UA timestamps) to `web_time::SystemTime`; it otherwise panics the same way on wasm32 when a caller sets `pdf_standard` or `pdf_ua`. Verified: cargo check --target wasm32-unknown-unknown -p office2pdf (with and without --features wasm), cargo check --workspace, and cargo fmt --all -- --check all pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
…s off wasm `wasm-pack test` builds every test target (lib tests, integration tests, examples) and all dev-dependencies for wasm32. Several are native-only and failed to build for wasm32, which is why the wasm integration tests in src/wasm.rs were never actually executed by CI (the wasm-check job only ran `cargo check`). Gate the native-only pieces off wasm32 so the wasm tests can build and run: - Cargo.toml: move criterion (pulls rayon, unsupported on wasm32) to non-wasm32 dev-dependencies. - Gate the native unit-test modules (filesystem / system-font dependent) and the fixture/qpdf integration tests under cfg(not(target_arch = "wasm32")). - Add a wasm32 stub `main` to the two filesystem examples. - CI: install wasm-pack and run `wasm-pack test --node --features wasm` in the wasm-check job so the issue developer0hye#178 class of runtime time panic cannot regress. Verified: `wasm-pack test --node --features wasm` runs all 6 wasm tests green; native `cargo test` (1061 lib tests), clippy, fmt, and both wasm32 `cargo check` steps still pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
pull Bot
pushed a commit
to RadaKichenin/office2pdf
that referenced
this pull request
May 31, 2026
…ible_match)
clippy 1.96.0 (current stable) enforces `collapsible_match`, which flagged four
parser match arms whose body was a single `if`. Fold each `if` condition into
the match arm as a guard. Every one of these matches has a `_ => {}` catch-all,
so a failed guard falls through to the no-op arm — behavior is unchanged.
Surfaced by the first `main` CI run since clippy 1.96 became stable; unrelated
to the wasm fix (developer0hye#179).
Verified: `cargo +1.96.0 clippy --workspace --all-targets -- -D warnings` passes;
`cargo test -p office2pdf --lib` (1061 passed); `cargo fmt --all -- --check` passes.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Yonghye Kwon <developer.0hye@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #178 — the
wasmbuild compiled forwasm32-unknown-unknownbut panicked at runtime withtime not implemented on this platform, becausestd::time::Instant::now()(andSystemTime::now()) are not implemented on that target.What changed
lib_pipeline.rs(original commit by @yourlogarithm): useweb_time::Instantonwasm32,std::time::Instantelsewhere.Cargo.toml:web-timeis declared under[target.'cfg(target_arch = "wasm32")'.dependencies]instead of being tied to thewasmfeature. It is therefore always available onwasm32(regardless of thewasmfeature) and a zero-coststdre-export on every other target — mirroring the existinggetrandomsetup. This also supportswasm32-wasiconsumers.render/pdf.rs:current_utc_datetime()used an unconditionalSystemTime::now()for PDF/A and PDF/UA timestamps, which panics the same way onwasm32. It now usesweb_time::SystemTimeonwasm32.Why the dependency is target-scoped, not feature-scoped
mod pipeline(which usesInstant) is compiled unconditionally, and the import is gated ontarget_arch, not on thewasmfeature. Ifweb-timewere only pulled in by thewasmfeature, the CIwasm-checkstepcargo check --target wasm32-unknown-unknown -p office2pdf(no--features wasm) would fail withE0432: unresolved module or unlinked crate web_time. Scoping the dependency to thewasm32target keeps that build green.CI now runs the wasm tests (regression guard)
Previously the
wasm-checkjob only rancargo check, so the wasm integration tests insrc/wasm.rswere never executed and the original panic went uncaught. This PR makes CI actually run them viawasm-pack test --node --features wasm. Becausewasm-pack testbuilds every test target + dev-dependency for wasm32, the native-only pieces are gated off wasm so the wasm tests can build:criterion(pulls rayon, no wasm support) moved to non-wasm32 dev-dependencies.cfg(not(target_arch = "wasm32")).mainfor the two filesystem examples.Verification
cargo check --target wasm32-unknown-unknown -p office2pdf✓ (no feature) and--features wasm✓cargo check --workspace/cargo clippy --workspace --all-targets -D warnings/cargo fmt --all -- --check✓cargo test -p office2pdf --lib✓ (1061 passed)wasm-pack test --node --features wasm✓ (6 wasm tests pass in Node: docx/pptx/xlsx + error cases)web-time(1.1) is the de-facto standardstd::timeshim for WASM (used by winit/egui); MSRV 1.60, well within the workspace MSRV (1.89).