From 0de0a2c0a1d12c32d6b3078664503b01e68dbc52 Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Mon, 26 Feb 2024 17:26:39 -0600 Subject: [PATCH 1/2] Fix GLFW compilation on Windows --- Makefile | 2 +- examples/utils/subprojects/glfw.Makefile | 47 +++++++++++++++++++----- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 36aca36..0e028e7 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ subprojects/wgpu: subprojects/wgpu.Makefile ifneq ($(OS),Windows_NT) file subprojects/wgpu/$(LIB_WGPU) else - IF EXIST subprojects/wgpu/$(LIB_WGPU) ECHO subprojects/wgpu/$(LIB_WGPU) exists. + @IF EXIST subprojects/wgpu/$(LIB_WGPU) ECHO subprojects/wgpu/$(LIB_WGPU) exists. endif subprojects/wgpu/$(LIB_WGPU): subprojects/wgpu wgpu: subprojects/wgpu/$(LIB_WGPU) diff --git a/examples/utils/subprojects/glfw.Makefile b/examples/utils/subprojects/glfw.Makefile index 28fdb91..00b8fa1 100644 --- a/examples/utils/subprojects/glfw.Makefile +++ b/examples/utils/subprojects/glfw.Makefile @@ -1,14 +1,41 @@ VERSION := 3.3.6 +OS ?= $(shell uname -s) -.DEFAULT_GOAL := glfw/src/libglfw3.a +ifeq ($(OS),Windows_NT) + TARGET := glfw/src/glfw3.lib +else + TARGET := glfw/src/libglfw3.a +endif -glfw/src/libglfw3.a: - @echo "Downloading GLFW sources…" - @curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output /tmp/glfw-$(VERSION).zip - @echo "Unzipping GLFW sources…" +.DEFAULT_GOAL := $(TARGET) + +ifeq ($(OS),Windows_NT) + ARCHIVE_ZIP := $(shell echo %USERPROFILE%/AppData/Local/Temp/glfw-$(VERSION).zip) +else + ARCHIVE_ZIP := /tmp/glfw-$(VERSION).zip +endif + +DEFINES := GLFW_BUILD_TESTS=OFF GLFW_BUILD_EXAMPLES=OFF GLFW_BUILD_DOCS=OFF +ifeq ($(OS),Windows_NT) + DEFINES += USE_MSVC_RUNTIME_LIBRARY_DLL=ON +endif + +$(TARGET): + @echo Downloading GLFW sources... +ifeq ($(OS),Windows_NT) + @if exist $(ARCHIVE_ZIP) echo Using cached download. + @if not exist $(ARCHIVE_ZIP) curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output $(ARCHIVE_ZIP) +else + @curl -L https://github.com/glfw/glfw/releases/download/$(VERSION)/glfw-$(VERSION).zip --output $(ARCHIVE_ZIP) +endif + @echo Unzipping GLFW sources... +ifeq ($(OS),Windows_NT) + @if not exist glfw tar -xf $(ARCHIVE_ZIP) + @if not exist glfw rdmd --eval "std.file.rename(\"glfw-$(VERSION)\", \"glfw\");" +else @unzip -q /tmp/glfw-$(VERSION).zip - @mv glfw-3.3.6 glfw - @echo "Building GLFW…" - @cd glfw && \ - cmake . -DGLFW_BUILD_TESTS=OFF -DGLFW_BUILD_EXAMPLES=OFF -DGLFW_BUILD_DOCS=OFF && \ - make + @mv glfw-$(VERSION) glfw +endif + @echo Building GLFW... + cmake -B glfw glfw -G "Unix Makefiles" $(patsubst %, -D%, $(DEFINES)) + make -C glfw From 7bc9fb26ac22bed66b185efbcc2e6ca03bc4bed0 Mon Sep 17 00:00:00 2001 From: Chance Snow Date: Mon, 26 Feb 2024 17:59:23 -0600 Subject: [PATCH 2/2] Fix example compilation --- examples/utils/dub.json | 2 +- examples/utils/source/examples/window.d | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/utils/dub.json b/examples/utils/dub.json index a02a636..fef3297 100644 --- a/examples/utils/dub.json +++ b/examples/utils/dub.json @@ -26,7 +26,7 @@ "libs-linux": [ "X11" ], - "libs-windows": ["glfw3", "gdi32"], + "libs-windows": ["glfw3", "gdi32", "opengl32", "msvcrt"], "lflags-posix": ["$UTILS_PACKAGE_DIR/subprojects/glfw/src/libglfw3.a"], "lflags-windows": ["/LIBPATH:$UTILS_PACKAGE_DIR/subprojects/glfw/src"] } diff --git a/examples/utils/source/examples/window.d b/examples/utils/source/examples/window.d index bc1bbe1..d8c97da 100644 --- a/examples/utils/source/examples/window.d +++ b/examples/utils/source/examples/window.d @@ -103,7 +103,7 @@ abstract class Window { ); version (Windows) { import core.sys.windows.windows : GetModuleHandleA; - surface = Surface.fromWindowsHwnd(instance, GetModuleHandleA(null), glfwGetWin32Window(window)); + surface = Surface.fromWindowsHwnd(this.gpu, GetModuleHandleA(null), glfwGetWin32Window(_window)); } assert(surface.valid, "Could not create native surface");