Stream: cargo-component

Topic: Incoming breaking change


view this post on Zulip Peter Huene (Mar 01 2024 at 19:31):

Just a heads up that I will be publishing 0.9.0 of cargo-component shortly, which will include a breaking change introduced with wit-bindgen 0.20.0.

It was decided that we'd return to using a generated export! macro that accepts the name of the type implementing the world (typically Component in cargo-component projects).

This was done for good reason: now the generated code does not refer to any user-defined types directly and it also moves naming the implementing types out of Cargo.toml into type-checked Rust source.

Besides adding this macro invocation to your cargo-component projects, there are additional steps to take if you're implementing worlds that export resources: a trait-associated type now names the type implementing the resource.

I'll have detailed instructions in the release notes.

view this post on Zulip Alex Crichton (Mar 01 2024 at 19:47):

Apologies again for the whiplash here on generated bindings and effort in cargo component to adapt to this, but my hope is that this is well worth the change!

view this post on Zulip Peter Huene (Mar 01 2024 at 19:59):

@Alex Crichton now that we have most of what was in the rt module of wit-bindgen now generated, do you think it might be possible to refactor the realloc feature out as a separate crate that we could reexport from wit-bindgen (and also perhaps the reexport of bitflags), like a wit-bindgen-rt crate?

The reason I ask is that currently cargo-component user projects add a wit-bindgen dependency with no-default-features and features = ["realloc"]; this happens via an implicit cargo add when cargo component new is run.

However, if a user specifies the dependency at the workspace level, cargo add refuses to add it at a workspace member level because of no-default-features (despite being set the same).

If we had a crate that exported everything we needed for "runtime" that we could activate without feature flags, I think that would probably be a better DX; cargo-component would just add a dependency to the "rt" crate and not wit-bindgen at all (we still have Opts::runtime_path that cargo-component can use to switch it to wit_bindgen_rt or whatever in the bindings).

view this post on Zulip Alex Crichton (Mar 01 2024 at 20:05):

I like that idea yeah, I can work on adding that :+1:

view this post on Zulip Alex Crichton (Mar 01 2024 at 20:26):

https://github.com/bytecodealliance/wit-bindgen/pull/876

This commit extracts out a wit-bindgen-rt crate which unconditionally provides the cabi_realloc function. This'll exist for cargo component to add a dependency on and otherwise the wit-bindgen crat...

view this post on Zulip Peter Huene (Mar 01 2024 at 21:05):

One last thing: would it be possible to kick off a publish job to get 0.20.0 of wit-bindgen-rt on crates.io? While it won't be used (reexported) from wit-bindgen until 0.21.0, a 0.20.0 of wit-bindgen-rt would allow me to switch cargo component new over to it as part of this breaking change release

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:07):

oh I was thinking I could do 0.20.1

view this post on Zulip Peter Huene (Mar 01 2024 at 21:07):

oh that's also great!

view this post on Zulip Peter Huene (Mar 01 2024 at 21:08):

thanks, Alex!

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:08):

oh no, that won't work

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:08):

I changed something in Opts that's breaking

view this post on Zulip Peter Huene (Mar 01 2024 at 21:08):

doh

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:08):

yeah though I can sneak in a publish manually for this

view this post on Zulip Peter Huene (Mar 01 2024 at 21:09):

that'd be sufficient for cargo-component at least, appreciate it!

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:09):

can do :+1:

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:36):

@Peter Huene hm this may not actually work, the generated code isn't prepared to access wit-bindgen-rt directly actually

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:37):

e.g. the generated code is calling wit_bindgen::rt::maybe_link_cabi_realloc()

view this post on Zulip Peter Huene (Mar 01 2024 at 21:37):

even via the runtime_path and bitflags_path Opts?

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:37):

so we'll need to add a wit_bindgen_rt_path: "..." to the opts

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:37):

oh hm

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:37):

no you're right runtime_path should work

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:37):

I should probably rename that for 0.21.0 to wit_bindgen_rt_path

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:38):

ok yeah no runtime_path will work for 0.20, disregard me

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:41):

Ok I have published

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:42):

actually wait

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:42):

I think that wit-bindgen 0.20.0 and wit-bindgen-rt 0.20.0 may conflict with each other

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:42):

since they both have a symbol of the same name

view this post on Zulip Peter Huene (Mar 01 2024 at 21:43):

cargo-component projects will only link in the latter tho, right?

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:43):

the issue stems from a workspace-level dep on wit-bindgen though, right?

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:43):

so while by default cargo-component would use wit-bindgen-rt that may not be the case for all users

view this post on Zulip Peter Huene (Mar 01 2024 at 21:43):

oh yeah, they'll have to fix the workspace dep as part of the breaking changes in this release

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:43):

ah ok

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:44):

I can also just make 0.21.0 if that's easier

view this post on Zulip Peter Huene (Mar 01 2024 at 21:44):

it's just new projects they create will get it

view this post on Zulip Peter Huene (Mar 01 2024 at 21:44):

they'll have to manually update; they shouldn't be referencing both

view this post on Zulip Alex Crichton (Mar 01 2024 at 21:44):

ok sounds reasonable

view this post on Zulip Peter Huene (Mar 01 2024 at 21:46):

i'll document what folks need to do to get things up-and-running again; i just wanted to batch these changes together in a single release

view this post on Zulip Peter Huene (Mar 01 2024 at 21:54):

changes look good, no more feature-flagged wit-bindgen dep :tada:


Last updated: Oct 23 2024 at 20:03 UTC