Skip to content

[cmake] Fix LLDB for ASTGen #70204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1387,9 +1387,6 @@ if(SWIFT_INCLUDE_TOOLS)

add_subdirectory(lib)

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

# Always include this after including stdlib/!
Expand Down
16 changes: 15 additions & 1 deletion SwiftCompilerSources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function(add_swift_compiler_modules_library name)

set(all_obj_files)
set(all_module_targets)
set(all_module_files)
get_property(modules GLOBAL PROPERTY "swift_compiler_modules")
foreach(module ${modules})

Expand All @@ -180,7 +181,7 @@ function(add_swift_compiler_modules_library name)

set(module_obj_file "${build_dir}/${module}.o")
set(module_file "${build_dir}/${module}.swiftmodule")
set_property(TARGET ${module_target} PROPERTY "module_file" "${module_file}")
list(APPEND all_module_files ${module_file})

set(all_obj_files ${all_obj_files} ${module_obj_file})
set(c_include_paths
Expand Down Expand Up @@ -231,6 +232,19 @@ function(add_swift_compiler_modules_library name)
add_library(${name} STATIC ${all_obj_files})
add_dependencies(${name} ${all_module_targets})
set_target_properties(${name} PROPERTIES LINKER_LANGUAGE CXX)

# Downstream linking should include the swiftmodule in debug builds to allow lldb to
# work correctly. Only do this on Darwin since neither gold (currently used by default
# on Linux), nor the default Windows linker 'link' support '-add_ast_path'.
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
if(debuginfo AND SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
set(public_link_flags)
foreach(module_file ${all_module_files})
list(APPEND public_link_flags "SHELL:-Xlinker -add_ast_path -Xlinker ${module_file}")
endforeach()
target_link_options(${name} PUBLIC ${public_link_flags})
endif()

set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
endfunction()

Expand Down
14 changes: 14 additions & 0 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ function(add_pure_swift_host_library name)
-emit-module-source-info-path;${module_sourceinfo_file};
-emit-module-interface-path;${module_interface_file}
>)
else()
# Emit a swiftmodule in the current directory.
set_target_properties(${name} PROPERTIES
Swift_MODULE_NAME ${name}
Swift_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set(module_file "${CMAKE_CURRENT_BINARY_DIR}/${name}.swiftmodule")
endif()

# Downstream linking should include the swiftmodule in debug builds to allow lldb to
# work correctly. Only do this on Darwin since neither gold (currently used by default
# on Linux), nor the default Windows linker 'link' support '-add_ast_path'.
is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" debuginfo)
if(debuginfo AND SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
target_link_options(${name} PUBLIC "SHELL:-Xlinker -add_ast_path -Xlinker ${module_file}")
endif()

if(LLVM_USE_LINKER)
Expand Down
12 changes: 0 additions & 12 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -522,18 +522,6 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
endif()

# Workaround to make lldb happy: we have to explicitly add all swift compiler modules
# to the linker command line.
set(swift_ast_path_flags " -Wl")
get_property(modules GLOBAL PROPERTY swift_compiler_modules)
foreach(module ${modules})
get_target_property(module_file "SwiftModule${module}" "module_file")
string(APPEND swift_ast_path_flags ",-add_ast_path,${module_file}")
endforeach()

set_property(TARGET ${target} APPEND_STRING PROPERTY
LINK_FLAGS ${swift_ast_path_flags})

# Workaround for a linker crash related to autolinking: rdar://77839981
set_property(TARGET ${target} APPEND_STRING PROPERTY
LINK_FLAGS " -lobjc ")
Expand Down
12 changes: 0 additions & 12 deletions tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,6 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
message(FATAL_ERROR "Unknown ASKD_BOOTSTRAPPING_MODE '${ASKD_BOOTSTRAPPING_MODE}'")
endif()

# Workaround to make lldb happy: we have to explicitly add all swift compiler modules
# to the linker command line.
set(swift_ast_path_flags "-Wl")
get_property(modules GLOBAL PROPERTY swift_compiler_modules)
foreach(module ${modules})
get_target_property(module_file "SwiftModule${module}" "module_file")
string(APPEND swift_ast_path_flags ",-add_ast_path,${module_file}")
endforeach()

set_property(TARGET ${target} APPEND_STRING PROPERTY
LINK_FLAGS " ${swift_ast_path_flags} ")

# Workaround for a linker crash related to autolinking: rdar://77839981
set_property(TARGET ${target} APPEND_STRING PROPERTY
LINK_FLAGS " -lobjc ")
Expand Down