Skip to content

Separate rust stubs #1354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

EugenDueck
Copy link

Changes

--stubs
    If true, generate stub implementations for any exported functions, interfaces, and/or resources

to

--stubs <STUBS>
    Whether to generate stub implementations for any exported functions, interfaces, and/or resources.
    
    Valid values are:
    
    - `omit`: Stubs will not be generated.
    
    - `embedded`: Stubs will be generated in the bindings file.
    
    - `separate`: Stubs will be generated in a separate _impl file.
    
    [default: omit]

resolves #1347

I put this in draft mode, because there is still things to discuss.

  1. The separate file is now called {world_name}_impl.rs.

However, I'd prefer the implementation to be in {world_name}.rs, and the bindings file in {world_name}_bindings.rs. So I suggest to output bindings into {world_name}_bindings.rs. Even when --stubs != separate, so that the names are consistent, allowing for this use case:
First time around, you run wit-bindgen --stubs separate. Then you make manual edits to the implementation, and when the wit file changes, you just do a wit-bindgen, so as not to overwrite your manual edits.
As that file name change is perhaps a change users won't agree to, I wanted to discuss this first, before making that change.

  1. codegen tests for --stubs separate

Currently, there only embedded stubs get codegen-tested. I have run all codegen cases for the --stubs separate case as well locally, but it's not a straightforward change to run tests for both embedded and separate, so I have for now put the latter case behind a false constant:

const STUB_SEPARATE: bool = false;

So it can at least be tested manually by flipping that const to true. But I think we should always be testing both, because putting stubs into a different file opens a couple of different pitfalls.

Please let me know what you think, what changes you'd like to see etc.

Eugen

@pchickey
Copy link
Contributor

Thanks for working on this.

re 1, I don't see harm in making that change for all cases, but I don't use the cli (I tend to just use the proc macro on its own) so I'm not very opinionated. If someone else has an opinion here I'll defer to it.

re 2, Yes, both modes should be tested. We should somehow factor the test runner such that it can test more configs per LanguageMethods impl?

@EugenDueck
Copy link
Author

We should somehow factor the test runner such that it can test more configs per LanguageMethods impl?

It was relatively easy to refactor, by removing the distinction between "test variants" and the test base case. Codegen cmd line args for the. base case were also forced upon the variants. Incidentally makes the code a little cleaner and more DRY.

@EugenDueck EugenDueck marked this pull request as ready for review August 16, 2025 04:32
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.

--generate-stub for Rust
2 participants