Stream: cargo-component

Topic: Moving to cargo-component from wit-bindgen


view this post on Zulip Landon James (Jan 13 2024 at 02:13):

Hello! I have a POC using the wit-bindgen crate to get a simple wasi:http example working. After some community feedback on one of the issues I created while getting this working I am looking into porting this to use cargo-component instead so I don't have to manually manage the preview1/2 wasi functionality. I have a few questions about things I've encountered along the way (all using version 0.6.0):

  1. Is there any documentation of the available cargo-component fields in Cargo.toml? Ex: I was trying to figure out how to add additional_derives and all I came across was this test function that shows the field I need
  2. Is there currently an active registry I can target with the cargo-component add wasi:http command? Trying to do it without setting a registry gives a related failure, but setting the below (only registry url I ran across) also throws an error:
[package.metadata.component.registries]
default = "https://preview-registry.bytecodealliance.org"

throws

$ cargo-component add wasi:http
    Updating component registry package logs
error: failed to update package logs for component registry `default`

Caused by:
    failed to deserialize JSON response: missing field `fetchToken` at line 1 column 379 (status code: 200 OK)
  1. If the registry is not yet ready, what is the best place/strategy for sourcing the wasi:* wit files to make a seamless transition when all of the machinery is in place?
Contribute to landonxjames/wasi-http-test development by creating an account on GitHub.

view this post on Zulip Peter Huene (Jan 15 2024 at 22:51):

Hi @Landon James . Thanks for the questions!

Is there any documentation of the available cargo-component fields in Cargo.toml? Ex: I was trying to figure out how to add additional_derives and all I came across was this test function that shows the field I need

Unfortunately the documentation of the Cargo.toml fields is pretty non-existent and something I would definitely appreciate PRs to improve; I'm stretched pretty thin at the moment, but I might have some time to put some together; ideally we'd have an mdBook specifically for cargo-component that outlines use cases, howtos, and reference information.

Is there currently an active registry I can target with the cargo-component add wasi:http command? Trying to do it without setting a registry gives a related failure, but setting the below (only registry url I ran across) also throws an error:

There's a mismatch between the preview registry and the version supported by cargo-component; I don't think the registry preview has been updated in a while and we haven't been publishing up-to-date packages for WASI to it.

There's some work being done right now to bootstrap a lighter implementation of a component registry on-top of OCI-based registries so we can get off the ground with this (and also consistently publish the WASI packages) that should bear fruit in the near-term, so hopefully within a month or two we'll have what's needed to finally land the appropriate developer experience here.

If the registry is not yet ready, what is the best place/strategy for sourcing the wasi:* wit files to make a seamless transition when all of the machinery is in place?

As the registry isn't ready yet, the best practice is to use a deps folder like you would with wit-bindgen, but as cargo-component doesn't automatically search a deps folder like wit-bindgen does, you'll need to add an explicit entry in Cargo.toml for each (transitive) dependency.

That can be done with cargo component add. An example of adding wasi:io:

cargo component add --target --path wit/deps/io wasi:io

When registries are finally a thing, we'll be able to simply target wasi:http/proxy (or any other published world) or directly reference wasi:http interfaces from your WIT with a cargo component add --target wasi:http


Last updated: Nov 25 2024 at 19:03 UTC