sbeckeriv opened PR #11739 from sbeckeriv:add-library-version to bytecodealliance:main:
Dearest Reviewer,
While using wasmtime I found myself wanting to pre-compile my functions. According to https://github.com/bytecodealliance/wasmtime/pull/11687 The pre-compiled functions should work across minor and patch version changes. I would like to use the version in my cache keys.
My current options are a build script that parses Cargo.toml or I can hard code the current version when I updated my Cargo.toml version.
Providing the built version will allow users of wasttime to ergonomically access the version to use.
Discussed in https://bytecodealliance.zulipchat.com/#narrow/channel/217126-wasmtime/topic/wasmtime.20version.20access/with/541092841 I opted for a const instead of a function.
Thanks for reviewing,
becker<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
sbeckeriv requested alexcrichton for a review on PR #11739.
sbeckeriv requested wasmtime-core-reviewers for a review on PR #11739.
bjorn3 commented on PR #11739:
Don't you need the ABI version of the compiled modules instead? That is currently a combination of
env!("CARGO_PKG_VERSION_MAJOR")and theVERSIONstatic incrates/wasmtime/src/engine/serialization.rsby default. Maybe extract a function to compute an opaque string with all this information to be reused both at the producer and consumer side?
pchickey commented on PR #11739:
Agreed with bjorn3, I think it is more useful to extract the meaningful aspects of the versioning check from https://github.com/bytecodealliance/wasmtime/blob/main/crates/wasmtime/src/engine/serialization.rs#L46 into a method on Engine, since it can change with Config.
sbeckeriv updated PR #11739.
sbeckeriv updated PR #11739.
sbeckeriv updated PR #11739.
bjorn3 created PR review comment:
Please also change the producer side to call this function.
bjorn3 submitted PR review.
sbeckeriv updated PR #11739.
sbeckeriv updated PR #11739.
alexcrichton commented on PR #11739:
@sbeckeriv for hashing purposes have you seen
precompile_compatibility_hash? I forget if that includes the version information, but if it doesn't it probably should. Have you tested out using that for your caching purposes? (it might remove the need for this standalone function)
sbeckeriv closed without merge PR #11739.
sbeckeriv commented on PR #11739:
Thanks!
It does look like the hasher includes the ModuleVersionStrategy https://github.com/bytecodealliance/wasmtime/blob/7380932631f7784d944cb0326a6ffaaf5dac29fc/crates/wasmtime/src/compile/code_builder.rs#L315
I can use this code in my file cache names.
use std::hash::Hasher; use std::hash::DefaultHasher; let engine = Engine::new(&config)?; let compatibility_hash = engine.precompile_compatibility_hash(); let mut hasher = DefaultHasher::new(); compatibility_hash.hash(&mut hasher); let hash_value = hasher.finish(); println!("Hash value: {}", hash_value);`
Last updated: Dec 06 2025 at 07:03 UTC