Skip to content

Commit

Permalink
Meta: Use dynamic vcpkg linkage for release builds
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
trflynn89 committed Oct 28, 2024
1 parent 17eda3a commit 458676e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
12 changes: 11 additions & 1 deletion Meta/CMake/lagom_install_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Meta/CMake/vcpkg/debug-triplets/debug.cmake
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion Meta/CMake/vcpkg/release-triplets/release.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
set(VCPKG_BUILD_TYPE release)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE dynamic)
2 changes: 1 addition & 1 deletion Meta/CMake/vcpkg/sanitizer-triplets/sanitizer.cmake
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 458676e

Please sign in to comment.