wasm-constraints
WASM build constraints for the crates/xberg-wasm crate — the wasm-target feature set, no-tokio sync-only internal APIs, the mandatory SyncExtractor trait for WASM-compatible extractors, the 2 MB HTML size limit, size-optimized build config (opt-level="z"), and the async-wrapper/sync-internal API pattern. Load when building for wasm32, adding or modifying a WASM-compatible extractor, or debugging WASM build/runtime failures.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- wasm-constraints
- description
- WASM build constraints for the crates/xberg-wasm crate — the wasm-target feature set, no-tokio sync-only internal APIs, the mandatory SyncExtractor trait for WASM-compatible extractors, the 2 MB HTML size limit, size-optimized build config (opt-level="z"), and the async-wrapper/sync-internal API pattern. Load when building for wasm32, adding or modifying a WASM-compatible extractor, or debugging WASM build/runtime failures.
03 SKILL.md 正文
WASM Build Constraints
Overview
WASM target in crates/xberg-wasm/. Uses wasm-bindgen with sync-only internal APIs.
Feature Flags
[features]
# Aggregate: pure-Rust no-ORT base + excel + OCR + tract layout/orientation.
# RT-DETR layout detection and PP-LCNet document-orientation run in WASM through
# the pure-Rust `tract` engine (layout-tract + auto-rotate-tract); weights are
# streamed in via load_from_memory (detectLayout / detectOrientation). Deliberately
# NO tree-sitter — the 306-language grammar pack pushes the browser .wasm past
# jsDelivr's 50 MB per-file cap, so code intelligence is unavailable in WASM.
wasm-target = ["no-ort-target", "excel-wasm", "ocr-wasm", "layout-tract", "auto-rotate-tract"]
wasm-threads = ["dep:wasm-bindgen-rayon"] # Optional
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 the internal SyncExtractor trait. This is not part of the public V1 extraction API; public callers still use unified extract / extract_batch.
impl SyncExtractor for MyExtractor {
fn extract_sync(&self, content: &[u8], mime_type: &str, config: &ExtractionConfig)
-> Result<InternalDocument> { /* sync implementation */ }
}
impl DocumentExtractor for MyExtractor {
fn as_sync_extractor(&self) -> Option<&dyn SyncExtractor> {
Some(self) // MUST return Some for WASM
}
}
3. HTML Size Limit
const MAX_HTML_SIZE: usize = 2 * 1024 * 1024; // 2MB - stack constraint
Build Config
[lib]
crate-type = ["cdylib", "rlib"]
[profile.release.package.xberg-wasm]
opt-level = "z" # Size optimization
codegen-units = 1
API Pattern
#[wasm_bindgen]
pub async fn extract_from_bytes(content: Vec<u8>, config: JsValue) -> Result<JsValue, JsValue> {
let config: ExtractionConfig = serde_wasm_bindgen::from_value(config)?;
let result = extract_bytes_sync(&content, mime_type, &config)?;
Ok(serde_wasm_bindgen::to_value(&result)?)
}
Functions can be async for JS compatibility, but internal extraction is sync.
Critical Rules
- No tokio -- all operations synchronous
- Implement SyncExtractor for all WASM-compatible extractors
- HTML limited to 2MB due to stack constraints
- Size optimization via
opt-level = "z" - Feature gate with
#[cfg(target_arch = "wasm32")]
04 同仓库更多 Skills
impeccable
Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.
release-versioning
How xberg versions are synced and released — Cargo.toml is the single source of truth, `task version:sync` propagates it to alef-managed binding manifests AND the integrations under integrations/, which are versioned and published in lockstep with core (including -rc.N). Load before bumping a version, editing the version-sync task, or touching an integration's version/xberg dependency.
plugin-architecture-patterns
Plugin architecture, registration, and trait patterns
mime-detection-routing
MIME type detection and extractor routing in core/mime.rs and core/extractor/bytes.rs — the extension→EXT_TO_MIME→validate→registry→extractor flow, key detection functions, the 118+ case-insensitive extension map, priority-based registry selection, wildcard MIME families, and how to add a new MIME type. Load when adding a format, wiring an extractor to a MIME type, or debugging why a file routes to the wrong (or no) extractor.
format-specific-extraction
Format-specific document extraction workflows
feature-flag-policy
Cargo feature flags for crates/xberg — ORT-incompatible targets (WASM, Android x86_64 emulator), type-only and tract inference companion features, WASM/Android-safe variants, PDF backend, mutually-exclusive ORT variants, platform-conditional deps, aggregate feature sets, and build profiles. Load when adding, wiring, or debugging a Cargo feature, or when reasoning about what compiles on WASM/Android/Windows/macOS-intel targets.