Momijiichigo / rust-hmr-experiment

Rust Web Dev: PoC for HMR with WASM tricks.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rust-hmr-experiment

Rust Web Dev; Proof of Concept for HMR (Hot Module Replacement) using WASM modules.

overview

Brief Roadmap

  • compile whole cargo project into WASM (main module)
  • modify the main wasm so it exports all the library functions
    • e.g. alloc::alloc::handle_alloc_error
  • Compile a single rust file into a separate WASM file (component module)
  • Load the component WASM module (mod1.wasm) from main WASM module
    • Import object: __wbindgen_placeholder__, __wbindgen_externref_xform__ fields
    • Use of Proxy in JS to flexibly resolve the importObject for WASM instanciation
    • Compile mod1.rs into object file with --emit obj flag in rustc
      • mod1.wasm will be minimal and imports all library functions at runtime
      • also imports memory from outside
    • Modify the wasm binary with Walrus
      • add exports
        • parse Custom Linking section of wasm binary and obtain name map of functions
      • demangle import & func names
    • pass in the host's memory & imports to instanciate mod1.wasm
  • Modify the source code and pass to the compiling process
    • Idea: Virtual sandboxed filesystem that returns processed file content

      • Similar idea as using Proxy in JS but for filesystems
    • substitute crate::mod with proj_name::mod only in the module compilation

  • Error: accessing thread_local! value from mod1.wasm fails; accessing to wrong memory address
    • Hmmmm
  • rust source modifier plugin (for activating HMR thru plugin interface)

About

Rust Web Dev: PoC for HMR with WASM tricks.

License:MIT License


Languages

Language:Rust 91.3%Language:JavaScript 8.3%Language:HTML 0.4%