@@ -94,6 +94,7 @@ include(CMakeDependentOption)
9494include (CheckLanguage)
9595include (GNUInstallDirs)
9696include (SwiftImplicitImport)
97+ include (FetchContent)
9798
9899# Enable Swift for the host compiler build if we have the language. It is
99100# optional until we have a bootstrap story.
@@ -691,10 +692,9 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang)
691692 add_compile_options ($<$<COMPILE_LANGUAGE:CXX>:-Werror=c++98-compat-extra-semi>)
692693endif ()
693694
694- # Make sure we know where swift-syntax is because we need it to build the parser.
695- if (NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE} " )
696- message (SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE" )
697- endif ()
695+ option (SWIFT_BUILD_SWIFT_SYNTAX
696+ "Enable building swift syntax"
697+ FALSE )
698698
699699set (SWIFT_BUILD_HOST_DISPATCH FALSE )
700700if (SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin" )
@@ -829,7 +829,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
829829 else ()
830830 set (BOOTSTRAPPING_MODE "HOSTTOOLS" )
831831 endif ()
832- elseif (BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER )
832+ elseif (BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX )
833833 # We are building using a pre-installed host toolchain but not bootstrapping
834834 # the Swift modules. This happens when building using 'build-tooling-libs'
835835 # where we haven't built a new Swift compiler. Use the Swift compiler from the
@@ -943,19 +943,6 @@ if(XCODE)
943943 set (SWIFT_SDKS "OSX" )
944944endif ()
945945
946- # When we have the early SwiftSyntax build, we can include its parser.
947- if (SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
948- set (SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
949- ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR} /cmake/SwiftSyntaxTargets.cmake)
950- if (NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS} " )
951- message (STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax" )
952- else ()
953- set (SWIFT_SWIFT_PARSER TRUE )
954- include (${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS} )
955- endif ()
956- endif ()
957-
958-
959946# FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics,
960947# so we need to hard-code it. For example, the SDK for Android is just 'ANDROID',
961948# and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately.
@@ -1164,13 +1151,29 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT CMAKE_CROSSCOMPILING)
11641151 set (CMAKE_OSX_DEPLOYMENT_TARGET "" )
11651152endif ()
11661153
1154+ set (SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _MODULE}" )
1155+ set (SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY} /swift/host" )
1156+ if (SWIFT_BUILD_SWIFT_SYNTAX)
1157+ if (NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE} " )
1158+ message (SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE" )
1159+ endif ()
1160+
1161+ set (BUILD_SHARED_LIBS_OLD "${BUILD_SHARED_LIBS} " )
1162+ set (BUILD_SHARED_LIBS ON )
1163+ FetchContent_Declare(SwiftSyntax
1164+ SOURCE_DIR "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE} "
1165+ )
1166+ FetchContent_MakeAvailable(SwiftSyntax)
1167+ set (BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_OLD} " )
1168+ endif ()
1169+
11671170if (SWIFT_INCLUDE_TOOLS)
11681171 message (STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_HOST_VARIANT_ARCH} " )
11691172 message (STATUS " Build type: ${CMAKE_BUILD_TYPE} " )
11701173 message (STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS} " )
11711174 message (STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO} " )
11721175 message (STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE} " )
1173- message (STATUS " Swift parser: ${SWIFT_SWIFT_PARSER } " )
1176+ message (STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX } " )
11741177 message (STATUS "" )
11751178else ()
11761179 message (STATUS "Not building host Swift tools" )
0 commit comments