From 58c259fcd5dcf74c4040cc37d1b4e3466af4cd21 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 27 Jan 2020 13:43:09 -0800 Subject: [PATCH 1/2] build: simplify the ICU include handling This simplifies the ICU flags handling. This inlines the use into just the library case, as the ICU usage is for the standard library targets only. It uses CMake to properly add the include paths as a system search path. This should fix the Linux builds as the include flags were being de-duplicated as we are now using CMake more than we were previously. --- cmake/modules/AddSwift.cmake | 27 +++------------------------ 1 file changed, 3 insertions(+), 24 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 19e78d5b8ceb..a7fd32aa63f1 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -373,30 +373,6 @@ function(_add_variant_c_compile_flags) endforeach() endif() - set(ICU_UC_INCLUDE_DIR ${SWIFT_${CFLAGS_SDK}_${CFLAGS_ARCH}_ICU_UC_INCLUDE}) - if(NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "" AND - NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/include" AND - NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_TRIPLE}/include" AND - NOT "${ICU_UC_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_TRIPLE}/include") - if(SWIFT_COMPILER_IS_MSVC_LIKE) - list(APPEND result -I;${ICU_UC_INCLUDE_DIR}) - else() - list(APPEND result -isystem;${ICU_UC_INCLUDE_DIR}) - endif() - endif() - - set(ICU_I18N_INCLUDE_DIR ${SWIFT_${CFLAGS_SDK}_${CFLAGS_ARCH}_ICU_I18N_INCLUDE}) - if(NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "" AND - NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/include" AND - NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${CFLAGS_SDK}_ARCH_${CFLAGS_ARCH}_TRIPLE}/include" AND - NOT "${ICU_I18N_INCLUDE_DIR}" STREQUAL "/usr/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_TRIPLE}/include") - if(SWIFT_COMPILER_IS_MSVC_LIKE) - list(APPEND result -I;${ICU_I18N_INCLUDE_DIR}) - else() - list(APPEND result -isystem;${ICU_I18N_INCLUDE_DIR}) - endif() - endif() - set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE) endfunction() @@ -1447,6 +1423,9 @@ function(_add_swift_library_single target name) endif() # Set compilation and link flags. + target_include_directories(${target} SYSTEM PRIVATE + ${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_UC_INCLUDE} + ${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_I18N_INCLUDE}) target_compile_options(${target} PRIVATE ${c_compile_flags}) target_link_options(${target} PRIVATE From c11443c6632282018b6d4cfd7eb6829889eaf94d Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 27 Jan 2020 15:04:16 -0800 Subject: [PATCH 2/2] build: repair the Windows build This should repair the Windows build after #29451. The quoting behaviour was incorrect and was constructing an invalid compiler invocation. Solve the issue by using `target_include_directories` instead. However, since this needs the target, hoist the flag computation to the local sites. This replicates more logic because of the custom build trying to replicate the CMake build logic in CMake. --- cmake/modules/AddSwift.cmake | 59 ++++++++++++------- cmake/modules/SwiftWindowsSupport.cmake | 8 +-- .../cmake/modules/AddSwiftSourceKit.cmake | 6 ++ 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index a7fd32aa63f1..99d4009fd3eb 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -264,18 +264,6 @@ function(_add_variant_c_compile_flags) endif() if("${CFLAGS_SDK}" STREQUAL "WINDOWS") - # MSVC doesn't support -Xclang. We don't need to manually specify - # the dependent libraries as `cl` does so. - if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") - list(APPEND result -Xclang;--dependent-lib=oldnames) - # TODO(compnerd) handle /MT, /MTd - if("${CFLAGS_BUILD_TYPE}" STREQUAL "Debug") - list(APPEND result -Xclang;--dependent-lib=msvcrtd) - else() - list(APPEND result -Xclang;--dependent-lib=msvcrt) - endif() - endif() - # MSVC/clang-cl don't support -fno-pic or -fms-compatibility-version. if(NOT SWIFT_COMPILER_IS_MSVC_LIKE) list(APPEND result -fno-pic) @@ -366,11 +354,6 @@ function(_add_variant_c_compile_flags) list(APPEND result -isystem;${path}) endforeach() list(APPEND result "-D__ANDROID_API__=${SWIFT_ANDROID_API_LEVEL}") - elseif(CFLAGS_SDK STREQUAL WINDOWS) - swift_windows_include_for_arch(${CFLAGS_ARCH} ${CFLAGS_ARCH}_INCLUDE) - foreach(path ${${CFLAGS_ARCH}_INCLUDE}) - list(APPEND result "\"${CMAKE_INCLUDE_FLAG_C}${path}\"") - endforeach() endif() set("${CFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE) @@ -921,11 +904,9 @@ function(_add_swift_library_single target name) if("${SWIFTLIB_SINGLE_SDK}" STREQUAL "WINDOWS") if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") - swift_windows_generate_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS) - foreach(flag ${SWIFTLIB_SINGLE_VFS_OVERLAY_FLAGS}) - list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS -Xcc;${flag}) - list(APPEND SWIFTLIB_SINGLE_C_COMPILE_FLAGS ${flag}) - endforeach() + swift_windows_get_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY) + list(APPEND SWIFTLIB_SINGLE_SWIFT_COMPILE_FLAGS + -Xcc;-Xclang;-Xcc;-ivfsoverlay;-Xcc;-Xclang;-Xcc;${SWIFTLIB_SINGLE_VFS_OVERLAY}) endif() swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} SWIFTLIB_INCLUDE) foreach(directory ${SWIFTLIB_INCLUDE}) @@ -1423,6 +1404,25 @@ function(_add_swift_library_single target name) endif() # Set compilation and link flags. + if(SWIFTLIB_SINGLE_SDK STREQUAL WINDOWS) + swift_windows_include_for_arch(${SWIFTLIB_SINGLE_ARCHITECTURE} + ${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE) + target_include_directories(${target} SYSTEM PRIVATE + ${${SWIFTLIB_SINGLE_ARCHITECTURE}_INCLUDE}) + + if(NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC) + swift_windows_get_sdk_vfs_overlay(SWIFTLIB_SINGLE_VFS_OVERLAY) + target_compile_options(${target} PRIVATE + "SHELL:-Xclang -ivfsoverlay -Xclang ${SWIFTLIB_SINGLE_VFS_OVERLAY}") + + # MSVC doesn't support -Xclang. We don't need to manually specify + # the dependent libraries as `cl` does so. + target_compile_options(${target} PRIVATE + "SHELL:-Xclang --dependent-lib=oldnames" + # TODO(compnerd) handle /MT, /MTd + "SHELL:-Xclang --dependent-lib=msvcrt$<$:d>") + endif() + endif() target_include_directories(${target} SYSTEM PRIVATE ${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_UC_INCLUDE} ${SWIFT_${SWIFTLIB_SINGLE_SDK}_${SWIFTLIB_SINGLE_ARCHITECTURE}_ICU_I18N_INCLUDE}) @@ -2625,6 +2625,21 @@ function(_add_swift_executable_single name) ${SWIFTEXE_SINGLE_DEPENDS}) llvm_update_compile_flags("${name}") + if(SWIFTEXE_SINGLE_SDK STREQUAL WINDOWS) + swift_windows_include_for_arch(${SWIFTEXE_SINGLE_ARCHITECTURE} + ${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE) + target_include_directories(${name} SYSTEM PRIVATE + ${${SWIFTEXE_SINGLE_ARCHITECTURE}_INCLUDE}) + + if(NOT ${CMAKE_C_COMPILER_ID} STREQUAL MSVC) + # MSVC doesn't support -Xclang. We don't need to manually specify + # the dependent libraries as `cl` does so. + target_compile_options(${name} PRIVATE + "SHELL:-Xclang --dependent-lib=oldnames" + # TODO(compnerd) handle /MT, /MTd + "SHELL:-Xclang --dependent-lib=msvcrt$<$:d>") + endif() + endif() target_compile_options(${name} PRIVATE ${c_compile_flags}) target_link_directories(${name} PRIVATE diff --git a/cmake/modules/SwiftWindowsSupport.cmake b/cmake/modules/SwiftWindowsSupport.cmake index ffb6f7da6b70..7d97cdbadcec 100644 --- a/cmake/modules/SwiftWindowsSupport.cmake +++ b/cmake/modules/SwiftWindowsSupport.cmake @@ -49,7 +49,7 @@ function(swift_windows_lib_for_arch arch var) set(${var} ${paths} PARENT_SCOPE) endfunction() -function(swift_windows_generate_sdk_vfs_overlay flags) +function(swift_windows_get_sdk_vfs_overlay overlay) get_filename_component(VCToolsInstallDir ${VCToolsInstallDir} ABSOLUTE) get_filename_component(UniversalCRTSdkDir ${UniversalCRTSdkDir} ABSOLUTE) set(UCRTVersion ${UCRTVersion}) @@ -58,10 +58,8 @@ function(swift_windows_generate_sdk_vfs_overlay flags) configure_file("${SWIFT_SOURCE_DIR}/utils/WindowsSDKVFSOverlay.yaml.in" "${CMAKE_CURRENT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml" @ONLY) - - set(${flags} - -Xclang;-ivfsoverlay;-Xclang;"${CMAKE_CURRENT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml" - PARENT_SCOPE) + set(${overlay} ${CMAKE_CURRENT_BINARY_DIR}/windows-sdk-vfs-overlay.yaml + PARENT_SCOPE) endfunction() function(swift_verify_windows_VCVAR var) diff --git a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake index c00130f3c8cb..0db38eb15437 100644 --- a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake +++ b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake @@ -82,6 +82,12 @@ function(add_sourcekit_default_compiler_flags target) endif() # Set compilation and link flags. + if(${SWIFT_HOST_VARIANT_SDK} STREQUAL WINDOWS) + swift_windows_include_for_arch(${SWIFT_HOST_VARIANT_ARCH} + ${SWIFT_HOST_VARIANT_ARCH}_INCLUDE) + target_include_directories(${target} SYSTEM PRIVATE + ${${SWIFT_HOST_VARIANT_ARCH}_INCLUDE}) + endif() target_compile_options(${target} PRIVATE -fblocks) target_link_options(${target} PRIVATE