# Diagnose WASM Build Constraints

Identify and resolve constraints for wasm32 builds, including feature limits, sync APIs, and size restrictions.

**Canonical URL:** https://skillshunter.net/skills/github-xberg-io-xberg-ai-rulez-skills-wasm-constraints-403bd29248c6

**JSON URL:** https://skillshunter.net/api/public/v1/skills/github-xberg-io-xberg-ai-rulez-skills-wasm-constraints-403bd29248c6

**Markdown URL:** https://skillshunter.net/skills/github-xberg-io-xberg-ai-rulez-skills-wasm-constraints-403bd29248c6.md

**Instructions download URL:** https://skillshunter.net/skills/github-xberg-io-xberg-ai-rulez-skills-wasm-constraints-403bd29248c6/download

**Category:** Software & Development

**Source URL:** https://github.com/xberg-io/xberg/blob/ffbf7971796a126fc52f6bb8fb40418772071f61/.ai-rulez/skills/wasm-constraints/SKILL.md

**Source commit:** ffbf7971796a126fc52f6bb8fb40418772071f61

**Listing approved at:** 2026-11-16

**Created at:** 2026-11-15T13:47:27.000000Z

**Updated at:** 2026-11-16T05:16:54.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

The skill requires understanding of Rust and wasm-bindgen, and familiarity with the `wasm32` target and its limitations such as sync-only APIs and HTML size constraints.

### When to use it

- Diagnose feature limits in wasm32 builds
- Resolve sync API constraints for WASM compatibility
- Address size limitations in HTML extraction for WASM

## Skill instructions

---
type: Playbook
title: Wasm Constraints
description: "Diagnose wasm32 builds/runtime: feature limits, sync APIs and size constraints."
paths:
  - "crates/xberg-wasm/**"
  - "e2e/wasm/**"
x-ai-rulez:
  kind: skill
  id: wasm-constraints
  metadata:
    name: wasm-constraints
---

# WASM Build Constraints

## Overview

WASM target lives in `crates/xberg-wasm/`, built with wasm-bindgen over sync-only internal
APIs. Note that `crates/xberg-wasm/src/lib.rs` is Alef-generated — do not hand-edit it.

## Feature Flags

```toml
# crates/xberg/Cargo.toml
wasm-target = [
    "no-ort-target",
    "excel-wasm",
    "ocr-wasm",
    "layout-tract",
    "auto-rotate-tract",
    "ner-candle-wasm",
]
```

RT-DETR layout detection and PP-LCNet document orientation run through the pure-Rust `tract`
engine; weights are streamed in from JS, never fetched by Rust (`hf-hub`/`reqwest` are
native-only). Deliberately **no** tree-sitter: the 371-language grammar pack pushes the
browser `.wasm` past jsDelivr's 50 MB per-file cap.

## Critical Constraints

### 1. No Tokio Runtime

All operations must be synchronous internally. Use `#[cfg(not(feature = "tokio-runtime"))]`
paths.

### 2. Internal Sync Extractor Required

Every WASM-compatible built-in extractor must implement `SyncExtractor`
(`crates/xberg/src/extractors/mod.rs`). It is `pub(crate)`, so only in-crate extractors can
implement it — out-of-crate plugins cannot. This is not part of the public API; public callers
still use `extract` / `extract_batch`.

```rust
impl SyncExtractor for MyExtractor {
    fn extract_sync(&self, content: &[u8], mime_type: &str, config: &ExtractionConfig)
        -> Result<InternalDocument> { /* sync implementation */ }
}
```

There is no `as_sync_extractor()` method on `DocumentExtractor` — do not write one.

### 3. HTML Size Limit

```rust
// crates/xberg/src/extraction/html/stack_management.rs
pub const MAX_HTML_SIZE_BYTES: usize = 2 * 1024 * 1024;  // 2 MB — stack constraint
```

## Build Config

```toml
# crates/xberg-wasm/Cargo.toml
[lib]
crate-type = ["cdylib"]

# root Cargo.toml
[profile.release.package.xberg-wasm]
opt-level = "z"   # codegen-units = 1 comes from the global [profile.release]
```

## API Pattern

The generated surface exposes `async` wasm-bindgen functions over sync internals:

```rust
#[wasm_bindgen]
pub async fn extract(input: JsValue, config: JsValue) -> Result<WasmExtractionResult, JsValue>
```

Functions can be `async` for JS ergonomics; extraction underneath is synchronous.

## Gating

**Gate WASM-specific code** with `#[cfg(target_arch = "wasm32")]`, and use the two-arm `cfg_attr` `async_trait` form on any plugin trait impl.

