Skip to content

Commit

Permalink
contrib: vulkan-loader: fix libunwind usage when static linking
Browse files Browse the repository at this point in the history
It ends up with
- set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "atomic;m;-l:libunwind.a;dl;c;-l:libunwind.a;dl")
- set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "windowsapp;windowsapp;ucrt;windowsapp;ucrtapp;c++;mingw32;-l:libunwind.a;moldname;mingwex;mingw32;-l:libunwind.a;moldname;mingwex")
  • Loading branch information
robUx4 committed Oct 19, 2024
1 parent c13b280 commit 8d83dc7
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From ce897781c15a650f59b0c2ffa7dced738b34fa60 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <[email protected]>
Date: Thu, 17 Oct 2024 11:56:18 +0200
Subject: [PATCH 3/3] fix libunwind usage when static linking

It ends up with
- set(CMAKE_C_IMPLICIT_LINK_LIBRARIES "atomic;m;-l:libunwind.a;dl;c;-l:libunwind.a;dl")
- set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "windowsapp;windowsapp;ucrt;windowsapp;ucrtapp;c++;mingw32;-l:libunwind.a;moldname;mingwex;mingw32;-l:libunwind.a;moldname;mingwex")
---
loader/CMakeLists.txt | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index 98da79ab8..93ab25f06 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -335,7 +335,13 @@ include(FindPkgConfig QUIET)
if(PKG_CONFIG_FOUND)
set(VK_API_VERSION "${LOADER_GENERATED_HEADER_VERSION}")
foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
- set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
+ if (IS_ABSOLUTE ${LIB} AND EXISTS ${LIB})
+ set(PRIVATE_LIBS "${PRIVATE_LIBS} ${LIB}")
+ elseif(${LIB} MATCHES "-l:libunwind.a") # android toolchain
+ set(PRIVATE_LIBS "${PRIVATE_LIBS} -lunwind")
+ else()
+ set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
+ endif()
endforeach()
if(MSVC)
set(VULKAN_LIB_SUFFIX "-1")
--
2.45.0.windows.1

27 changes: 20 additions & 7 deletions contrib/src/vulkan-loader/002-proper-def-files-for-32bit.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
From 56ce783d2cad375cb29f19be43b5dda7061ded3c Mon Sep 17 00:00:00 2001
From: Alexey Pavlov <[email protected]>
Date: Fri, 8 Nov 2019 07:40:41 +0100
Subject: [PATCH 1/3] proper def files for 32bit

