Skip to content

Support compiling the library for wasm32 - #65

Closed
l1n wants to merge 4 commits into
QuartzLibrary:mainfrom
l1n:wasm-support
Closed

Support compiling the library for wasm32#65
l1n wants to merge 4 commits into
QuartzLibrary:mainfrom
l1n:wasm-support

Conversation

@l1n

@l1n l1n commented Jul 8, 2026

Copy link
Copy Markdown

What

Makes the glowpub library compile for wasm32-unknown-unknown, enabling in-browser epub generation. The CLI binary is unchanged and remains native-only.

  • The networking, filesystem-cache, and auth modules (api, cached, auth) are gated behind cfg(not(target_arch = "wasm32")), along with their dependencies (reqwest, tokio, glob, clap, simple_logger, rpassword), which move to a target-specific dependency table.
  • Thread::to_epub / Continuity::to_epub are split: the async native half downloads images as before, then delegates to a new sync to_epub_from_images(options, HashMap<String, InternedImage>), which is available on wasm so callers can supply images fetched by other means (e.g. JS fetch). to_epub_remote_images is untouched.
  • intern_images keeps InternedImage and its pure image-processing methods on wasm; only the download-and-intern async functions are native-gated.
  • getrandom's JS backends are enabled for wasm32 (rand and uuid pull it in transitively).

Building

RUSTFLAGS='--cfg getrandom_backend="wasm_js"' cargo check --lib --target wasm32-unknown-unknown

(--lib because the CLI binary doesn't build on wasm; getrandom_backend is required by getrandom 0.3 on wasm32-unknown-unknown.)

Motivation / testing

I run an RSS/epub mirror (glowficrss.com) that uses the glowpub CLI server-side. For access-locked threads the server has no credentials, so it now falls back to a page that fetches the thread through the user's own glowfic login and assembles the epub in the browser with this library compiled to wasm (via a small wasm-bindgen wrapper crate that parses the raw API JSON into Post/Reply and calls to_epub_from_images). That path is running in production: output is byte-identical to the native path for the threads I compared, with icons interned, covers rendered (the bundled Cinzel font makes this work without system fonts), and the result readable in Calibre and Apple Books.

cargo check/cargo test pass natively; cargo check --lib passes for wasm32 as above.

🤖 Generated with Claude Code

lin and others added 3 commits July 8, 2026 19:07
Gate the networking, filesystem-cache, and auth code (and their
dependencies: reqwest, tokio, glob, clap, simple_logger, rpassword)
behind cfg(not(target_arch = "wasm32")). The pure generation path —
types, transforms, cover rendering, image processing, and epub assembly
— now builds for wasm32-unknown-unknown, enabling in-browser epub
generation.

Thread::to_epub and Continuity::to_epub are split into a native async
half that downloads images and a new sync to_epub_from_images(options,
images) that accepts caller-fetched images and is available on wasm,
alongside the existing to_epub_remote_images.

getrandom's JS backends are enabled for wasm32 (needed transitively by
rand and uuid); building for wasm requires
RUSTFLAGS='--cfg getrandom_backend="wasm_js"' and --lib (the CLI
binary remains native-only).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Current stable clippy (1.96) flags these five collapsible_if cases in
cached.rs now that if-let chains are stable, failing the -D warnings CI
gate. No behavior change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Uncomment the wasm clippy step sketched in check.yml. The CLI moves to
src/cli.rs with src/main.rs compiling it natively and building as an
empty stub on wasm32, so the whole workspace (not just --lib) checks
cleanly for wasm32-unknown-unknown.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@l1n

l1n commented Jul 8, 2026

Copy link
Copy Markdown
Author

Pushed two follow-ups: current stable clippy (1.96) fails the existing -D warnings gate on five pre-existing collapsible_ifs in cached.rs (if-let chains are stable now), so those are collapsed in their own commit; and the commented-out wasm CI steps in check.yml are enabled — the CLI moved to src/cli.rs with a stub main on wasm32 so the whole workspace clippy-checks cleanly for wasm32-unknown-unknown without --lib.

@QuartzLibrary

Copy link
Copy Markdown
Owner

Hi! Really cool to see this running in a third party service. :D

wasm is actually something I have wanted to do. Hope you don't mind, but I pushed an alternative implementation at #67.

Would you mind checking it does what you you need it to before I merge it?

@QuartzLibrary

Copy link
Copy Markdown
Owner

Closed in favor of #67.

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