bytecodealliance / bytecodealliance/wit-bindgen
C++: generated `_cpp.h` includes `exports-*.h` before the records they use
- Dominant language
- Rust
- Stars
- 1.5k
- Forks
- 286
- Avg merge
- 6h 32m
- Merged PRs (30d)
- 19
Description
A world that exports a resource taking a record generates a `_cpp.h` that doesn't compile. The user-class header is `#include`d above the record definitions it references.
### Example
Given the following wit:
```wit
package foo:bar;
interface my-interface {
record options {
name: string
}
resource my-resource {
constructor(o: options);
}
}
world my-world { export my-interface; }
```
Generate wit bindings:
```shell
wit-bindgen cpp wit --world my-world
```
Run the output through the compiler
```shell
$WASI_SDK_PATH/bin/clang++ --target=wasm32-wasip2 -std=c++23 -fsyntax-only my_world.cpp
```
Gives the following error:
```
In file included from my_world.cpp:11:
In file included from ./my_world_cpp.h:4:
./exports-foo-bar-my_interface-MyResource.h:18:36: error: no type named 'Options' in namespace
'exports::foo::bar::my_interface'
18 | MyResource(my_interface::Options o);
| ~~~~~~~~~~~~~~^
./exports-foo-bar-my_interface-MyResource.h:19:42: error: no type named 'Options' in namespace
'exports::foo::bar::my_interface'
19 | static Owned New(my_interface::Options o){return Owned(new MyResource(std::move(o)));}
| ~~~~~~~~~~~~~~^
2 errors generated.
```
Tested with wit-bindgen v0.59.0
Contributor guide
No contributing guide indexed for this repository
Research direction
Run `wit-bindgen cpp wit --world my-world` with the WIT example, then compile `my_world.cpp` using the shown WASI SDK command. Inspect `my_world_cpp.h` and `exports-foo-bar-my_interface-MyResource.h`; done means the generated header compiles without the reported missing `Options` errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, wasm
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100