Skip to content

feature request: bindings subcommand #362

Closed

Description

@dakom

When working on a component locally, I often go through this flow:

  1. Make changes to the wit
  2. Generate the new bindings
  3. Make changes to the component

Currently, afaik, the way to generate the new bindings is to run a full cargo component build. This has a few drawbacks:

  1. It inevitably has errors, because I don't make the rest of the code changes until I have the new bindings to build against
  2. It's a bit unintuitive, I genuinely don't want to build the component, feels a bit like using the non-optimal command for its side-effect
  3. It's doing more than necessary (I think), a bindings-only subcommand would likely be much faster

I think it would be a tooling improvement to have an explicit subcommand that just generates the bindings, without building the full component

Activity

  1. sunfishcode commented on Dec 13, 2024

    @sunfishcode
    Member

    A somewhat lighter-weight alternative that works today is cargo component check. It still prints the errors, but it doesn't do as much work so it is faster. That said, I agree, a way to generate just the bindings is a good idea.

  2. vados-cosmonic commented on Dec 21, 2024

    @vados-cosmonic

    This is a slightly bigger change, but what @sunfishcode what do you think about re-introducing a macro to generate the bindings, or a build.rs?

    Reading over the previous context it seems like we removed it in order to increase build speed, but it really seems like what we want is to hook into the build process and ensure bindings are built (and if they can't be, to error early/quickly) -- I think in most of the ecosystem outside of cargo-component this is done with macros that possibly output to local files for easy review (otherwise people lean on cargo-expand)...

    I agree with both of you here and want to point out that the experience of cargo component new and being greeted with tons of "red squigglies" isn't great. My immediate first thought was:

    oh, I should add information about the binding generation command to component-docs so that people can at least know to run that before the open src/lib.rs

    And then found this issue because it doesn't exist (yet!). That made me start to think again about the whole starting experience here.

  3. added a commit that references this issue on Jan 3, 2025
    5e2c261
  4. sunfishcode commented on Jan 3, 2025

    @sunfishcode
    Member

    I've now submitted #366 which adds a bindings subcommand which just regenerates the bindings.

    @vados-cosmonic I also added some code to auto-generate the bindings as part of cargo component new, which should improve the startup experience.

    I'm not opposed to larger changes, but I'm curious if these simple fixes are enough.

  5. vados-cosmonic commented on Jan 4, 2025

    @vados-cosmonic

    Hey @sunfishcode IMO that's perfect, thanks -- the bindings subcommand was more than enough, and the new integration sounds like it'll be a very ergonomic change.

    The README and related documentation should probably be changed to match as well, but I'm in favor of making that a separate, focused issue (so we can capture the parts to change, and maybe even do a bit of a docs overhaul for this crate).

  6. added a commit that references this issue on Jan 6, 2025
    130438f
  7. sunfishcode commented on Jan 7, 2025

    @sunfishcode
    Member

    The new bindings subcommand and cargo component new improvements are now released in cargo-component 0.20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions