Rust Web Dev; Proof of Concept for HMR (Hot Module Replacement) using WASM modules.
./hmr-server
- It does:
- compilation & modification of host-wasm
- compilation & modification of mod1.wasm
- serves to
localhost:3000
- It does:
./wasm-project
- It is the sample project that will be compiled into wasm
- contains
lib.rs
andmod1.rs
cd hmr-server
cargo run
- 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
- e.g.
- 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 inrustc
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
- add exports
- pass in the host's memory & imports to instanciate
mod1.wasm
- Import object:
- Error: accessing
thread_local!
value frommod1.wasm
fails; accessing to wrong memory address- Hmmmm
- Try: Override
thread_local
crate for the compilation- Try it in the host module compilation first
- 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
- Similar idea as using
-
substitute
crate::mod
withproj_name::mod
only in the module compilation
-
- rust source modifier plugin (for activating HMR thru plugin interface)