Skip to content

Commit

Permalink
buildscript: Fix dynamic Rust lib linking on MSVC debug builds
Browse files Browse the repository at this point in the history
This is a hacky fix that manually adds transitive dependencies
which aren't being picked up for some reason by MSVC in debug
configuration. This isn't ideal but I've been struggling (and
failing) to find a proper solution for about 2 weeks now.
  • Loading branch information
caseif committed Aug 10, 2024
1 parent 914de91 commit 67aa3b4
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmake/ConfigureModule.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,41 @@ function(_argus_configure_module MODULE_PROJECT_DIR ROOT_DIR
corrosion_link_libraries(${PROJECT_NAME} ${ARGUS_LIBRARY})
set(LIB_OUT_DIR "${CMAKE_BINARY_DIR}/${DYN_MODULE_PREFIX}")
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${DYN_MODULE_PREFIX}")

# for some reason transitive linker dependencies don't get applied
# correctly specifically in MSVC debug builds, so we manually add them
# as dependencies here via Corrosion
if(MSVC AND CMAKE_BUILD_TYPE STREQUAL "Debug")
set(seen_libs "")
set(dep_stack "${MODULE_LINKER_DEPS}")
while(NOT "${dep_stack}" STREQUAL "")
list(POP_FRONT dep_stack lib)
if("${lib}" STREQUAL "")
continue()
endif()

list(FIND seen_libs ${lib} seen_index)
if(NOT seen_index EQUAL -1)
continue()
endif()

list(APPEND seen_libs ${lib})

if(TARGET ${lib})
get_target_property(target_type ${lib} TYPE)
if(${target_type} STREQUAL "INTERFACE_LIBRARY")
get_target_property(lib_linker_libs ${lib} INTERFACE_LINK_LIBRARIES)
else()
get_target_property(lib_linker_libs ${lib} LINK_LIBRARIES)
endif()
if(NOT "${lib_linker_libs}" STREQUAL "lib_link_libs-NOTFOUND")
list(APPEND dep_stack ${lib_linker_libs})
endif()

corrosion_link_libraries(${PROJECT_NAME} ${lib})
endif()
endwhile()
endif()
else()
message(FATAL_ERROR "Only Rust projects are supported as external projects at this time")
endif()
Expand Down

0 comments on commit 67aa3b4

Please sign in to comment.