Skip to content

build: improve SourceKit handling of libdispatch #12098

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 2 commits into from
Oct 4, 2017
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
51 changes: 39 additions & 12 deletions tools/SourceKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,25 +98,52 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
CMAKE_ARGS
-DCMAKE_C_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang
-DCMAKE_CXX_COMPILER=${PATH_TO_CLANG_BUILD}/bin/clang++
-DCMAKE_SWIFT_COMPILER=$<TARGET_FILE:swift>c
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DENABLE_SWIFT=YES
BUILD_BYPRODUCTS
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX})

${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
STEP_TARGETS
configure)

# CMake does not like the addition of INTERFACE_INCLUDE_DIRECTORIES without
# the directory existing. Just create the location which will be populated
# during the installation.
ExternalProject_Get_Property(libdispatch install_dir)
file(MAKE_DIRECTORY ${install_dir}/include)

# TODO(compnerd) this should be taken care of by the
# INTERFACE_INCLUDE_DIRECTORIES below
include_directories(AFTER
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)
link_directories(${SWIFT_PATH_TO_LIBDISPATCH_BUILD})
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})
add_dependencies(libdispatch
swift
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftCore-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}
swiftSwiftOnoneSupport-swiftmodule-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})
endif()

include_directories(AFTER ${SWIFT_PATH_TO_LIBDISPATCH_SOURCE})

add_library(dispatch UNKNOWN IMPORTED)
ExternalProject_Get_Property(libdispatch install_dir)
add_library(dispatch SHARED IMPORTED)
set_target_properties(dispatch
PROPERTIES
IMPORTED_LOCATION ${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX})

add_library(swiftCore SHARED IMPORTED)
set_target_properties(swiftCore PROPERTIES
IMPORTED_LOCATION ${SOURCEKIT_BINARY_DIR}/lib/swift/linux/libswiftCore.so)
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/src/${CMAKE_SHARED_LIBRARY_PREFIX}dispatch${CMAKE_SHARED_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${install_dir}/include
IMPORTED_LINK_INTERFACE_LIBRARIES
swiftCore-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH})

add_library(BlocksRuntime STATIC IMPORTED)
set_target_properties(BlocksRuntime
PROPERTIES
IMPORTED_LOCATION
${SWIFT_PATH_TO_LIBDISPATCH_BUILD}/${CMAKE_STATIC_LIBRARY_PREFIX}BlocksRuntime${CMAKE_STATIC_LIBRARY_SUFFIX}
INTERFACE_INCLUDE_DIRECTORIES
${SWIFT_PATH_TO_LIBDISPATCH_SOURCE}/src/BlocksRuntime)

set(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH TRUE)
endif()
Expand Down
10 changes: 10 additions & 0 deletions tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ function(add_sourcekit_default_compiler_flags target)
RESULT_VAR_NAME link_flags)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
# TODO(compnerd) this should really use target_compile_options but the use
# of keyword and non-keyword flags prevents this
list(APPEND c_compile_flags "-fblocks")
# TODO(compnerd) this should really use target_link_libraries but the use of
# explicit_llvm_config using target_link_libraries without keywords on
# executables causes conflicts here
list(APPEND link_flags "-L${SWIFT_PATH_TO_LIBDISPATCH_BUILD}")
list(APPEND link_flags "-lBlocksRuntime")
# NOTE(compnerd) since we do not use target_link_libraries, we do not get
# the implicit dependency tracking. Add an explicit dependency until we can
# use target_link_libraries.
add_dependencies(${target} BlocksRuntime)
endif()

# Convert variables to space-separated strings.
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/complete-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()

if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch swiftCore)
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch)
endif()

add_sourcekit_executable(complete-test
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/sourcekitd-repl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ if(HAVE_UNICODE_LIBEDIT)
endif()

if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
set(SOURCEKITD_REPL_LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} dispatch swiftCore)
set(SOURCEKITD_REPL_LINK_LIBS ${SOURCEKITD_REPL_LINK_LIBS} dispatch)
endif()

add_sourcekit_executable(sourcekitd-repl
Expand Down
2 changes: 1 addition & 1 deletion tools/SourceKit/tools/sourcekitd-test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else()
endif()

if(SOURCEKIT_NEED_EXPLICIT_LIBDISPATCH)
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch swiftCore)
set(SOURCEKITD_TEST_LINK_LIBS ${SOURCEKITD_TEST_LINK_LIBS} dispatch)
endif()

add_sourcekit_executable(sourcekitd-test
Expand Down
4 changes: 0 additions & 4 deletions tools/SourceKit/tools/sourcekitd/bin/InProc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ if (SOURCEKITD_BUILD_STATIC_INPROC)
)
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
target_link_libraries(sourcekitdInProc PUBLIC BlocksRuntime)
endif()

if (SOURCEKIT_BUILT_STANDALONE)
# Create the symlinks necessary to find the swift runtime.
add_custom_command(TARGET sourcekitdInProc PRE_BUILD
Expand Down