gfx-rs / wgpu-native

Native WebGPU implementation based on wgpu-core
Apache License 2.0
885 stars 105 forks source link

Change include path in `wgpu.h` #424

Closed eliemichel closed 2 months ago

eliemichel commented 2 months ago

The generated release zips files are organized as follows:

 - include/
   - webgpu/
     - webgpu.h
   - wgpu/
     - wgpu.h
 - lib/
   - ...

However, wgpu.h includes webgpu.h with #include "webgpu.h", which forces to add include/webgpu/ to the include directories, while it feels more idiomatic to only include include/. Other implementations also have webgpu.h in a include/webgpu/ subfolder so I suggest leaving this so, leading to two possible fixes:

almarklein commented 2 months ago

@rajveermalviya and @Sahnvour thoughts?

I don't really care personally (I made wgpu-py find the files regardless of folder structure 😅).

rajveermalviya commented 2 months ago

Thanks for catching this issue, @eliemichel!

Updating the checked-in file directly would cause problems with bindgen, and since this only impacts package builds, the best approach (for now) is to update the Makefile instead:

diff --git a/Makefile b/Makefile
index 6a5546e..ddea760 100644
--- a/Makefile
+++ b/Makefile
@@ -59,6 +59,7 @@ package: lib-native lib-native-release
                cp ./dist/wgpu-native-git-tag                 dist/$$ARCHIVEDIR; \
                cp ./ffi/webgpu-headers/webgpu.h              dist/$$ARCHIVEDIR/include/webgpu; \
                cp ./ffi/wgpu.h                               dist/$$ARCHIVEDIR/include/wgpu; \
+               sed -i '' 's/"webgpu.h"/<webgpu\/webgpu.h>/'  dist/$$ARCHIVEDIR/include/wgpu/wgpu.h; \
                if [ $(OS_NAME) = linux ]; then \
                        cp ./$$LIBDIR/libwgpu_native.so           dist/$$ARCHIVEDIR/lib; \
                        cp ./$$LIBDIR/libwgpu_native.a            dist/$$ARCHIVEDIR/lib; \

For reference, the folder structure was updated in #417 and #419, but we missed updating the include path because there’s no testing infrastructure for the built archives at the moment.

almarklein commented 2 months ago

I know I said I don't care ... but changing the contents of a file in the makefile is rather unexpected and may cause confusion.

What about option B? Keeping webgpu.h and wgpu.h together does feel nice and simple, and wgpu.h basically defines 'extensions' so webgpu, so it kinda makes sense (to me)?

Sahnvour commented 2 months ago

IMHO option B is simpler and more intuitive, I don't think it causes any trouble to have both headers in the same folder.

eliemichel commented 2 months ago

If Option B feels like a better solution, here is an alternative PR (which indeed only affects the Makefile): https://github.com/gfx-rs/wgpu-native/pull/425

almarklein commented 2 months ago

Thanks @eliemichel! Closing in favor of #425