Files
microw8/examples/rust
Dennis Ranke 26206a312a add filter-exports command to automatically remove unused exports
this removes the need for a manual step in the rust example
2022-01-01 19:02:58 +01:00
..
2022-01-01 15:51:18 +01:00
2022-01-01 15:51:18 +01:00

A small example how to produce somewhat reasonably small MicroW8
carts in rust.

A nightly rust compiler is needed for the unstable sqrtf32
intrinsic.

Simply compiling with rustc as shown in build.sh results in a
371 byte tunnel.wasm. Using wasm-opt this can be reduced to
260 bytes.

When you disassemble this wasm file using wasm2wat you can see
these globals and exports:

(global (;0;) i32 (i32.const 65536))
(global (;1;) i32 (i32.const 65536))
(export "__data_end" (global 0))
(export "__heap_base" (global 1))

They are meant to be used for heap allocations and stack for any
values that are not simple scalars (i32, f32, etc.). Since our
code doesn't actually use any of that, the globals are only
referenced by the exports and we can remove them using
'uw8 filter-exports' (preferably before running wasm-opt) which
removes all exports except those used by the MicroW8 platform.

This gives us a 216 byte wasm file. Running this through
uw8 pack brings us to the final size of 119 bytes.