---
loader/CMakeLists.txt | 15 +++++++++++++--
loader/vk_loader_platform.h | 8 +++++++-
loader/vulkan-1.def | 2 +-
3 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index 8bb10fd..fc38ecc 100644
index d1606f549..0552c5bdd 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -127,7 +127,7 @@ set(ASM_FAILURE_MSG "${ASM_FAILURE_MSG}Note that this may be unsafe, as the C co
Expand Down Expand Up @@ -35,35 +46,34 @@ index 8bb10fd..fc38ecc 100644
endif()
elseif(APPLE)
# For MacOS, use the C code and force the compiler's tail-call optimization instead of using assembly code.
@@ -261,6 +263,7 @@ endif()
@@ -217,6 +219,7 @@ endif()

if(WIN32)
add_library(loader-opt STATIC ${OPT_LOADER_SRCS})
+ set_target_properties(loader-opt PROPERTIES DEFINE_SYMBOL "VK_BUILDING_DLL")
target_link_libraries(loader-opt PUBLIC loader_specific_options)
add_dependencies(loader-opt loader_asm_gen_files)
set_target_properties(loader-opt PROPERTIES CMAKE_C_FLAGS_DEBUG "${MODIFIED_C_FLAGS_DEBUG}")
@@ -237,10 +240,17 @@ if(WIN32)
@@ -237,9 +240,17 @@ if(WIN32)
# when adding the suffix the import and runtime library names must be consistent
# mingw: libvulkan-1.dll.a / libvulkan-1.dll
# msvc: vulkan-1.lib / vulkan-1.dll
+ if(MSVC)
set_target_properties(vulkan
PROPERTIES
OUTPUT_NAME vulkan-1)
-
+ else()
+ set_target_properties(vulkan
+ PROPERTIES
+ LIBRARY_OUTPUT_NAME vulkan
+ RUNTIME_OUTPUT_NAME vulkan-1
+ ARCHIVE_OUTPUT_NAME vulkan)
+ endif()

if(MSVC AND ENABLE_WIN10_ONECORE)
target_link_libraries(vulkan OneCoreUAP.lib LIBCMT.LIB LIBCMTD.LIB LIBVCRUNTIME.LIB LIBUCRT.LIB)
set_target_properties(vulkan PROPERTIES LINK_FLAGS "/NODEFAULTLIB")
diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h
index 507a901..6b8fc48 100644
index 594a24986..6bbe6798b 100644
--- a/loader/vk_loader_platform.h
+++ b/loader/vk_loader_platform.h
@@ -77,7 +77,13 @@
Expand All @@ -82,7 +92,7 @@ index 507a901..6b8fc48 100644
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
#define LOADER_EXPORT __attribute__((visibility("default")))
diff --git a/loader/vulkan-1.def b/loader/vulkan-1.def
index 6a88b55..1d26b1f 100644
index f1aab7880..0b8a68ff8 100644
--- a/loader/vulkan-1.def
+++ b/loader/vulkan-1.def
@@ -22,7 +22,7 @@
Expand All @@ -94,3 +104,6 @@ index 6a88b55..1d26b1f 100644
EXPORTS
vkCreateInstance
vkDestroyInstance
--
2.45.0.windows.1

16 changes: 15 additions & 1 deletion contrib/src/vulkan-loader/004-disable-suffix-in-static-lib.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
From e9e54996189115fd4868cc7be55e2390419e0c57 Mon Sep 17 00:00:00 2001
From: Biswapriyo Nath <[email protected]>
Date: Sat, 22 Jan 2022 09:51:26 +0100
Subject: [PATCH 2/3] disable suffix in static lib

---
loader/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/loader/CMakeLists.txt b/loader/CMakeLists.txt
index 0552c5bdd..98da79ab8 100644
--- a/loader/CMakeLists.txt
+++ b/loader/CMakeLists.txt
@@ -398,7 +398,7 @@
@@ -337,7 +337,7 @@ if(PKG_CONFIG_FOUND)
foreach(LIB ${CMAKE_CXX_IMPLICIT_LINK_LIBRARIES} ${PLATFORM_LIBS})
set(PRIVATE_LIBS "${PRIVATE_LIBS} -l${LIB}")
endforeach()
Expand All @@ -9,3 +20,6 @@
set(VULKAN_LIB_SUFFIX "-1")
# Set libdir path as in cmake's FindVulkan.cmake
# https://github.com/KhronosGroup/Vulkan-Loader/issues/668
--
2.45.0.windows.1

1 change: 1 addition & 0 deletions contrib/src/vulkan-loader/rules.mak
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ vulkan-loader: Vulkan-Loader-$(VULKAN_LOADER_VERSION).tar.gz .sum-vulkan-loader
# https://github.com/msys2/MINGW-packages/tree/master/mingw-w64-vulkan-loader
$(APPLY) $(SRC)/vulkan-loader/002-proper-def-files-for-32bit.patch
$(APPLY) $(SRC)/vulkan-loader/004-disable-suffix-in-static-lib.patch
$(APPLY) $(SRC)/vulkan-loader/0003-fix-libunwind-usage-when-static-linking.patch
ifeq ($(HOST),i686-w64-mingw32)
cp -v $(SRC)/vulkan-loader/libvulkan-32.def $(UNPACK_DIR)/loader/vulkan-1.def
endif
Expand Down

0 comments on commit 8d83dc7

Please sign in to comment.