Skip to content

Commit ea18c8f

Browse files
committed
Generate remote header
1 parent bd0de53 commit ea18c8f

File tree

4 files changed

+63
-40
lines changed

4 files changed

+63
-40
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs)
5353
lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs)
5454
cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST)
5555

56-
wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
56+
wgpu-bindings/*.h: Cargo.lock wgpu-bindings/src/*.rs lib-native
5757
cargo +nightly-2018-12-27 run --manifest-path wgpu-bindings/Cargo.toml
5858

5959
examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c)

wgpu-bindings/src/main.rs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,51 @@ extern crate cbindgen;
22

33
use std::path::PathBuf;
44

5-
const HEADER: &str = "
6-
#ifdef WGPU_REMOTE
7-
typedef uint32_t WGPUId;
8-
#else
9-
typedef void *WGPUId;
10-
#endif
11-
";
5+
struct Binding<'a> {
6+
library: &'a str,
7+
features: &'a [&'a str],
8+
output: &'a str,
9+
}
10+
11+
const BINDINGS: [Binding; 2] = [
12+
Binding {
13+
library: "wgpu-native",
14+
features: &["local"],
15+
output: "wgpu.h",
16+
},
17+
Binding {
18+
library: "wgpu-remote",
19+
features: &[],
20+
output: "wgpu-remote.h",
21+
},
22+
];
1223

1324
fn main() {
1425
let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
15-
let source_dir = crate_dir.parent().unwrap().join("wgpu-native");
26+
let parent = crate_dir.parent().unwrap();
1627

17-
let config = cbindgen::Config {
18-
header: Some(String::from(HEADER.trim())),
19-
enumeration: cbindgen::EnumConfig {
20-
prefix_with_name: true,
21-
..Default::default()
22-
},
23-
export: cbindgen::ExportConfig {
24-
prefix: Some(String::from("WGPU")),
25-
exclude: vec![
26-
// We manually define `Id` is within the header, so exclude it here
27-
String::from("Id"),
28-
],
28+
for bind in &BINDINGS {
29+
let config = cbindgen::Config {
30+
enumeration: cbindgen::EnumConfig {
31+
prefix_with_name: true,
32+
..Default::default()
33+
},
34+
export: cbindgen::ExportConfig {
35+
prefix: Some(String::from("WGPU")),
36+
..Default::default()
37+
},
38+
language: cbindgen::Language::C,
2939
..Default::default()
30-
},
31-
language: cbindgen::Language::C,
32-
..Default::default()
33-
};
40+
};
3441

35-
cbindgen::Builder::new()
36-
.with_crate(source_dir)
37-
.with_config(config)
38-
.with_parse_expand(&["wgpu-native"])
39-
.with_parse_expand_features(&["local"])
40-
.generate()
41-
.unwrap()
42-
.write_to_file(crate_dir.join("wgpu.h"));
42+
println!("Generating {}...", bind.output);
43+
cbindgen::Builder::new()
44+
.with_crate(parent.join(bind.library))
45+
.with_config(config)
46+
.with_parse_expand(&[bind.library])
47+
.with_parse_expand_features(bind.features)
48+
.generate()
49+
.unwrap()
50+
.write_to_file(crate_dir.join(bind.output));
51+
}
4352
}

wgpu-bindings/wgpu-remote.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <stdarg.h>
2+
#include <stdbool.h>
3+
#include <stdint.h>
4+
#include <stdlib.h>
5+
6+
typedef struct WGPUClient WGPUClient;
7+
8+
WGPUDeviceId wgpu_adapter_create_device(const WGPUClient *client,
9+
WGPUAdapterId adapter_id,
10+
const WGPUDeviceDescriptor *desc);
11+
12+
WGPUAdapterId wgpu_instance_get_adapter(const WGPUClient *client,
13+
WGPUInstanceId instance_id,
14+
const WGPUAdapterDescriptor *desc);

wgpu-bindings/wgpu.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
#ifdef WGPU_REMOTE
2-
typedef uint32_t WGPUId;
3-
#else
4-
typedef void *WGPUId;
5-
#endif
6-
71
#include <stdarg.h>
82
#include <stdbool.h>
93
#include <stdint.h>
@@ -138,7 +132,8 @@ typedef enum {
138132
WGPUTextureFormat_R8g8b8a8Unorm = 0,
139133
WGPUTextureFormat_R8g8b8a8Uint = 1,
140134
WGPUTextureFormat_B8g8r8a8Unorm = 2,
141-
WGPUTextureFormat_D32FloatS8Uint = 3,
135+
WGPUTextureFormat_D32Float = 3,
136+
WGPUTextureFormat_D32FloatS8Uint = 4,
142137
} WGPUTextureFormat;
143138

144139
typedef enum {
@@ -155,8 +150,11 @@ typedef enum {
155150
WGPUVertexFormat_FloatR32G32B32 = 1,
156151
WGPUVertexFormat_FloatR32G32 = 2,
157152
WGPUVertexFormat_FloatR32 = 3,
153+
WGPUVertexFormat_IntR8G8B8A8 = 4,
158154
} WGPUVertexFormat;
159155

156+
typedef uint32_t WGPUId;
157+
160158
typedef WGPUId WGPUDeviceId;
161159

162160
typedef WGPUId WGPUAdapterId;
@@ -632,6 +630,8 @@ WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id,
632630

633631
WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc);
634632

633+
void wgpu_device_destroy(WGPUBufferId device_id);
634+
635635
WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id);
636636

637637
WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id,

0 commit comments

Comments
 (0)