wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

--generate-stub for Rust

Open EugenDueck opened this issue 7 months ago • 6 comments

Does anything speak against adding a --generate-stub flag for Rust, like the one for CSharp?

> wit-bindgen csharp --help | grep stub
      --generate-stub
          Whether or not to generate a stub class for exported functions

If not, I may consider contributing a PR for this.

EugenDueck avatar Aug 12 '25 13:08 EugenDueck

Does the --stubs flag work for you?

alexcrichton avatar Aug 12 '25 14:08 alexcrichton

The problem with --stubs is that the stub gets embedded within the bindings file. What I'm looking for is something like a separate lib.rs file containing just the stub. A file that can be manually edited, and that won't get overwritten when re-running wit-bindgen (unless perhaps the --generate-stub flag is set again)

EugenDueck avatar Aug 12 '25 22:08 EugenDueck

However, as the rust command already has the --stubs flag, adding another --generate-stubs doesn't feel ideal. Perhaps adding an optional value to --stubs that can be either embedded or separate, defaulting to the former if we want to maintain backwards compatibility?

EugenDueck avatar Aug 12 '25 22:08 EugenDueck

The reason I wanted this no longer applies, as I already have a WIT generator and decided to just add a flag to also generate the stubs. However, if there’s interest in such a feature for wit-bindgen, I may take a stab at it.

EugenDueck avatar Aug 13 '25 07:08 EugenDueck

Ah ok makes sense, and yeah I think it'd be reasonable to add support for this and generating into a separate file

alexcrichton avatar Aug 13 '25 15:08 alexcrichton

I've created a draft PR with a couple of discussion points: #1354

EugenDueck avatar Aug 15 '25 03:08 EugenDueck