@@ -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" )
@@ -794,7 +794,6 @@ include(SwiftConfigureSDK)
794794include (SwiftComponents)
795795include (SwiftList)
796796include (AddPureSwift)
797- include (SetRPATH)
798797
799798# Configure swift include, install, build components.
800799swift_configure_components()
@@ -830,29 +829,19 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
830829 else ()
831830 set (BOOTSTRAPPING_MODE "HOSTTOOLS" )
832831 endif ()
833- elseif (BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER )
832+ elseif (BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX )
834833 # We are building using a pre-installed host toolchain but not bootstrapping
835834 # the Swift modules. This happens when building using 'build-tooling-libs'
836835 # where we haven't built a new Swift compiler. Use the Swift compiler from the
837836 # pre-installed host toolchain to build the Swift modules.
838837 set (SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER} " )
839838endif ()
840839
841- # When we have the early SwiftSyntax build, we can include its parser.
842- if (SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR)
843- set (SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS
844- ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR} /cmake/SwiftSyntaxTargets.cmake)
845- if (NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS} " )
846- message (STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax" )
847- else ()
848- set (SWIFT_SWIFT_PARSER TRUE )
849- include (${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS} )
850-
851- if (SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" )
852- # Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
853- message (WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled" )
854- set (BOOTSTRAPPING_MODE "HOSTTOOLS" )
855- endif ()
840+ if (SWIFT_BUILD_SWIFT_SYNTAX)
841+ # Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled.
842+ if (SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" )
843+ message (WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled" )
844+ set (BOOTSTRAPPING_MODE "HOSTTOOLS" )
856845 endif ()
857846endif ()
858847
@@ -962,7 +951,6 @@ if(XCODE)
962951 set (SWIFT_SDKS "OSX" )
963952endif ()
964953
965-
966954# FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics,
967955# so we need to hard-code it. For example, the SDK for Android is just 'ANDROID',
968956# and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately.
@@ -1171,13 +1159,17 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT CMAKE_CROSSCOMPILING)
11711159 set (CMAKE_OSX_DEPLOYMENT_TARGET "" )
11721160endif ()
11731161
1162+ swift_get_host_triple(SWIFT_HOST_TRIPLE)
1163+ set (SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _ARCH_${SWIFT_HOST_VARIANT_ARCH} _MODULE}" )
1164+ set (SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY} /swift/host" )
1165+
11741166if (SWIFT_INCLUDE_TOOLS)
11751167 message (STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_HOST_VARIANT_ARCH} " )
11761168 message (STATUS " Build type: ${CMAKE_BUILD_TYPE} " )
11771169 message (STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS} " )
11781170 message (STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO} " )
11791171 message (STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE} " )
1180- message (STATUS " Swift parser: ${SWIFT_SWIFT_PARSER } " )
1172+ message (STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX } " )
11811173 message (STATUS "" )
11821174else ()
11831175 message (STATUS "Not building host Swift tools" )
@@ -1323,6 +1315,34 @@ endif()
13231315add_subdirectory (include )
13241316
13251317if (SWIFT_INCLUDE_TOOLS)
1318+ # Include 'swift-syntax'.
1319+ # This is a function because we want to set some 'CMAKE_*' variables temporarily.'
1320+ # TODO: Replace this with 'block()' after CMake 3.25
1321+ function (include_swift_syntax)
1322+ if (NOT SWIFT_BUILD_SWIFT_SYNTAX)
1323+ return ()
1324+ endif ()
1325+ if (NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE} " )
1326+ message (SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE" )
1327+ return ()
1328+ endif ()
1329+
1330+ set (CMAKE_Swift_COMPILER_TARGET ${SWIFT_HOST_TRIPLE} )
1331+ set (BUILD_SHARED_LIBS ON )
1332+ # All libraries in 'swift-syntax' goes to 'lib/swift/host'.
1333+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR} " )
1334+ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR} " )
1335+ if (SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" )
1336+ set (SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK} _LIB_SUBDIR}" )
1337+ endif ()
1338+
1339+ FetchContent_Declare(SwiftSyntax
1340+ SOURCE_DIR "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE} "
1341+ )
1342+ FetchContent_MakeAvailable(SwiftSyntax)
1343+ endfunction ()
1344+ include_swift_syntax()
1345+
13261346 add_subdirectory (lib)
13271347
13281348 # SwiftCompilerSources must come before "tools".
0 commit comments