Add external-id attribute#672
Open
lukewagner wants to merge 2 commits into
Open
Conversation
9e2219f to
eeb2ed0
Compare
alexcrichton
approved these changes
Jun 30, 2026
ricochet
approved these changes
Jun 30, 2026
ricochet
left a comment
Contributor
There was a problem hiding this comment.
This looks good to me. I'd use it right away.
You may want to update Linking.md as well:
mutually known to later stages in the deployment pipeline (specifically with
the [depname] case ofimportnamein the text and binary format).
To something like:
mutually known to later stages in the deployment pipeline. (How an import
name is resolved to a particular registry artifact is left to the host or
build tooling; the optional [external-id] attribute can carry a
tooling-specific identifier such as a registry path or URL.)
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR extends #613, which added an
(implements <interfacename>)attribute to imports and exports, with an(external-id <string>)attribute. Theexternal-idattribute is useful when a component import or export name wants to match some external identifier, but the kebab-case syntax is too restrictive. One example is ESM-integration, where Module Specifiers can (now) be arbitrary Unicode strings (including URLs). Another is when importing stateful stores, e.g.:(as enabled by #613) and the platform-defined identifier of these stores isn't a valid
<plainname>, so you'd either have to add a whole separate name-mapping scheme (e.g. mappingredisandmemcachedto their host IDs) or mangle the host IDs into the<plainname>(say, via URL-encoding; ew). Instead, with this PR, you can use the@external-idattribute in WIT:and the WAT
(external-id <string>)is plumbed into the host, alongside(implements <interfacename>), so that the host can reflect on it and act accordingly.As mentioned above,
@external-idcan subsume the use cases forurl=<...>names for ESM-integration. Moreover, the reasoning in #613 for movingimplementsout of the name and into a separate attribute I think similarly suggests that the<urlname>,<depname>and<hashname>cases of<importname>aren't really the right place to solve their associated use cases. IIUC, these 3 name cases aren't currently being produced since there's no WIT syntax to emit them. Thus, this PR tentatively proposes removing these 3 name cases. The use cases are still important, but I think when we're ready to prioritize adding them to WIT/tooling, we should consider adding them as attributes instead. In the meantime, it lets us mergeimportnameandexportnameintoexternname, which simplifies nicely things.The PR also tidies up some sloppiness in the text-format grammar around string literals (e.g.,
"foo-bar") vs. the contents inside the quotes (e.g.foo-bar), using<Xstr>for the former and<X>for the latter. Note that, following the Core Wasm spec's convention,<string>is a double-quoted string literal in the text format, whereas<name>is thelen:<u32>-prefixed, non-quoted string literal in the binary format, hencestr-vs-namesuffixes inExplainer.md-vs-Binary.md.