wasm-constraints

Enforces WASM build constraints for the xberg-wasm crate including sync-only APIs and size limits.

9.2k|581|Updated Jan 31, 2025
One-click install
npx skills add https://github.com/kreuzberg-dev/kreuzberg --skill wasm-constraints
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: wasm-constraints
Source: https://github.com/kreuzberg-dev/kreuzberg/tree/main/.ai-rulez/skills/wasm-constraints
Command: npx skills add https://github.com/kreuzberg-dev/kreuzberg --skill wasm-constraints

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building the xberg document extraction library for wasm32 targets fails or produces oversized binaries when developers use tokio-based async internals, skip the crate-private SyncExtractor trait, or ignore the 2 MB HTML stack limit and size-optimized build profile.

Core Features & Use Cases

  • Feature Flag Guidance: Documents the wasm-target feature set (no-ort-target, excel-wasm, ocr-wasm, layout-tract, auto-rotate-tract, ner-candle-wasm) and explains why tree-sitter is excluded to stay under jsDelivr's 50 MB cap.
  • Sync-Only Internal API Rules: Requires every WASM-compatible in-crate extractor to implement the pub(crate) SyncExtractor trait, with no tokio runtime anywhere in the call path.
  • Build Configuration: Specifies opt-level = "z" on the xberg-wasm package profile, cdylib crate type, and the async wasm-bindgen wrapper over synchronous internals pattern.
  • Use Case: When adding a new extractor that must work in the browser, load this Skill to correctly gate code with #[cfg(target_arch = "wasm32")], implement SyncExtractor, and respect the 2 MB HTML limit.

Quick Start

Load the wasm-constraints skill before adding a new WASM-compatible extractor to crates/xberg so the implementation follows the sync-only and size constraints.

Frequently Asked Questions about wasm-constraints

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build the xberg crate for wasm32 targets?▼

Build the crates/xberg-wasm crate with the wasm-target feature set enabled, which activates no-ort-target, excel-wasm, ocr-wasm, layout-tract, auto-rotate-tract, and ner-candle-wasm. The crate compiles as a cdylib with wasm-bindgen and opt-level z for size.

How do I make a new extractor WASM-compatible in Rust?▼

Implement the crate-private SyncExtractor trait with a synchronous extract_sync method taking content bytes, mime type, and ExtractionConfig. Gate WASM-specific code with #[cfg(target_arch = "wasm32")] and never introduce tokio into the call path.

Can I use tokio or async code in the WASM build?▼

No tokio runtime is allowed; all internal operations must be synchronous. The public wasm-bindgen functions may be declared async for JavaScript ergonomics, but the extraction underneath runs synchronously.

Why is tree-sitter excluded from the WASM build?▼

The 371-language tree-sitter grammar pack pushes the browser .wasm file past jsDelivr's 50 MB per-file cap, so it is deliberately excluded from the wasm-target feature set.

What is the HTML size limit in the WASM extractor?▼

HTML input is capped at MAX_HTML_SIZE_BYTES, defined as 2 MB, due to stack constraints in the WASM environment. Larger HTML documents must be truncated or processed on native targets.

Can external plugins implement SyncExtractor for WASM?▼

No. SyncExtractor is pub(crate), so only in-crate extractors can implement it. Out-of-crate plugins cannot provide WASM-compatible synchronous extraction through this trait.