From 95e4a6b6ae81a4958ce72a8431dfbf643b0b489c Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 27 Jan 2024 14:42:56 +0700 Subject: [PATCH] wgpu.h: Don't require preprocessing to use. Right now, `wgpu.h` can be included directly and it then includes `webgpu-headers/webgpu.h`. This is altered during creation of a distribution package to remove the `"webgpu-headers"`, but by adding `ffi/webgpu-headers` to the include search path, we can avoid having to preprocess the `wgpu.h`. --- Makefile | 6 ++---- build.rs | 2 +- examples/capture/CMakeLists.txt | 1 + examples/compute/CMakeLists.txt | 1 + examples/enumerate_adapters/CMakeLists.txt | 1 + examples/framework/CMakeLists.txt | 1 + examples/texture_arrays/CMakeLists.txt | 1 + examples/triangle/CMakeLists.txt | 1 + ffi/wgpu.h | 2 +- 9 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d7d9bb92..b56a1132 100644 --- a/Makefile +++ b/Makefile @@ -50,13 +50,11 @@ package: lib-native lib-native-release ARCHIVE=$(ARCHIVE_NAME)-$$RELEASE.zip; \ LIBDIR=$(TARGET_DIR)/$$RELEASE; \ rm -f dist/$$ARCHIVE; \ - sed 's/webgpu-headers\///' ffi/wgpu.h > wgpu.h ;\ if [ $(OS_NAME) = windows ]; then \ - 7z a -tzip dist/$$ARCHIVE ./$$LIBDIR/wgpu_native.dll ./$$LIBDIR/wgpu_native.dll.lib ./$$LIBDIR/wgpu_native.pdb ./$$LIBDIR/wgpu_native.lib ./ffi/webgpu-headers/*.h ./wgpu.h ./dist/commit-sha; \ + 7z a -tzip dist/$$ARCHIVE ./$$LIBDIR/wgpu_native.dll ./$$LIBDIR/wgpu_native.dll.lib ./$$LIBDIR/wgpu_native.pdb ./$$LIBDIR/wgpu_native.lib ./ffi/webgpu-headers/*.h ./ffi/wgpu.h ./dist/commit-sha; \ else \ - zip -j dist/$$ARCHIVE ./$$LIBDIR/libwgpu_native.so ./$$LIBDIR/libwgpu_native.dylib ./$$LIBDIR/libwgpu_native.a ./ffi/webgpu-headers/*.h ./wgpu.h ./dist/commit-sha; \ + zip -j dist/$$ARCHIVE ./$$LIBDIR/libwgpu_native.so ./$$LIBDIR/libwgpu_native.dylib ./$$LIBDIR/libwgpu_native.a ./ffi/webgpu-headers/*.h ./ffi/wgpu.h ./dist/commit-sha; \ fi; \ - rm wgpu.h ;\ done clean: diff --git a/build.rs b/build.rs index 50d70a41..c4ff2512 100644 --- a/build.rs +++ b/build.rs @@ -42,8 +42,8 @@ fn main() { ("WGPUTextureView", "WGPUTextureViewImpl"), ]; let mut builder = bindgen::Builder::default() - .header("ffi/webgpu-headers/webgpu.h") .header("ffi/wgpu.h") + .clang_arg("-Iffi/webgpu-headers") .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .blocklist_function("wgpuGetProcAddress") .prepend_enum_name(false) diff --git a/examples/capture/CMakeLists.txt b/examples/capture/CMakeLists.txt index 60f261ec..db148c9a 100644 --- a/examples/capture/CMakeLists.txt +++ b/examples/capture/CMakeLists.txt @@ -12,6 +12,7 @@ endif() add_definitions(-DSTB_IMAGE_WRITE_IMPLEMENTATION) include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) include_directories(${CMAKE_SOURCE_DIR}/framework) if (WIN32) diff --git a/examples/compute/CMakeLists.txt b/examples/compute/CMakeLists.txt index cbd28afa..e6efecfe 100644 --- a/examples/compute/CMakeLists.txt +++ b/examples/compute/CMakeLists.txt @@ -10,6 +10,7 @@ else() endif() include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) include_directories(${CMAKE_SOURCE_DIR}/framework) if (WIN32) diff --git a/examples/enumerate_adapters/CMakeLists.txt b/examples/enumerate_adapters/CMakeLists.txt index 82c26d94..a939822d 100644 --- a/examples/enumerate_adapters/CMakeLists.txt +++ b/examples/enumerate_adapters/CMakeLists.txt @@ -10,6 +10,7 @@ else() endif() include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) include_directories(${CMAKE_SOURCE_DIR}/framework) if (WIN32) diff --git a/examples/framework/CMakeLists.txt b/examples/framework/CMakeLists.txt index caee9824..bdefbd36 100644 --- a/examples/framework/CMakeLists.txt +++ b/examples/framework/CMakeLists.txt @@ -10,6 +10,7 @@ else() endif() include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) if (WIN32) set(OS_LIBRARIES d3dcompiler ws2_32 userenv bcrypt ntdll opengl32) diff --git a/examples/texture_arrays/CMakeLists.txt b/examples/texture_arrays/CMakeLists.txt index 4c1a3e5b..b235c859 100644 --- a/examples/texture_arrays/CMakeLists.txt +++ b/examples/texture_arrays/CMakeLists.txt @@ -10,6 +10,7 @@ else() endif() include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) include_directories(${CMAKE_SOURCE_DIR}/framework) if (WIN32) diff --git a/examples/triangle/CMakeLists.txt b/examples/triangle/CMakeLists.txt index d1af70e7..61537239 100644 --- a/examples/triangle/CMakeLists.txt +++ b/examples/triangle/CMakeLists.txt @@ -10,6 +10,7 @@ else() endif() include_directories(${CMAKE_SOURCE_DIR}/../ffi) +include_directories(${CMAKE_SOURCE_DIR}/../ffi/webgpu-headers) include_directories(${CMAKE_SOURCE_DIR}/framework) if (WIN32) diff --git a/ffi/wgpu.h b/ffi/wgpu.h index 9257a6e7..d397fa68 100644 --- a/ffi/wgpu.h +++ b/ffi/wgpu.h @@ -1,7 +1,7 @@ #ifndef WGPU_H_ #define WGPU_H_ -#include "webgpu-headers/webgpu.h" +#include "webgpu.h" typedef enum WGPUNativeSType { // Start at 0003 since that's allocated range for wgpu-native