-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CMake] Support Macros in Linux #68082
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
Changes from all commits
9c9010e
2a2787b
0f0c492
9017ef5
914a6fd
602604b
757aaa3
319b8bd
4ccc866
dc68773
f645069
0aa0aac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,32 @@ add_custom_target(SwiftUnitTests) | |
|
||
set_target_properties(SwiftUnitTests PROPERTIES FOLDER "Tests") | ||
|
||
# Add a new Swift unit test executable. | ||
# | ||
# Usage: | ||
# add_swift_unittest(name | ||
# [IS_TARGET_TEST] | ||
# source1 [source2 source3 ...]) | ||
# | ||
# name | ||
# Name of the test (e.g., SwiftASTTest). | ||
# | ||
# IS_TARGET_TEST | ||
# Indicates this is a test for target libraries. Not host library. | ||
# This avoids linking with toolchains stdlib. | ||
# | ||
# source1 ... | ||
# Sources to add into this executable. | ||
function(add_swift_unittest test_dirname) | ||
cmake_parse_arguments(ASU | ||
"IS_TARGET_TEST" | ||
"" | ||
"" | ||
${ARGN}) | ||
|
||
# *NOTE* Even though "add_unittest" does not have llvm in its name, it is a | ||
# function defined by AddLLVM.cmake. | ||
add_unittest(SwiftUnitTests ${test_dirname} ${ARGN}) | ||
add_unittest(SwiftUnitTests ${test_dirname} ${ASU_UNPARSED_ARGUMENTS}) | ||
|
||
set_target_properties(${test_dirname} PROPERTIES LINKER_LANGUAGE CXX) | ||
|
||
|
@@ -89,7 +111,8 @@ function(add_swift_unittest test_dirname) | |
endif() | ||
endif() | ||
|
||
if (SWIFT_SWIFT_PARSER) | ||
if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST) | ||
# Link to stdlib the compiler uses. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. |
||
_add_swift_runtime_link_flags(${test_dirname} "../../lib" "") | ||
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF) | ||
endif() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
set(SWIFT_SET_RPATH_SCRIPT_FILE "${CMAKE_CURRENT_LIST_FILE}") | ||
|
||
function(swift_get_set_rpath_script_file out_var) | ||
set(${out_var} "${SWIFT_SET_RPATH_SCRIPT_FILE}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
# Actual RPATH_CHANGE operation to the file. | ||
function(_swift_set_rpath_impl file new_rpath) | ||
# FIXME: Handle non-ELF files. We can't use RPATH_SET because it's only available CMake 3.21.0 | ||
execute_process( | ||
COMMAND readelf -Wd "${file}" | ||
COMMAND grep -Po "R(UN)?PATH.*\\[\\K[^\\]]*" | ||
OUTPUT_VARIABLE current_rpath | ||
) | ||
string(STRIP "${current_rpath}" current_rpath) | ||
|
||
# NOTE: RPATH_CHANGE is not documented, and works only for ELF and XCOFF. | ||
file(RPATH_CHANGE FILE "${file}" OLD_RPATH "${current_rpath}" NEW_RPATH "${new_rpath}") | ||
endfunction() | ||
|
||
# For 'cmake -P <scirpt>'. | ||
if (SWIFT_SET_RPATH_FILE AND SWIFT_SET_RPATH_NEW_RPATH) | ||
_swift_set_rpath_impl("${SWIFT_SET_RPATH_FILE}" "${SWIFT_SET_RPATH_NEW_RPATH}") | ||
endif() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ function(swift_supports_implicit_module module_name out_var) | |
"${CMAKE_Swift_COMPILER}" | ||
-Xfrontend -disable-implicit-${module_name}-module-import | ||
-Xfrontend -parse-stdlib | ||
-c - -o /dev/null | ||
-parse - | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linux |
||
INPUT_FILE | ||
"${CMAKE_BINARY_DIR}/tmp/empty-check-${module_name}.swift" | ||
OUTPUT_QUIET ERROR_QUIET | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ if (SWIFT_SWIFT_PARSER) | |
list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "SwiftSyntax::" | ||
OUTPUT_VARIABLE SWIFT_SYNTAX_TARGETS) | ||
|
||
set(SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR | ||
set(SWIFT_SYNTAX_LIBRARIES_BUILD_DIR | ||
"${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host") | ||
Comment on lines
-36
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really meant to be a "build" directory where earlyswiftsyntax's |
||
set(SWIFT_HOST_LIBRARIES_DEST_DIR | ||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") | ||
|
@@ -53,17 +53,35 @@ if (SWIFT_SWIFT_PARSER) | |
# Copy over all of the shared libraries from earlyswiftsyntax so they can | ||
# be found via RPATH. | ||
foreach (sharedlib ${SWIFT_SYNTAX_SHARED_LIBRARIES}) | ||
set(add_origin_rpath) | ||
if(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX") | ||
# At runtime, use swiftCore in the current toolchain. | ||
swift_get_set_rpath_script_file(setrpath_command) | ||
set(add_origin_rpath COMMAND ${CMAKE_COMMAND} | ||
"-DSWIFT_SET_RPATH_FILE=${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" | ||
"-DSWIFT_SET_RPATH_NEW_RPATH='$$ORIGIN:$$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}'" | ||
-P "${setrpath_command}" | ||
) | ||
endif() | ||
|
||
add_custom_command( | ||
OUTPUT "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" | ||
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${sharedlib}" | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib} | ||
DEPENDS "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib}" | ||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${sharedlib} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib} | ||
${add_origin_rpath} | ||
) | ||
|
||
add_custom_target(copy_swiftSyntaxLibrary_${sharedlib} | ||
DEPENDS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" | ||
COMMENT "Copying ${sharedlib}" | ||
) | ||
|
||
swift_install_in_component( | ||
PROGRAMS "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${sharedlib}" | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" | ||
COMPONENT compiler | ||
) | ||
|
||
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib}) | ||
endforeach() | ||
|
||
|
@@ -76,7 +94,7 @@ if (SWIFT_SWIFT_PARSER) | |
foreach(module_dir ${SWIFT_SYNTAX_MODULE_DIRS}) | ||
# Find all of the source module files. | ||
file(GLOB module_files | ||
"${SWIFT_SYNTAX_LIBRARIES_SOURCE_DIR}/${module_dir}/*.swiftinterface") | ||
"${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${module_dir}/*.swiftinterface") | ||
|
||
# Determine the destination module files. | ||
set(dest_module_files) | ||
|
@@ -98,6 +116,12 @@ if (SWIFT_SWIFT_PARSER) | |
COMMENT "Copying ${module_dir}" | ||
) | ||
|
||
swift_install_in_component( | ||
FILES ${dest_module_files} | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/${module_dir}" | ||
COMPONENT compiler | ||
) | ||
|
||
add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxModule_${module_dir}) | ||
endforeach() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,19 @@ function(add_swift_macro_library name) | |
# Add the library. | ||
add_pure_swift_host_library(${name} SHARED ${ASML_SOURCES}) | ||
|
||
# Add rpath to 'lib/{platform}' | ||
file(RELATIVE_PATH relpath_to_lib | ||
"${SWIFT_HOST_PLUGINS_DEST_DIR}" | ||
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" | ||
) | ||
_set_pure_swift_link_flags(${name} "${relpath_to_lib}") | ||
|
||
# Add rpath to 'lib/host' | ||
if(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX") | ||
set_property(TARGET ${name} | ||
APPEND PROPERTY INSTALL_RPATH "$ORIGIN/..") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linux's |
||
endif() | ||
|
||
# If we don't have the Swift swift parser, bail out, because the above | ||
# add_pure_swift_host_library did nothing. | ||
if (NOT SWIFT_SWIFT_PARSER) | ||
|
@@ -44,12 +57,14 @@ function(add_swift_macro_library name) | |
LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_PLUGINS_DEST_DIR}" | ||
) | ||
|
||
set(destination_dir "lib${LLVM_LIBDIR_SUFFIX}/swift/host/plugins") | ||
|
||
swift_install_in_component(TARGETS ${name} | ||
LIBRARY | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/plugins" | ||
DESTINATION "${destination_dir}" | ||
COMPONENT compiler | ||
ARCHIVE | ||
DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/plugins" | ||
DESTINATION "${destination_dir}" | ||
COMPONENT compiler) | ||
|
||
# Export this macro plugin target. | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid mtime of
HeaderDependencies.cpp
being updated every timecmake
configuration happens.