From d86693158a973c3333d77dbca0500e8218b3818f Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 3 Aug 2024 10:40:00 -0400 Subject: [PATCH] Meta: Use dynamic vcpkg linkage for release builds By using static linkage, we are opening ourselves up to ODR violations that result in runtime crashes (rather than build-time link errors). For example, we've seen this happen while trying to use Skia context in both LibGfx and LibWeb. --- Meta/CMake/lagom_install_options.cmake | 12 +++++++++++- Meta/CMake/vcpkg/debug-triplets/debug.cmake | 2 +- Meta/CMake/vcpkg/release-triplets/release.cmake | 2 +- Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Meta/CMake/lagom_install_options.cmake b/Meta/CMake/lagom_install_options.cmake index ea0d526d92a..97f10d5b491 100644 --- a/Meta/CMake/lagom_install_options.cmake +++ b/Meta/CMake/lagom_install_options.cmake @@ -20,7 +20,17 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${IN_BUILD_PREFIX}${CMAK set(CMAKE_Swift_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/${IN_BUILD_PREFIX}swift") set(CMAKE_SKIP_BUILD_RPATH FALSE) -set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) + +if ("${VCPKG_INSTALLED_DIR}" STREQUAL "") + set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE) +else() + if (CMAKE_BUILD_TYPE MATCHES "Release|RelWithDebInfo") + set(CMAKE_BUILD_RPATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib") + else() + set(CMAKE_BUILD_RPATH "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/lib") + endif() +endif() + # See slide 100 of the following ppt :^) # https://crascit.com/wp-content/uploads/2019/09/Deep-CMake-For-Library-Authors-Craig-Scott-CppCon-2019.pdf if (APPLE) diff --git a/Meta/CMake/vcpkg/debug-triplets/debug.cmake b/Meta/CMake/vcpkg/debug-triplets/debug.cmake index 765215e7d3d..ef4097ea965 100644 --- a/Meta/CMake/vcpkg/debug-triplets/debug.cmake +++ b/Meta/CMake/vcpkg/debug-triplets/debug.cmake @@ -1,3 +1,3 @@ # Ideally, we would set VCPKG_BUILD_TYPE="debug", but that is currently not supported as a standalone build type. # See: https://github.com/microsoft/vcpkg/issues/38224 -set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) diff --git a/Meta/CMake/vcpkg/release-triplets/release.cmake b/Meta/CMake/vcpkg/release-triplets/release.cmake index d19538159a8..df4f65b89ed 100644 --- a/Meta/CMake/vcpkg/release-triplets/release.cmake +++ b/Meta/CMake/vcpkg/release-triplets/release.cmake @@ -1,2 +1,2 @@ set(VCPKG_BUILD_TYPE release) -set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) diff --git a/Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake b/Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake index 1eca4ceee3e..c8ad8738c4b 100644 --- a/Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake +++ b/Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake @@ -1,5 +1,5 @@ set(VCPKG_BUILD_TYPE release) -set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_LIBRARY_LINKAGE dynamic) set(VCPKG_C_FLAGS "") set(VCPKG_CXX_FLAGS "-frtti")