component-model icon indicating copy to clipboard operation
component-model copied to clipboard

Interface version / compatibilty changes

Open lann opened this issue 5 months ago • 3 comments

Wasmtime currently performs a slightly complicated dance to allow a guest import/export of an interface to be linked with a different but semver-compatible host version of that interface. For a description of why this behavior was implemented see https://github.com/bytecodealliance/wasmtime/issues/7860. Based on a discussion with @lukewagner and @alexcrichton we think this behavior can be brought into the spec itself with some relatively straightforward changes:

  • Define "interface version canonicalization", meaning roughly "trimming a version down to the part that matters for compatibility"

    • e.g. 0.2.50.2, 1.2.31
    • See https://github.com/WebAssembly/component-model/pull/378; specifically https://github.com/WebAssembly/component-model/blob/3c6c4a9f1228676a342d2f971ced73b0e0ba0d2b/design/mvp/BuildTargets.md#interface-name-canonicalization

      The definition in this PR preserves semver prerelease tags but we think that may not be necessary.

  • Update <version> to allow canonical versions in addition to full semver: x (x > 0) and 0.y (y > 0)

  • To allow round-tripping WIT and nicer error messages, add an optional field to imports/exports that preserves the original full version

    • This could contain the entire version (1.2.3) or just the trimmed suffix (.2.3 / 2.3)
  • (pre-1.0) start enforcing (instead of just allowing) canonical <version>s

With these spec changes, bindings generators would start emitting canonicalized versions in import/export names. This should effectively give behavior similar to what the Wasmtime linker does today, and additionally should solve the same underlying version compatibility problems for other tools like wac and wasi-virt.

lann avatar Jun 24 '25 19:06 lann

This makes sense to me since it allows simple equality-based name matching to provide the semver semantics that it seems like everyone needs in practice, minimizing the number of places that have to think about it while still preserving the precise version information for diagnostic purposes.

I'm happy to write up a PR for this repo (after waiting to see if there's any more thoughts in this issue) or happy to let you do it @lann if you're inclined.

lukewagner avatar Jun 25 '25 17:06 lukewagner

I can take a crack at it.

lann avatar Jun 25 '25 18:06 lann

This draft is ready for initial review: https://github.com/WebAssembly/component-model/pull/536

Moved comment about binary format to the PR.

lann avatar Jun 25 '25 20:06 lann