@@ -157,6 +157,7 @@ function(add_swift_compiler_modules_library name)
157157
158158 set (all_obj_files)
159159 set (all_module_targets)
160+ set (all_module_files)
160161 get_property (modules GLOBAL PROPERTY "swift_compiler_modules" )
161162 foreach (module ${modules} )
162163
@@ -180,7 +181,7 @@ function(add_swift_compiler_modules_library name)
180181
181182 set (module_obj_file "${build_dir} /${module} .o" )
182183 set (module_file "${build_dir} /${module} .swiftmodule" )
183- set_property ( TARGET ${module_target} PROPERTY "module_file" " ${module_file} " )
184+ list ( APPEND all_module_files ${module_file} )
184185
185186 set (all_obj_files ${all_obj_files} ${module_obj_file} )
186187 set (c_include_paths
@@ -231,6 +232,19 @@ function(add_swift_compiler_modules_library name)
231232 add_library (${name} STATIC ${all_obj_files} )
232233 add_dependencies (${name} ${all_module_targets} )
233234 set_target_properties (${name} PROPERTIES LINKER_LANGUAGE CXX)
235+
236+ # Downstream linking should include the swiftmodule in debug builds to allow lldb to
237+ # work correctly. Only do this on Darwin since neither gold (currently used by default
238+ # on Linux), nor the default Windows linker 'link' support '-add_ast_path'.
239+ is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE} " debuginfo)
240+ if (debuginfo AND SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
241+ set (public_link_flags)
242+ foreach (module_file ${all_module_files} )
243+ list (APPEND public_link_flags "SHELL:-Xlinker -add_ast_path -Xlinker ${module_file} " )
244+ endforeach ()
245+ target_link_options (${name} PUBLIC ${public_link_flags} )
246+ endif ()
247+
234248 set_property (GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name} )
235249endfunction ()
236250
0 commit comments