adampetro opened issue #6660:
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: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 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
- Because macros are evaluated at compile time, it wouldn't be compatible with
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.- It would be more complicated to implement for
s390xbecause of this file.Alternatives
- shell out to multiple versions of
wasmtimeCLI 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
alexcrichton commented on issue #6660:
Personally I think it's a good idea to strive to support this, it's generally "cleaner" to not rely on having a single version of things. That being said the implementation of this needs to be balanced with maintainability at the same time. For example if a release checklist was "go on
mainand update a bunch of symbols" I don't think would work well, but having something more automatic (e.g. adding a suffix as you suggest) would work well. A suffix implementation, however, is likely to be somewhat nontrivial but still not outside the realm of feasability if you're interested in tackling it.It's worth pointing out that
wasmtime-fiber"correctly" has alinkswhich says "there can only be one copy of this". It looks likewasmtime-runtime_incorrectly_ does not have alinks. I would not recommend usingcargo:rustc-link-arg=-Wl,--allow-multiple-definitionas that is more likely to produce a broken binary than a working one. Duplicate symbols are not guaranteed to have the same behavior, and overwriting one with a different version would almost certainly cause the resulting binary to break.Some places I can think of off the top of my head to handle a version suffix are:
- Any invocation of
asm_func!as a macro, including those inwasmtime-fiberandcrates/runtime/src/trampolines/*.rs- As you've pointed out the external s390x assembly file (there's one for fibers as well)
- As you've pointed out, the
crates/runtime/src/debug_builtins.rsfile.For all the assembly trampolines that can all be fixed by suffixing symbols with the crate's current version number. For the debug builtins I think it would be best to probably turn off that file by default and have it be opt-in, since I don't think it's really well supported anywhere today anyway.
Would you be interested in working on a scheme to suffix the assembly symbols with the crate's current version?
adampetro commented on issue #6660:
Would you be interested in working on a scheme to suffix the assembly symbols with the crate's current version?
Yes, I'm happy to do that. I've opened draft PR #6673 to get feedback on my initial approach. Thanks!
adampetro commented on issue #6660:
Resolved by #6673
adampetro closed issue #6660:
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: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 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
- Because macros are evaluated at compile time, it wouldn't be compatible with
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.- It would be more complicated to implement for
s390xbecause of this file.Alternatives
- shell out to multiple versions of
wasmtimeCLI 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
Last updated: Dec 13 2025 at 19:03 UTC