WeChat Mini Program support is an experimental Canvas 2D WebAssembly
route (product_class experimental, ready=false). Unlike Android, iOS, and
HarmonyOS, it does not use the native mobile
window event loop: the Mini Program template calls the canvas host callbacks
directly. The code paths compile, but no development/demonstration usability
or product commitment is made until real Mini Program pixel smoke,
touch-event verification,
and wx API service integrations close remaining gaps.
The Skyline rendering engine provides enhanced Canvas 2D performance in the
Mini Program environment. MoonBit packages support wasm and wasm-gc; the
repository build helper currently targets wasm for WXWebAssembly and lowers
unsupported features before staging the template. Rendering is dispatched
through the CanvasRenderingContext2D API.
moui/backend/wechatexposes the canvas host callbacks, owns the canvas surface host, and provides a neutralentry(WechatAppOptions)platform closure.moui_web_renderer/canvas2dimplements the Canvas 2D renderer producing aRendererProviderthat binds a per-windowRendererSessionwith wasm FFI imports.examples/*/wechat_canvascomposes both sides with@runtime.run_app(...).render(@render_canvas2d.canvas()).backend(@wechat.entry(...)).window/wechat/templateowns the Mini Program project template and its JS bridge to the exported MoonBit callbacks.scripts/build-wechat-demo.shis the canonical build script for demo applications.
┌─────────────────────────────────────────────────┐
│ WeChat Mini Program (Skyline Engine) │
│ ┌───────────┐ ┌─────────────┐ ┌───────────┐ │
│ │ WXML │ │ WXSS │ │ JS Logic │ │
│ │ Canvas 2D │ │ Styles │ │ Runtime │ │
│ └─────┬─────┘ └─────────────┘ └─────┬─────┘ │
│ │ │ │
│ │ CanvasRenderingContext2D │ │
│ │ (touch events) │ │
│ │ │ │
│ ┌─────▼────────────────────────────────▼─────┐ │
│ │ MoonBit WebAssembly Module │ │
│ │ ┌──────────────────────────────────────┐ │ │
│ │ │ moui_web_renderer/canvas2d │ │ │
│ │ │ DrawCommand → Canvas2D API │ │ │
│ │ └──────────────────────────────────────┘ │ │
│ │ ┌──────────────────────────────────────┐ │ │
│ │ │ moui/backend/wechat │ │ │
│ │ │ PlatformEntry + HostRuntimeDriver │ │ │
│ │ └──────────────────────────────────────┘ │ │
│ └────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────┘
The Canvas 2D renderer uses the following approach:
- Backend:
canvas2d-wasm(RendererBackendKind::Canvas2DWasm) - Family:
canvas2d(RendererFamily::Canvas2D) - Target:
wasmin the template build; package support also includeswasm-gc - Presentation: WebCanvas (CanvasRenderingContext2D API)
DrawCommands are mapped to Canvas 2D API calls:
- Rect/FillRect →
fillRect,strokeRect - RoundedRect → path-based rounded rect +
fill/stroke - Text →
fillTextwithmeasureTextfor layout - Image →
drawImage - Clip →
save/restore+clip - Transform →
setTransform,translate,rotate,scale - Opacity →
globalAlpha - Path →
beginPath/moveTo/lineTo/arc/bezierCurveTo+fill/stroke - Gradient →
createLinearGradient/createRadialGradient - Shadow →
shadowBlur/shadowColor/shadowOffsetX/shadowOffsetY - BlendMode →
globalCompositeOperation - Filter →
filterproperty (blur, saturate, brightness, contrast) - LayerCompositing → offscreen canvases
The Mini Program provides touch events through the Canvas element:
- TouchStart →
PointerDown - TouchMove →
PointerMove - TouchEnd →
PointerUp
Keyboard and IME are not available in the Mini Program canvas environment.
The Mini Program template owns the App and Page lifecycle. The backend exports surface and lifecycle callback slots; they remain partial until device evidence proves the complete lifecycle contract:
App.onLaunch→ runtime initializationApp.onShow→handle_resumed()App.onHide→handle_suspended()Page.onUnload→destroy_surfaces()
# Build the counter demo
sh scripts/build-wechat-demo.sh counter
# Build the showcase demo
sh scripts/build-wechat-demo.sh showcaseBuild output is placed in _build/wechat/<app>/ and is ready to be imported
into WeChat Developer Tools.
- WeChat Mini Program base library 3.0+ (Skyline rendering engine)
- WebAssembly support (base library 2.15+)
- WeChat Developer Tools (latest stable)
- MoonBit toolchain with wasm-gc target support
Services are provided through wx API calls bridged from the wasm module:
| Capability | Status | Notes |
|---|---|---|
| Clipboard | Gap | wx.getClipboardData / wx.setClipboardData |
| File Dialog | Gap | Not available in Mini Program |
| System Theme | Gap | wx.getSystemInfo theme detection |
| Open URL | Gap | wx.navigateToMiniProgram / web-view |
- No DOM access: All rendering is through Canvas 2D only
- No keyboard/IME: Mini Program Canvas doesn't support text input
- No drag-drop: Not available in Mini Program environment
- No multi-window: Mini Program is single-page by design
- No file dialogs: Mini Program file system is sandboxed
- Skyline required: Base library 3.0+ with Skyline rendering engine
- Package size: wasm-gc module must fit within Mini Program size limits (2MB for code package)
Platform evidence is tracked in checks/platforms/wechat.json. Current status:
- Renderer: partial (compiles, no real Mini Program pixel smoke)
- Host: ready (window-hosted, lifecycle events)
- Input: partial (touch events, no keyboard/IME)
- Services: gap (wx API integration pending)