Skip to content

TinyWasmModule::from_twasm portable across architectures? #31

Closed

Description

@dragonnn

Hi!
I tried using a program on my PC to serialize TinyWasmModule into a file and then load it on a STM32L552 into TinyWasm but it fails:

1.000610 INFO  loading twasm: 296
└─ embassy_stm32f4_examples::wasm_test::{async_fn#0} @ src/main.rs:62  
1.001403 ERROR access error: "Error { inner: Failure }"
└─ tinywasm_types::archive::{impl#2}::from_twasm::{closure#0} @ tinywasm/crates/types/src/archive.rs:62  
1.003570 INFO  loaded twasm with result: "Err(InvalidArchive)"
└─ embassy_stm32f4_examples::wasm_test::{async_fn#0} @ src/main.rs:64 

That isn't a supported use case? I am not sure where the issue lies, as far I understand rkyv should be stable across architectures (https://rkyv.org/format.html)?
If that isn't supported by rkyv maybe using postcard as an alternative format would work too?
By itself when not having to include tinywasm::parser::Parser my program is like ~15kB with is freaking amazing, but having to include the parser blows it up to like 350kB :/

Activity

  1. dragonnn commented on Jan 16, 2025

    @dragonnn
    ContributorAuthor

    Just did a quick test adding serde to all TinyWasmModule types, used postcard on my pc to save that struct to a pwasm file, loaded it into stm32, deseralized with postcard and it did work 🤔!
    The final binary for my program ended up with ~147kB right now with is much better the using Parser. And interesting the pwasm file is even smaller then wat:

    -rw-r--r-- 1 mateusz wheel  42 01-16 13:55 add.pwasm
    -rw-r--r-- 1 mateusz wheel 296 01-16 13:55 add.twasm
    -rw-r--r-- 1 mateusz wheel  71 01-16 13:55 add.wat
    

    That looks like a pretty viable option to me!

  2. explodingcamera commented on Jan 16, 2025

    @explodingcamera
    Owner

    I think I've had similar issues when the twasm bytes weren't aligned to 4 bytes. I've changed it to show the actual rkyv error now, but I've been thinking of switching to something else anyways (rkyv has some weird limitations around enum sizes and some other things...) and postcard looks pretty nice

  3. dragonnn commented on Jan 16, 2025

    @dragonnn
    ContributorAuthor

    I am fine with making a PR for that, do you prefer having postcard directly in tinywasm-types or just limit to serde (with is what I did currently and used postcard outside it)?

  4. explodingcamera commented on Jan 17, 2025

    @explodingcamera
    Owner

    If you already have some code that would be great 👍 I'd love to do some rough performance benchmarking before committing to the switch though. Probably would keep the API in tinywasm types the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions