Skip to content

Make component target semver compatible - #2763

Merged
alexcrichton merged 3 commits into
bytecodealliance:mainfrom
chenyan2002:target
Oct 12, 2026
Merged

alexcrichton merged 3 commits into
bytecodealliance:mainfrom
chenyan2002:target

Conversation

@chenyan2002

@chenyan2002 chenyan2002 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Fix #2220

  • In CLI, changed the flag name from emit_canonical_names to semver_compatible.
  • When semver_compatible is enabled, component target first checks if the binary is already using canonical names. If not, we decode the WIT, merge imports, re-encode WIT with canonical names. Then we can type check the WIT against the target world all based on canonical names.
  • Fix wasmparser to include full version when reporting errors.

@chenyan2002
chenyan2002 requested a review from a team as a code owner October 9, 2026 05:09
@chenyan2002
chenyan2002 requested review from pchickey and removed request for a team October 9, 2026 05:09
@pchickey
pchickey requested review from alexcrichton and removed request for pchickey October 9, 2026 17:03
Comment thread crates/wasmparser/src/validator/names.rs Outdated
///
/// Imports and exports of nested modules and components are not considered.
/// This does not validate `bytes`.
pub fn has_canonical_names(bytes: &[u8]) -> Result<bool> {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to skip this? I'm not sure the purpose of this function and it's kind of subtle only checking the root, and not for example instance exports of the root.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. I was hoping to use this as an optimization that if the binary is already canonicalized, we can skip the reencode. Checking the root is okay for target, because subtyping allows more exports than the target world. But as a general function, it does miss those cases. I will remove it.

Comment thread crates/wit-component/src/targets.rs Outdated
Comment on lines +39 to +41
// The merge above already ensures imports have unique canonical names,
// so this mainly catches semver-compatible duplicate exports.
check_duplicate_canonical_names(&test_resolve, test_world)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a test be added for this? I'm not entirely sure what purpose this part here is serving

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly needed. It's mainly to exclude exports with both 0.1.0 and 0.1.1, but the encoder would catch that anyway.

@chenyan2002 chenyan2002 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also add some fix in the wasmparser to include full version when reporting errors.

///
/// Imports and exports of nested modules and components are not considered.
/// This does not validate `bytes`.
pub fn has_canonical_names(bytes: &[u8]) -> Result<bool> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense. I was hoping to use this as an optimization that if the binary is already canonicalized, we can skip the reencode. Checking the root is okay for target, because subtyping allows more exports than the target world. But as a general function, it does miss those cases. I will remove it.

Comment thread crates/wit-component/src/targets.rs Outdated
Comment on lines +39 to +41
// The merge above already ensures imports have unique canonical names,
// so this mainly catches semver-compatible duplicate exports.
check_duplicate_canonical_names(&test_resolve, test_world)?;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly needed. It's mainly to exclude exports with both 0.1.0 and 0.1.1, but the encoder would catch that anyway.

@alexcrichton
alexcrichton added this pull request to the merge queue Oct 12, 2026
Merged via the queue into bytecodealliance:main with commit e3623d9 Oct 12, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow component targets to validate a binary in a semver-compatible manner

2 participants