Skip to content

Commit 73c6dcb

Browse files
committed
[cmake] Fix LLDB for ASTGen
Add the swiftmodule paths for ASTGen via `-add_ast_path` to the public linker flags such that downstream linking picks them up, allowing LLDB to load them when debugging. Also switch SwiftCompilerModules to using public linker flags instead of adding the linker flags in `_add_swift_runtime_link_flags`.
1 parent 55032ea commit 73c6dcb

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,9 +1387,6 @@ if(SWIFT_INCLUDE_TOOLS)
13871387

13881388
add_subdirectory(lib)
13891389

1390-
# SwiftCompilerSources must come before "tools".
1391-
# It adds swift module names to the global property "swift_compiler_modules"
1392-
# which is used in add_swift_host_tool for the lldb workaround.
13931390
add_subdirectory(SwiftCompilerSources)
13941391

13951392
# Always include this after including stdlib/!

SwiftCompilerSources/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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})
235249
endfunction()
236250

cmake/modules/AddPureSwift.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,20 @@ function(add_pure_swift_host_library name)
229229
-emit-module-source-info-path;${module_sourceinfo_file};
230230
-emit-module-interface-path;${module_interface_file}
231231
>)
232+
else()
233+
# Emit a swiftmodule in the current directory.
234+
set_target_properties(${name} PROPERTIES
235+
Swift_MODULE_NAME ${name}
236+
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
237+
set(module_file "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule")
238+
endif()
239+
240+
# Downstream linking should include the swiftmodule in debug builds to allow lldb to
241+
# work correctly. Only do this on Darwin since neither gold (currently used by default
242+
# on Linux), nor the default Windows linker 'link' support '-add_ast_path'.
243+
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
244+
if(debuginfo AND SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
245+
target_link_options(${name} PUBLIC "SHELL:-Xlinker -add_ast_path -Xlinker ${module_file}")
232246
endif()
233247

234248
if(LLVM_USE_LINKER)

cmake/modules/AddSwift.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,18 +522,6 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
522522
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
523523
endif()
524524
525-
# Workaround to make lldb happy: we have to explicitly add all swift compiler modules
526-
# to the linker command line.
527-
set(swift_ast_path_flags " -Wl")
528-
get_property(modules GLOBAL PROPERTY swift_compiler_modules)
529-
foreach(module ${modules})
530-
get_target_property(module_file "SwiftModule${module}" "module_file")
531-
string(APPEND swift_ast_path_flags ",-add_ast_path,${module_file}")
532-
endforeach()
533-
534-
set_property(TARGET ${target} APPEND_STRING PROPERTY
535-
LINK_FLAGS ${swift_ast_path_flags})
536-
537525
# Workaround for a linker crash related to autolinking: rdar://77839981
538526
set_property(TARGET ${target} APPEND_STRING PROPERTY
539527
LINK_FLAGS " -lobjc ")

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,6 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
9898
message(FATAL_ERROR "Unknown ASKD_BOOTSTRAPPING_MODE '${ASKD_BOOTSTRAPPING_MODE}'")
9999
endif()
100100

101-
# Workaround to make lldb happy: we have to explicitly add all swift compiler modules
102-
# to the linker command line.
103-
set(swift_ast_path_flags "-Wl")
104-
get_property(modules GLOBAL PROPERTY swift_compiler_modules)
105-
foreach(module ${modules})
106-
get_target_property(module_file "SwiftModule${module}" "module_file")
107-
string(APPEND swift_ast_path_flags ",-add_ast_path,${module_file}")
108-
endforeach()
109-
110-
set_property(TARGET ${target} APPEND_STRING PROPERTY
111-
LINK_FLAGS " ${swift_ast_path_flags} ")
112-
113101
# Workaround for a linker crash related to autolinking: rdar://77839981
114102
set_property(TARGET ${target} APPEND_STRING PROPERTY
115103
LINK_FLAGS " -lobjc ")

0 commit comments

Comments
 (0)