Skip to content

Commit bc21d4f

Browse files
committed
build: move the RPATH handling to the executables
This moves the handling of the RPATH and the exported symbol to the binary themselves. The exported symbol is needed due to the use of the exported symbol list. This makes the small difference that `_main` is always exported on Darwin which is not strictly needed in ASAN as ASAN provides the entry point. The RPATH is only setup on installation which is sufficient for testing purposes as CMake ensures that the libraries are fully linked and will be loaded properly when run from the build tree.
1 parent 0c5f1ee commit bc21d4f

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,6 @@ macro(add_sourcekit_executable name)
245245
target_link_libraries(${name} PRIVATE ${LLVM_COMMON_LIBS})
246246

247247
set_target_properties(${name} PROPERTIES FOLDER "SourceKit executables")
248-
if (NOT SWIFT_ASAN_BUILD)
249-
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
250-
set_target_properties(${name}
251-
PROPERTIES
252-
LINK_FLAGS "-Wl,-exported_symbol,_main")
253-
endif()
254-
if(SWIFT_ANALYZE_CODE_COVERAGE)
255-
set_property(TARGET "${name}" APPEND_STRING PROPERTY
256-
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
257-
endif()
258-
endif()
259248
add_sourcekit_default_compiler_flags("${name}")
260249
endmacro()
261250

tools/SourceKit/tools/complete-test/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,17 @@ if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
1313
BlocksRuntime)
1414
endif()
1515

16-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
17-
set_target_properties(complete-test
18-
PROPERTIES
19-
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
16+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
17+
set_target_properties(complete-test PROPERTIES
18+
INSTALL_RPATH "@executable_path/../lib")
19+
target_link_options(complete-test PRIVATE
20+
"LINKER:-exported_symbol,_main")
2021
endif()
21-
2222
if(SWIFT_ANALYZE_CODE_COVERAGE)
2323
set_property(TARGET complete-test APPEND_STRING PROPERTY
2424
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
2525
endif()
2626

2727
add_dependencies(tools complete-test)
2828
swift_install_in_component(TARGETS complete-test
29-
RUNTIME
30-
DESTINATION bin
31-
COMPONENT tools)
29+
RUNTIME DESTINATION bin COMPONENT tools)

tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ target_include_directories(sourcekitd-repl PRIVATE
1717
target_link_libraries(sourcekitd-repl PRIVATE
1818
${LibEdit_LIBRARIES})
1919

20-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
21-
set_target_properties(sourcekitd-repl
22-
PROPERTIES
23-
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
20+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
21+
set_target_properties(sourcekitd-repl PROPERTIES
22+
INSTALL_RPATH "@executable_path/../lib")
23+
target_link_options(sourcekitd-repl PRIVATE
24+
"LINKER:-exported_symbol,_main")
2425
endif()
2526
if(SWIFT_ANALYZE_CODE_COVERAGE)
2627
set_property(TARGET sourcekitd-repl APPEND_STRING PROPERTY
@@ -29,6 +30,4 @@ endif()
2930

3031
add_dependencies(tools sourcekitd-repl)
3132
swift_install_in_component(TARGETS sourcekitd-repl
32-
RUNTIME
33-
DESTINATION bin
34-
COMPONENT tools)
33+
RUNTIME DESTINATION bin COMPONENT tools)

tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,17 @@ endif()
2525

2626
add_dependencies(sourcekitd-test sourcekitdTestOptionsTableGen)
2727

28-
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
29-
set_target_properties(sourcekitd-test
30-
PROPERTIES
31-
LINK_FLAGS "-Wl,-rpath -Wl,@executable_path/../lib")
28+
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
29+
set_target_properties(sourcekitd-test PROPERTIES
30+
INSTALL_RPATH "@executable_path/../lib")
31+
target_link_options(sourcekitd-test PRIVATE
32+
"LINKER:-exported_symbol,_main")
3233
endif()
33-
3434
if(SWIFT_ANALYZE_CODE_COVERAGE)
3535
set_property(TARGET sourcekitd-test APPEND_STRING PROPERTY
3636
LINK_FLAGS " -fprofile-instr-generate -fcoverage-mapping")
3737
endif()
3838

3939
add_dependencies(tools sourcekitd-test)
4040
swift_install_in_component(TARGETS sourcekitd-test
41-
RUNTIME
42-
DESTINATION bin
43-
COMPONENT tools)
41+
RUNTIME DESTINATION bin COMPONENT tools)

0 commit comments

Comments
 (0)