Skip to content

Fix #178: Use web_time::Instant for wasm32 target#179

Merged
developer0hye merged 3 commits into
developer0hye:mainfrom
yourlogarithm:main
May 31, 2026
Merged

Fix #178: Use web_time::Instant for wasm32 target#179
developer0hye merged 3 commits into
developer0hye:mainfrom
yourlogarithm:main

Conversation

@yourlogarithm
Copy link
Copy Markdown
Contributor

@yourlogarithm yourlogarithm commented May 13, 2026

Addresses #178 — the wasm build compiled for wasm32-unknown-unknown but panicked at runtime with time not implemented on this platform, because std::time::Instant::now() (and SystemTime::now()) are not implemented on that target.

What changed

  • lib_pipeline.rs (original commit by @yourlogarithm): use web_time::Instant on wasm32, std::time::Instant elsewhere.
  • Cargo.toml: web-time is declared under [target.'cfg(target_arch = "wasm32")'.dependencies] instead of being tied to the wasm feature. It is therefore always available 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 supports wasm32-wasi consumers.
  • render/pdf.rs: current_utc_datetime() used an unconditional SystemTime::now() for PDF/A and PDF/UA timestamps, which panics the same way on wasm32. It now uses web_time::SystemTime on wasm32.

Why the dependency is target-scoped, not feature-scoped

mod pipeline (which uses Instant) is compiled unconditionally, and the import is gated on target_arch, not on the wasm feature. If web-time were only pulled in by the wasm feature, the CI wasm-check step cargo check --target wasm32-unknown-unknown -p office2pdf (no --features wasm) would fail with E0432: unresolved module or unlinked crate web_time. Scoping the dependency to the wasm32 target keeps that build green.

CI now runs the wasm tests (regression guard)

Previously the wasm-check job only ran cargo check, so the wasm integration tests in src/wasm.rs were never executed and the original panic went uncaught. This PR makes CI actually run them via wasm-pack test --node --features wasm. Because wasm-pack test builds 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.
  • Native unit-test modules and the fixture/qpdf integration tests gated behind cfg(not(target_arch = "wasm32")).
  • wasm32 stub main for 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 standard std::time shim for WASM (used by winit/egui); MSRV 1.60, well within the workspace MSRV (1.89).

@yourlogarithm yourlogarithm changed the title Fix #178: Use web_time::Instant for wasm32 target. Fix #178: Use web_time::Instant for wasm32 target May 13, 2026
Signed-off-by: Vlad-Sebastian Cretu <vlad.sebastian.cretu.dev@gmail.com>
developer0hye and others added 2 commits May 31, 2026 13:23
…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>
@developer0hye developer0hye merged commit 38395ac into developer0hye:main May 31, 2026
1 check passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants