From ea18c8fa85cc7854af9689d140833279c2e395c5 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 25 Feb 2019 21:18:42 -0500 Subject: [PATCH] Generate remote header --- Makefile | 2 +- wgpu-bindings/src/main.rs | 73 +++++++++++++++++++++---------------- wgpu-bindings/wgpu-remote.h | 14 +++++++ wgpu-bindings/wgpu.h | 14 +++---- 4 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 wgpu-bindings/wgpu-remote.h diff --git a/Makefile b/Makefile index 9b183aec1..84183036e 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ lib-native: Cargo.lock wgpu-native/Cargo.toml $(wildcard wgpu-native/**/*.rs) lib-rust: Cargo.lock wgpu-rs/Cargo.toml $(wildcard wgpu-rs/**/*.rs) cargo build --manifest-path wgpu-rs/Cargo.toml --features $(FEATURE_RUST) -wgpu-bindings/wgpu.h: Cargo.lock wgpu-bindings/src/*.rs lib-native +wgpu-bindings/*.h: Cargo.lock wgpu-bindings/src/*.rs lib-native cargo +nightly-2018-12-27 run --manifest-path wgpu-bindings/Cargo.toml examples-native: lib-native wgpu-bindings/wgpu.h $(wildcard wgpu-native/**/*.c) diff --git a/wgpu-bindings/src/main.rs b/wgpu-bindings/src/main.rs index c0ae3386c..0eafa66f5 100644 --- a/wgpu-bindings/src/main.rs +++ b/wgpu-bindings/src/main.rs @@ -2,42 +2,51 @@ extern crate cbindgen; use std::path::PathBuf; -const HEADER: &str = " -#ifdef WGPU_REMOTE - typedef uint32_t WGPUId; -#else - typedef void *WGPUId; -#endif -"; +struct Binding<'a> { + library: &'a str, + features: &'a [&'a str], + output: &'a str, +} + +const BINDINGS: [Binding; 2] = [ + Binding { + library: "wgpu-native", + features: &["local"], + output: "wgpu.h", + }, + Binding { + library: "wgpu-remote", + features: &[], + output: "wgpu-remote.h", + }, +]; fn main() { let crate_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - let source_dir = crate_dir.parent().unwrap().join("wgpu-native"); + let parent = crate_dir.parent().unwrap(); - let config = cbindgen::Config { - header: Some(String::from(HEADER.trim())), - enumeration: cbindgen::EnumConfig { - prefix_with_name: true, + for bind in &BINDINGS { + let config = cbindgen::Config { + enumeration: cbindgen::EnumConfig { + prefix_with_name: true, + ..Default::default() + }, + export: cbindgen::ExportConfig { + prefix: Some(String::from("WGPU")), + ..Default::default() + }, + language: cbindgen::Language::C, ..Default::default() - }, - export: cbindgen::ExportConfig { - prefix: Some(String::from("WGPU")), - exclude: vec![ - // We manually define `Id` is within the header, so exclude it here - String::from("Id"), - ], - ..Default::default() - }, - language: cbindgen::Language::C, - ..Default::default() - }; + }; - cbindgen::Builder::new() - .with_crate(source_dir) - .with_config(config) - .with_parse_expand(&["wgpu-native"]) - .with_parse_expand_features(&["local"]) - .generate() - .unwrap() - .write_to_file(crate_dir.join("wgpu.h")); + println!("Generating {}...", bind.output); + cbindgen::Builder::new() + .with_crate(parent.join(bind.library)) + .with_config(config) + .with_parse_expand(&[bind.library]) + .with_parse_expand_features(bind.features) + .generate() + .unwrap() + .write_to_file(crate_dir.join(bind.output)); + } } diff --git a/wgpu-bindings/wgpu-remote.h b/wgpu-bindings/wgpu-remote.h new file mode 100644 index 000000000..9d55b1a32 --- /dev/null +++ b/wgpu-bindings/wgpu-remote.h @@ -0,0 +1,14 @@ +#include +#include +#include +#include + +typedef struct WGPUClient WGPUClient; + +WGPUDeviceId wgpu_adapter_create_device(const WGPUClient *client, + WGPUAdapterId adapter_id, + const WGPUDeviceDescriptor *desc); + +WGPUAdapterId wgpu_instance_get_adapter(const WGPUClient *client, + WGPUInstanceId instance_id, + const WGPUAdapterDescriptor *desc); diff --git a/wgpu-bindings/wgpu.h b/wgpu-bindings/wgpu.h index db6a7ade9..29c9aff2e 100644 --- a/wgpu-bindings/wgpu.h +++ b/wgpu-bindings/wgpu.h @@ -1,9 +1,3 @@ -#ifdef WGPU_REMOTE - typedef uint32_t WGPUId; -#else - typedef void *WGPUId; -#endif - #include #include #include @@ -138,7 +132,8 @@ typedef enum { WGPUTextureFormat_R8g8b8a8Unorm = 0, WGPUTextureFormat_R8g8b8a8Uint = 1, WGPUTextureFormat_B8g8r8a8Unorm = 2, - WGPUTextureFormat_D32FloatS8Uint = 3, + WGPUTextureFormat_D32Float = 3, + WGPUTextureFormat_D32FloatS8Uint = 4, } WGPUTextureFormat; typedef enum { @@ -155,8 +150,11 @@ typedef enum { WGPUVertexFormat_FloatR32G32B32 = 1, WGPUVertexFormat_FloatR32G32 = 2, WGPUVertexFormat_FloatR32 = 3, + WGPUVertexFormat_IntR8G8B8A8 = 4, } WGPUVertexFormat; +typedef uint32_t WGPUId; + typedef WGPUId WGPUDeviceId; typedef WGPUId WGPUAdapterId; @@ -632,6 +630,8 @@ WGPUSwapChainId wgpu_device_create_swap_chain(WGPUDeviceId device_id, WGPUTextureId wgpu_device_create_texture(WGPUDeviceId device_id, const WGPUTextureDescriptor *desc); +void wgpu_device_destroy(WGPUBufferId device_id); + WGPUQueueId wgpu_device_get_queue(WGPUDeviceId device_id); WGPUSurfaceId wgpu_instance_create_surface_from_macos_layer(WGPUInstanceId instance_id,