Skip to content

Commit

Permalink
Implement latest component model spec. (#826)
Browse files Browse the repository at this point in the history
This commit implements the latest changes to the component model spec:

* Adds a `URL` field to imports and exports.
* Adds validation of the `URL` field.
* Adds validation of various "names" such that they are kebab-cased.

Consequently, import and export names in components are no longer allowed to be
empty, which required fixes in many component model tests.
  • Loading branch information
peterhuene committed Nov 18, 2022
1 parent a44c779 commit 57aad84
Show file tree
Hide file tree
Showing 90 changed files with 2,679 additions and 1,918 deletions.
1 change: 1 addition & 0 deletions crates/wasm-compose/Cargo.toml
Expand Up @@ -22,6 +22,7 @@ log = { workspace = true }
serde_yaml = "0.8.26"
clap = { workspace = true, optional = true }
smallvec = "1.10.0"
heck = "0.4.0"

[features]
default = []
Expand Down
6 changes: 3 additions & 3 deletions crates/wasm-compose/src/composer.rs
Expand Up @@ -210,7 +210,7 @@ impl<'a> CompositionGraphBuilder<'a> {
let (_, instance_id) = self.instances.get_index(instance).unwrap();
let (_, component) = self.graph.get_component_of_instance(*instance_id).unwrap();
match component.export_by_name(export) {
Some((export_index, kind, index)) if kind == ComponentExternalKind::Instance => {
Some((export_index, _, kind, index)) if kind == ComponentExternalKind::Instance => {
let export_ty = component.types.component_instance_at(index).unwrap();
if !ComponentInstanceType::is_subtype_of(export_ty, component.types(), ty, types) {
bail!("component `{path}` exports an instance named `{export}` but it is not compatible with import `{arg_name}` of component `{dependent_path}`",
Expand All @@ -234,7 +234,7 @@ impl<'a> CompositionGraphBuilder<'a> {
r: InstanceImportRef,
) -> (&Component, &str, &ComponentInstanceType) {
let component = self.graph.get_component(r.component).unwrap();
let (name, ty) = component.import(r.import).unwrap();
let (name, _, ty) = component.import(r.import).unwrap();
match ty {
ComponentTypeRef::Instance(index) => (
component,
Expand Down Expand Up @@ -310,7 +310,7 @@ impl<'a> CompositionGraphBuilder<'a> {
let count = queue.len();

// Push a dependency for every instance import
for (import, name, ty) in component.imports() {
for (import, name, _, ty) in component.imports() {
match ty {
ComponentTypeRef::Instance(_) => {}
_ => bail!(
Expand Down

0 comments on commit 57aad84

Please sign in to comment.