odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.1k stars 550 forks source link

`wgpu` vendor library doesn't compile on Windows #3797

Closed Valakor closed 1 week ago

Valakor commented 1 week ago

Context

Odin:    dev-2024-06:3af9d31bd
OS:      Windows 11 Professional (version: 23H2), build 22631.3737
CPU:     AMD Ryzen 9 5900X 12-Core Processor
RAM:     32692 MiB
Backend: LLVM 17.0.1

Expected Behavior

Importing and using the new wgpu bindings should compile successfully on supported platforms.

Current Behavior

Compilation fails on Windows 11 with 12 unresolved externals during linking.

Failure Information

Linking fails with 12 unresolved externals: GetClientRect, ChoosePixelFormat, GetPixelFormat, SetPixelFormat, DescribePixelFormat, RegisterClassExA, DefWindowProcA, DestroyWindow, ReleaseDC, GetDC, SwapBuffers, and CreateWindowExA. I believe these references are coming from the internal wgpu_hal component.

Steps to Reproduce

  1. Try to compile a project importing wgpu on Windows

Failure Logs

wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.04.rcgu.o) : error LNK2019: unresolved external symbol GetClientRect referenced in function _ZN8wgpu_hal4dx127adapter98_$LT$impl$u20$wgpu_hal..Adapter$LT$wgpu_hal..dx12..Api$GT$$u20$for$u20$wgpu_hal..dx12..Adapter$GT$20surface_capabilities17h2dc065962b670410E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol ChoosePixelFormat referenced in function _ZN8wgpu_hal4gles3wgl18setup_pixel_format17h7b4da851ec93afe6E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol GetPixelFormat referenced in function _ZN8wgpu_hal4gles3wgl18setup_pixel_format17h7b4da851ec93afe6E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol SetPixelFormat referenced in function _ZN8wgpu_hal4gles3wgl18setup_pixel_format17h7b4da851ec93afe6E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol DescribePixelFormat referenced in function _ZN8wgpu_hal4gles3wgl18setup_pixel_format17h7b4da851ec93afe6E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol RegisterClassExA referenced in function _ZN8wgpu_hal4gles3wgl26create_global_window_class17h3e18397baa90112cE
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol DefWindowProcA referenced in function _ZN8wgpu_hal4gles3wgl26create_global_window_class8wnd_proc17h04764272b1c8decbE
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol DestroyWindow referenced in function _ZN93_$LT$wgpu_hal..gles..wgl..create_instance_device..Window$u20$as$u20$core..ops..drop..Drop$GT$4drop17h1d8752a627823d6aE
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol ReleaseDC referenced in function _ZN82_$LT$wgpu_hal..gles..wgl..DeviceContextHandle$u20$as$u20$core..ops..drop..Drop$GT$4drop17h6b5c61f7b387c816E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.07.rcgu.o) : error LNK2001: unresolved external symbol ReleaseDC
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol GetDC referenced in function _ZN8wgpu_hal4gles3wgl7Surface7present17hcb7a9eb52e50d730E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.07.rcgu.o) : error LNK2001: unresolved external symbol GetDC
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.11.rcgu.o) : error LNK2019: unresolved external symbol SwapBuffers referenced in function _ZN8wgpu_hal4gles3wgl7Surface7present17hcb7a9eb52e50d730E
wgpu_native.lib(wgpu_hal-21a2669e9a4b6f3d.wgpu_hal.c844be58bcd8d3b9-cgu.07.rcgu.o) : error LNK2019: unresolved external symbol CreateWindowExA referenced in function _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17hd587767320e9ec7bE
D:\Projects\odin\demo\demo.exe : fatal error LNK1120: 12 unresolved externals
MrMonotone commented 1 week ago

try adding "system:user32.lib" to the list in https://github.com/odin-lang/Odin/blob/3af9d31bd52c4714beddd2eaf154eadaf81d14b1/vendor/wgpu/wgpu.odin#L19

Valakor commented 1 week ago

Whoops, I forgot to add to my original post that adding system:user32.lib and system:gdi32.lib fixes the compilation errors, I just haven't been able to set up a fork and make a pull request.

laytan commented 1 week ago

I did have this working while testing without these libraries, I took the needed libraries from https://github.com/gfx-rs/wgpu-native/blob/v0.19.4.1/examples/framework/CMakeLists.txt I will test it again and report back.

laytan commented 1 week ago

It may be because I was testing in combination with glfw, which adds the user32.lib dependency