Feature
It would be beneficial to provide the ability to include multiple versions of wasmtime in a crate in order to compile modules with multiple wasmtime versions.
By using all default features excluding async, it is somewhat possible. However, it is necessary to include compiler flags like cargo:rustc-link-arg=-Wl,--allow-multiple-definition in a build script in order to get by the multiple definition errors such as:
wasmtime-runtime-8.0.1/src/debug_builtins.rs:39: multiple definition of `set_vmctx_memory'
I would like to avoid using these compiler flags if possible for a couple of reasons. First, I have had difficulty using them in a single crate in a workspace, as the individual crate can be tested and built in isolation but using workspace-level commands still yields the multiple definition errors. Additionally, there is a risk of undefined behaviour.
Benefit
Supporting multiple versions of wasmtime in the same crate can be hugely beneficial in applications that rely on caching large numbers of compiled modules, specifically for handling wasmtime version bumps. If multiple versions of wasmtime can be included in a crate, it is possible to build up the cache of compiled modules for the new version while still executing modules for the old version, and then cut over to executing with the new version seamlessly with a fully populated cache.
Implementation
A small helper crate with a small number of procedural macros could be used to add a suffix to any named entities that lead to multiple definition errors, and any references to them. The suffix could be based on the wasmtime crate version or customizable with an environment variable.
I have prepared a prototype in this commit that uses the wasmtime crate version to generate the suffix.
Potential complications
- Because macros are evaluated at compile time, it wouldn't be compatible with
ModuleVersionStrategy::Custom when the value used is generated dynamically at runtime. However, if versioned exports are opt-in then it shouldn't be a problem, it just can't be used with dynamic custom versions.
- It would be more complicated to implement for
s390x because of this file.
Alternatives
- shell out to multiple versions of
wasmtime CLI to achieve multi-version compilation
- use compiler flags such as
cargo:rustc-link-arg=-Wl,--allow-multiple-definition, but as mentioned above this has undesirable consequences
Feature
It would be beneficial to provide the ability to include multiple versions of
wasmtimein a crate in order to compile modules with multiplewasmtimeversions.By using all default features excluding
async, it is somewhat possible. However, it is necessary to include compiler flags likecargo:rustc-link-arg=-Wl,--allow-multiple-definitionin a build script in order to get by themultiple definitionerrors such as:I would like to avoid using these compiler flags if possible for a couple of reasons. First, I have had difficulty using them in a single crate in a workspace, as the individual crate can be tested and built in isolation but using workspace-level commands still yields the
multiple definitionerrors. Additionally, there is a risk of undefined behaviour.Benefit
Supporting multiple versions of
wasmtimein the same crate can be hugely beneficial in applications that rely on caching large numbers of compiled modules, specifically for handlingwasmtimeversion bumps. If multiple versions ofwasmtimecan be included in a crate, it is possible to build up the cache of compiled modules for the new version while still executing modules for the old version, and then cut over to executing with the new version seamlessly with a fully populated cache.Implementation
A small helper crate with a small number of procedural macros could be used to add a suffix to any named entities that lead to
multiple definitionerrors, and any references to them. The suffix could be based on thewasmtimecrate version or customizable with an environment variable.I have prepared a prototype in this commit that uses the
wasmtimecrate version to generate the suffix.Potential complications
ModuleVersionStrategy::Customwhen the value used is generated dynamically at runtime. However, if versioned exports are opt-in then it shouldn't be a problem, it just can't be used with dynamic custom versions.s390xbecause of this file.Alternatives
wasmtimeCLI to achieve multi-version compilationcargo:rustc-link-arg=-Wl,--allow-multiple-definition, but as mentioned above this has undesirable consequences