Skip to content
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

Generating Rust types from C headers #78

Closed
kvark opened this issue Feb 22, 2021 · 1 comment
Closed

Generating Rust types from C headers #78

kvark opened this issue Feb 22, 2021 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@kvark
Copy link
Member

kvark commented Feb 22, 2021

Now that we are getting closer to #6 with PRs by @Sineaggi like #77, it seems to me that trying to re-define all the types that we need for C headers is a lot of redundant work. We already have those definitions in the shared C header, perhaps we could generate the Rust types automatically? https://github.com/rust-lang/rust-bindgen would help.

So wgpu-native would not need to define anything, it would just contain logic to map from the auto-generated types into wgpu-core and wgpu-types.

@kvark kvark added the help wanted Extra attention is needed label Feb 22, 2021
@kvark kvark pinned this issue Feb 22, 2021
bors bot added a commit that referenced this issue Apr 2, 2021
85: Start migration from cbindgen to bindgen r=kvark a=DevOrc

Fix for #78 - has rust types generated by the header instead of vice-versa. Currently still needs a lot of work (most of the original codebase is deleted 😞 ) but I am slowly reimplementing everything with the generated types. Currently the triangle and compute examples _should_ work on Windows and Linux. Anyways, thought I would post this here to get initial thoughts before I finished adding everything. 

## Big changes
- all of the header types are generated at build time and inserted into the `crate::native` module
- enums are mapped from their c types to wgt using a macro (map_enum!)
- two c headers (`ffi/webgpu.h` for things in the [webgpu-native](https://github.com/webgpu-native/webgpu-headers) headers, and `ffi/wgpu.h` for stuff unique to wgpu-native)

## Small Notes
- auto-generated bindings are modified at build time to change all of the *Impl to Ids (`BindGroupImpl` -> `wgc::id::BindGroupId`)
- libclang now required to build (required by bindgen)
- enum constants are i32 on windows and are u32 on macos/linux
- example shaders are now written in WGSL
- Had to change some of the makefiles for windows c development (if anyone has a better way to write makefiles please let me know :smile:)

## Stuff that still needs to be added
- [x] MacOS Surfaces
- [ ] Wayland Surfaces
- [x]  most commands
- [x] undelete / update the capture example
- [x] logging
- [x] Textures
- [x] Fix IOS
- [ ] Include webgpu.h in release CI

Co-authored-by: Noah Charlton <[email protected]>
@cwfitzgerald
Copy link
Member

This has happened.

@cwfitzgerald cwfitzgerald unpinned this issue Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants