Stream: wasmtime

Topic: Serialization backward compatibility?


view this post on Zulip Pete Vetere (Nov 22 2022 at 17:08):

Hi. Is there any sort of guarantee that serialized modules from previous versions of Wasmtime will be deserializable in future versions? I am updating my product's embedded version of Wasmtime to the latest in main (3.0.0) and noticed that there has been a breaking change in the serialization format (the old HEADER value is no longer present). I'm a little confused about what assumptions to make around this.

In the Wasmtime code, I see:

    match &engine.config().module_version {
        ModuleVersionStrategy::WasmtimeVersion => {
            let version = std::str::from_utf8(version)?;
            if version != env!("CARGO_PKG_VERSION") {
                bail!(
                    "Module was compiled with incompatible Wasmtime version '{}'",
                    version
                );
            }
        }
        ModuleVersionStrategy::Custom(v) => {
            let version = std::str::from_utf8(&version)?;
            if version != v {
                bail!(
                    "Module was compiled with incompatible version '{}'",
                    version
                );
            }
        }
        ModuleVersionStrategy::None => { /* ignore the version info, accept all */ }
    }

This seems to indicate that, by default, Wasmtime will not deserialize modules that came from a previous version. However, it also seems that it is allowable to set the ModuleVersionStrategy to None, which overrides this.

The use case is that, for efficiency, I pre-compile and persist the serialized version of each module so that it can be instantiated as quickly as possible when requested again. However, in future versions of our product, we plan to upgrade Wasmtime, and new versions would ideally need to be able to deserialize modules that were created from before.

view this post on Zulip Alex Crichton (Nov 22 2022 at 17:11):

Wasmtime's AOT artifacts are only usable by the exact release of Wasmtime, and the ModuleVersionStrategy is an escape hatch where "if you know what you're doing" you can subvert that if necessary

view this post on Zulip Alex Crichton (Nov 22 2022 at 17:12):

by default though 3.0.0 artifacts are only consumable by 3.0.0, nothing else

view this post on Zulip Pete Vetere (Nov 22 2022 at 17:44):

Thanks, Alex. In that case, is there some way to "decompile" an AOT artifact back to a .wasm file?

view this post on Zulip Lann Martin (Nov 22 2022 at 17:51):

I'm pretty confident there is not

view this post on Zulip Alex Crichton (Nov 22 2022 at 18:01):

Correct, there is no way of doing that

view this post on Zulip Alex Crichton (Nov 22 2022 at 18:02):

what Fastly does is to save the wasm modules and then each time a new version of wasmtime is built-in it recompiles the wasm mdoules

view this post on Zulip Pete Vetere (Nov 22 2022 at 19:32):

Ok, thank you!


Last updated: Nov 26 2024 at 01:30 UTC