An example code for embeding rust code into WeChat MiniProgram
Required tools:
- latest rust toolchain
- wasm-pack
- wasm2js tool from binaryen , should be available in PATH.
Compilation:
- The
rust-moddir is a rust project. Compile it withwasm-pack build. The compiled code is inrust-mod/pkg. - Put Compile the wasm code
rust-mod/pkg/rust_mod_bg.wasminto js code withwasm2js:wasm2js -o pkg/rust_mod_bg.wasm.js pkg/rust_mod_bg.wasm - Inject polyfill: prepend
import { TextDecoder, TextEncoder } from '../../polyfill';topkg/rust_mod.js - Inject polyfill: prepend
import { atob } from '../../polyfill';topkg/rust_mod_bg.wasm.js - Run in WeChat developer tools now!