Skip to content

examples: add component model example#7759

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
rockwotj:component-example
Jan 9, 2024
Merged

examples: add component model example#7759
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
rockwotj:component-example

Conversation

@rockwotj
Copy link
Copy Markdown
Contributor

@rockwotj rockwotj commented Jan 8, 2024

As part of my journey on learning how the component model works, I realized there is no example in wasmtime, so I figured it'd be useful to add a simple example of guest and host calls.

@rockwotj rockwotj force-pushed the component-example branch 2 times, most recently from 1bf82e5 to 2c38776 Compare January 8, 2024 05:37
@rockwotj rockwotj marked this pull request as ready for review January 8, 2024 05:49
@rockwotj rockwotj requested review from a team as code owners January 8, 2024 05:49
@rockwotj rockwotj requested review from alexcrichton and removed request for a team January 8, 2024 05:49
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Thanks for this!

I'm somewhat of two minds on this. On one hand this example showcases a lot of downsides to the unsupported nature of the component model in languages. For example embeddings may not always embed wit-component itself and turn core wasm into components on-the-fly. Additionally this probably won't work for many "real world" use cases in the sense that WASI isn't handled here. That would require tweaks to both the build process and the embedder. Finaly the wasm32-unknown-unknown target, rarely used off the web, is used here (for simplicity of course, which makes sense)

On the other hand this showcases a concrete working example which is something folks can base work on. In that sense it's great to have! Given the number of moving parts in the component model being able to start somewhere is definitely valuable.

I'd probably lean towards landing this, although perhaps with a few more comments with respect to WASI and usage. Could you add a comment indicating that wasm32-unknown-unknown is used for simplicity here and additionally indicate that the usage of wit-component in embeddings is done for the purposes of this example and otherwise may not be expected in all host embeddings of Wasmtime?

Comment thread examples/component/wasm/Cargo.toml Outdated
Comment thread examples/component/wasm/guest.rs Outdated
@rockwotj
Copy link
Copy Markdown
Contributor Author

rockwotj commented Jan 9, 2024

Thanks for the review! I ended up submitting this because I wanted to:

  1. Have a place where there was a single simple as possible example of the component model that was in code. Everywhere else I could find were documentation of the steps of how to do things and were not specific to wasmtime (so didn't include how to create custom worlds using wasmtime's binding macro).
  2. Learn more about the generated bindings via cargo expand so I know what to expose via the C-API

I thought the first use case was something others wanted to do, so I ended up creating this. I whole heartedly agree with your comments and have updated the PR.

@rockwotj rockwotj requested a review from alexcrichton January 9, 2024 18:52
Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
Copy link
Copy Markdown
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Sounds good!

@alexcrichton alexcrichton added this pull request to the merge queue Jan 9, 2024
Merged via the queue into bytecodealliance:main with commit b5169d9 Jan 9, 2024
@rockwotj rockwotj deleted the component-example branch January 9, 2024 22:44
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.

2 participants