From 613bfe0b8b4e1c81571415ab783feceaa6209602 Mon Sep 17 00:00:00 2001 From: Antonio Ospite Date: Tue, 27 May 2025 18:51:12 +0200 Subject: [PATCH] device-select: fix build errors on some stricter build configurations After commit 45eb3bfd328 (device-select: only try wayland/x11 if the required vars are set, 2024-10-18), building `device_select_layer.c` can results in compiler errors on some stricter build configurations (-Werror,-Wunused-variable): ----------------------------------------------------------------------- ../src/vulkan/device-select-layer/device_select_layer.c:149:9: error: unused variable 'has_wayland' [-Werror,-Wunused-variable] 149 | bool has_wayland = getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"); | ^~~~~~~~~~~ ../src/vulkan/device-select-layer/device_select_layer.c:150:9: error: unused variable 'has_xcb' [-Werror,-Wunused-variable] 150 | bool has_xcb = !!getenv("DISPLAY"); | ^~~~~~~ 2 errors generated. ----------------------------------------------------------------------- So guard the declarations of the `has_wayland` and `has_xcb` variables behind `VK_USE_PLATFORM_WAYLAND_KHR` and `VK_USE_PLATFORM_XCB_KHR` respectively, just like the user code. Note: the declarations are still kept outside of the loop body, in order to assign the variables once and for all. Reviewed-by: Yiwei Zhang Part-of: --- src/vulkan/device-select-layer/device_select_layer.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vulkan/device-select-layer/device_select_layer.c b/src/vulkan/device-select-layer/device_select_layer.c index 13fd9daae24..03c71631ee0 100644 --- a/src/vulkan/device-select-layer/device_select_layer.c +++ b/src/vulkan/device-select-layer/device_select_layer.c @@ -127,8 +127,12 @@ device_select_CreateInstance(const VkInstanceCreateInfo *pCreateInfo, info->xwayland = !strcmp(applicationName, "Xwayland"); info->xserver = !strcmp(applicationName, "Xorg") || !strcmp(applicationName, "Xephyr"); +#ifdef VK_USE_PLATFORM_WAYLAND_KHR bool has_wayland = getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET"); +#endif +#ifdef VK_USE_PLATFORM_XCB_KHR bool has_xcb = !!getenv("DISPLAY"); +#endif for (unsigned i = 0; i < pCreateInfo->enabledExtensionCount; i++) { #ifdef VK_USE_PLATFORM_WAYLAND_KHR