Rust Web Dev; Proof of Concept for HMR (Hot Module Replacement) using WASM modules.
mod1.wasm
has all its dependencies externalized- It compiles extremely fast and is extremely lightweight.
mod1.wasm
imports all dependencies (std libraries, dependency functions, memory, etc.)
- It compiles extremely fast and is extremely lightweight.
- It proves the possibility of dynamic component replacement on browser without page reloading.
./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)
- 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
- Compile
- 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
- pass in the host's memory & imports to instanciate
mod1.wasm
- Import object:
- Invoking functions in
mod1.wasm
- func with no param
- func that takes in params of values / references
- Accessing
thread_local!
value in host frommod1.wasm
- Make a test function in
mod1
that appends a Leptos component tobody()
when invoked - 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)