From 041691184cc41d6af19a2c215c3e998bdb242949 Mon Sep 17 00:00:00 2001 From: Ben Barham Date: Tue, 16 May 2023 16:25:12 -0700 Subject: [PATCH 01/13] [CMake] Replace early swift-syntax with FetchContent Use FetchContent to include swift-syntax directly in swift. This can be thought of as an `add_subdirectory` for a directory outside the root. The default build directory will be `_deps/swiftsyntax-subbuild/`, though the modules and shared libraries will be built in `lib/swift/host` by passing down `SWIFT_HOST_LIBRARIES_DEST_DIR` to avoid copying them as we were doing previously. --- CMakeLists.txt | 49 +++--- cmake/modules/AddPureSwift.cmake | 30 +++- cmake/modules/AddSwift.cmake | 12 +- cmake/modules/AddSwiftUnittests.cmake | 2 +- lib/AST/CMakeLists.txt | 4 +- lib/ASTGen/CMakeLists.txt | 20 +-- lib/CMakeLists.txt | 143 ------------------ lib/Frontend/CMakeLists.txt | 4 +- lib/Frontend/PrintingDiagnosticConsumer.cpp | 8 +- lib/IDE/CodeCompletion.cpp | 2 +- lib/Macros/CMakeLists.txt | 2 +- .../Sources/ObservationMacros/CMakeLists.txt | 10 +- lib/Macros/Sources/SwiftMacros/CMakeLists.txt | 8 +- lib/Parse/CMakeLists.txt | 36 ++--- lib/Parse/ParseDecl.cpp | 10 +- lib/Parse/ParseIfConfig.cpp | 2 +- lib/Parse/ParseType.cpp | 2 +- lib/Sema/CMakeLists.txt | 4 +- lib/Sema/CSApply.cpp | 2 +- lib/Sema/CSGen.cpp | 2 +- lib/Sema/TypeCheckMacros.cpp | 20 +-- test/lit.site.cfg.in | 2 +- .../cmake/modules/AddSwiftSourceKit.cmake | 8 +- tools/driver/CMakeLists.txt | 4 +- tools/libSwiftScan/CMakeLists.txt | 2 +- tools/swift-plugin-server/CMakeLists.txt | 8 +- utils/build-script-impl | 10 -- .../build_script_invocation.py | 17 +-- .../swift_build_support/products/__init__.py | 2 - .../products/earlyswiftdriver.py | 7 +- .../products/earlyswiftsyntax.py | 82 ---------- 31 files changed, 145 insertions(+), 369 deletions(-) delete mode 100644 utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a460b731d019..99cff228a7908 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,7 @@ include(CMakeDependentOption) include(CheckLanguage) include(GNUInstallDirs) include(SwiftImplicitImport) +include(FetchContent) # Enable Swift for the host compiler build if we have the language. It is # optional until we have a bootstrap story. @@ -691,10 +692,9 @@ if(CMAKE_C_COMPILER_ID MATCHES Clang) add_compile_options($<$:-Werror=c++98-compat-extra-semi>) endif() -# Make sure we know where swift-syntax is because we need it to build the parser. -if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") - message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") -endif() +option(SWIFT_BUILD_SWIFT_SYNTAX + "Enable building swift syntax" + FALSE) set(SWIFT_BUILD_HOST_DISPATCH FALSE) if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") @@ -830,7 +830,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*") else() set(BOOTSTRAPPING_MODE "HOSTTOOLS") endif() -elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER) +elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX) # We are building using a pre-installed host toolchain but not bootstrapping # the Swift modules. This happens when building using 'build-tooling-libs' # where we haven't built a new Swift compiler. Use the Swift compiler from the @@ -838,21 +838,11 @@ elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER) set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}") endif() -# When we have the early SwiftSyntax build, we can include its parser. -if(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR) - set(SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS - ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/cmake/SwiftSyntaxTargets.cmake) - if(NOT EXISTS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}") - message(STATUS "Skipping Swift Swift parser integration due to missing early SwiftSyntax") - else() - set(SWIFT_SWIFT_PARSER TRUE) - include(${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_TARGETS}) - - if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS") - # Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled. - message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled") - set(BOOTSTRAPPING_MODE "HOSTTOOLS") - endif() +if(SWIFT_BUILD_SWIFT_SYNTAX) + # Only "HOSTTOOLS" is supported in Linux when Swift parser integration is enabled. + if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS") + message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled") + set(BOOTSTRAPPING_MODE "HOSTTOOLS") endif() endif() @@ -962,7 +952,6 @@ if(XCODE) set(SWIFT_SDKS "OSX") endif() - # FIXME: the parameters we specify in SWIFT_SDKS are lacking architecture specifics, # so we need to hard-code it. For example, the SDK for Android is just 'ANDROID', # and we have to specify SWIFT_SDK_ANDROID_ARCHITECTURES separately. @@ -1171,13 +1160,29 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT CMAKE_CROSSCOMPILING) set(CMAKE_OSX_DEPLOYMENT_TARGET "") endif() +set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}") +set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") +if(SWIFT_BUILD_SWIFT_SYNTAX) + if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") + message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") + endif() + + set(BUILD_SHARED_LIBS_OLD "${BUILD_SHARED_LIBS}") + set(BUILD_SHARED_LIBS ON) + FetchContent_Declare(SwiftSyntax + SOURCE_DIR "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}" + ) + FetchContent_MakeAvailable(SwiftSyntax) + set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_OLD}") +endif() + if(SWIFT_INCLUDE_TOOLS) message(STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_HOST_VARIANT_ARCH}") message(STATUS " Build type: ${CMAKE_BUILD_TYPE}") message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}") message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}") message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}") - message(STATUS " Swift parser: ${SWIFT_SWIFT_PARSER}") + message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}") message(STATUS "") else() message(STATUS "Not building host Swift tools") diff --git a/cmake/modules/AddPureSwift.cmake b/cmake/modules/AddPureSwift.cmake index 6c79fdcf351ce..dd0dcb4412c61 100644 --- a/cmake/modules/AddPureSwift.cmake +++ b/cmake/modules/AddPureSwift.cmake @@ -121,7 +121,7 @@ endfunction() # source1 ... # Sources to add into this library. function(add_pure_swift_host_library name) - if (NOT SWIFT_SWIFT_PARSER) + if (NOT SWIFT_BUILD_SWIFT_SYNTAX) message(STATUS "Not building ${name} because swift-syntax is not available") return() endif() @@ -196,13 +196,15 @@ function(add_pure_swift_host_library name) # Make sure we can use the host libraries. target_include_directories(${name} PUBLIC - ${SWIFT_HOST_LIBRARIES_DEST_DIR}) + "${SWIFT_HOST_LIBRARIES_DEST_DIR}") + target_link_directories(${name} PUBLIC + "${SWIFT_HOST_LIBRARIES_DEST_DIR}") if(APSHL_EMIT_MODULE) # Determine where Swift modules will be built and installed. - set(module_triple ${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}) - set(module_dir ${SWIFT_HOST_LIBRARIES_DEST_DIR}) + set(module_triple "${SWIFT_HOST_MODULE_TRIPLE}") + set(module_dir "${SWIFT_HOST_LIBRARIES_DEST_DIR}") set(module_base "${module_dir}/${name}.swiftmodule") set(module_file "${module_base}/${module_triple}.swiftmodule") set(module_interface_file "${module_base}/${module_triple}.swiftinterface") @@ -234,6 +236,12 @@ function(add_pure_swift_host_library name) >) endif() + if(LLVM_USE_LINKER) + target_link_options(${name} PRIVATE + "-use-ld=${LLVM_USE_LINKER}" + ) + endif() + # Export this target. set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name}) endfunction() @@ -241,7 +249,7 @@ endfunction() # Add a new "pure" Swift host tool. # # "Pure" Swift host tools can only contain Swift code, and will be built -# with the host compiler. +# with the host compiler. # # Usage: # add_pure_swift_host_tool(name @@ -262,7 +270,7 @@ endfunction() # source1 ... # Sources to add into this tool. function(add_pure_swift_host_tool name) - if (NOT SWIFT_SWIFT_PARSER) + if (NOT SWIFT_BUILD_SWIFT_SYNTAX) message(STATUS "Not building ${name} because swift-syntax is not available") return() endif() @@ -322,7 +330,15 @@ function(add_pure_swift_host_tool name) # Make sure we can use the host libraries. target_include_directories(${name} PUBLIC - ${SWIFT_HOST_LIBRARIES_DEST_DIR}) + "${SWIFT_HOST_LIBRARIES_DEST_DIR}") + target_link_directories(${name} PUBLIC + "${SWIFT_HOST_LIBRARIES_DEST_DIR}") + + if(LLVM_USE_LINKER) + target_link_options(${name} PRIVATE + "-use-ld=${LLVM_USE_LINKER}" + ) + endif() # Workaround to touch the library and its objects so that we don't # continually rebuild (again, see corresponding change in swift-syntax). diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index b55f7d8071656..c7125385a305c 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -442,7 +442,7 @@ endfunction() function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping) if(NOT BOOTSTRAPPING_MODE) - if (SWIFT_SWIFT_PARSER) + if (SWIFT_BUILD_SWIFT_SYNTAX) set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS") else() return() @@ -578,7 +578,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping) ${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}) endif() - if(SWIFT_SWIFT_PARSER) + if(SWIFT_BUILD_SWIFT_SYNTAX) # For the "end step" of bootstrapping configurations, we need to be # able to fall back to the SDK directory for libswiftCore et al. if (BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*") @@ -656,7 +656,7 @@ function(add_swift_host_library name) translate_flags(ASHL "${options}") # Once the new Swift parser is linked, everything has Swift modules. - if (SWIFT_SWIFT_PARSER AND ASHL_SHARED) + if (SWIFT_BUILD_SWIFT_SYNTAX AND ASHL_SHARED) set(ASHL_HAS_SWIFT_MODULES ON) endif() @@ -702,7 +702,7 @@ function(add_swift_host_library name) add_library(${name} ${libkind} ${ASHL_SOURCES}) - target_link_directories(${name} PUBLIC ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}) + target_link_directories(${name} PUBLIC "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") # Respect LLVM_COMMON_DEPENDS if it is set. # @@ -924,7 +924,7 @@ function(add_swift_host_tool executable) endif() # Once the new Swift parser is linked in, every host tool has Swift modules. - if (SWIFT_SWIFT_PARSER AND NOT ASHT_DOES_NOT_USE_SWIFT) + if (SWIFT_BUILD_SWIFT_SYNTAX AND NOT ASHT_DOES_NOT_USE_SWIFT) set(ASHT_HAS_SWIFT_MODULES ON) endif() @@ -963,7 +963,7 @@ function(add_swift_host_tool executable) endif() endif() - if(SWIFT_SWIFT_PARSER) + if(SWIFT_BUILD_SWIFT_SYNTAX) set(extra_relative_rpath "") if(NOT "${ASHT_BOOTSTRAPPING}" STREQUAL "") if(executable MATCHES "-bootstrapping") diff --git a/cmake/modules/AddSwiftUnittests.cmake b/cmake/modules/AddSwiftUnittests.cmake index b3ed5ef8a391f..78a84e6ec5821 100644 --- a/cmake/modules/AddSwiftUnittests.cmake +++ b/cmake/modules/AddSwiftUnittests.cmake @@ -123,7 +123,7 @@ function(add_swift_unittest test_dirname) APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}") endif() - if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST) + if (SWIFT_BUILD_SWIFT_SYNTAX AND NOT ASU_IS_TARGET_TEST) # Link to stdlib the compiler uses. _add_swift_runtime_link_flags(${test_dirname} "${relative_lib_path}" "") diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt index 9e5590b7315db..4bf20a642f0f8 100644 --- a/lib/AST/CMakeLists.txt +++ b/lib/AST/CMakeLists.txt @@ -155,10 +155,10 @@ target_link_libraries(swiftAST INTERFACE clangAPINotes clangBasic) -if(SWIFT_SWIFT_PARSER) +if(SWIFT_BUILD_SWIFT_SYNTAX) target_compile_definitions(swiftAST PRIVATE - SWIFT_SWIFT_PARSER + SWIFT_BUILD_SWIFT_SYNTAX ) endif() diff --git a/lib/ASTGen/CMakeLists.txt b/lib/ASTGen/CMakeLists.txt index f5d4a899cec73..736970051e359 100644 --- a/lib/ASTGen/CMakeLists.txt +++ b/lib/ASTGen/CMakeLists.txt @@ -26,15 +26,15 @@ add_pure_swift_host_library(swiftASTGen STATIC DEPENDENCIES swiftAST SWIFT_DEPENDENCIES - SwiftSyntax::SwiftBasicFormat - SwiftSyntax::SwiftCompilerPluginMessageHandling - SwiftSyntax::SwiftDiagnostics - SwiftSyntax::SwiftOperators - SwiftSyntax::SwiftParser - SwiftSyntax::SwiftParserDiagnostics - SwiftSyntax::SwiftSyntax - SwiftSyntax::SwiftSyntaxBuilder - SwiftSyntax::SwiftSyntaxMacros - SwiftSyntax::SwiftSyntaxMacroExpansion + SwiftBasicFormat + SwiftCompilerPluginMessageHandling + SwiftDiagnostics + SwiftOperators + SwiftParser + SwiftParserDiagnostics + SwiftSyntax + SwiftSyntaxBuilder + SwiftSyntaxMacros + SwiftSyntaxMacroExpansion swiftLLVMJSON ) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 7a6f55c80406f..9054a85a5eb41 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -12,149 +12,6 @@ # directory. list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets) -# Set up for linking against swift-syntax. -if (SWIFT_SWIFT_PARSER) - # Set up linking against the swift-syntax modules. - # Link against the swift-syntax modules. - set(SWIFT_SYNTAX_MODULES - SwiftBasicFormat - SwiftParser - SwiftParserDiagnostics - SwiftDiagnostics - SwiftSyntax - SwiftOperators - SwiftSyntaxBuilder - SwiftSyntaxMacros - SwiftSyntaxMacroExpansion - SwiftCompilerPluginMessageHandling - ) - - # Compute the list of SwiftSyntax targets that we will link against. - list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "SwiftSyntax::" - OUTPUT_VARIABLE SWIFT_SYNTAX_TARGETS) - - set(SWIFT_SYNTAX_LIBRARIES_BUILD_DIR - "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host") - set(SWIFT_HOST_LIBRARIES_DEST_DIR - "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") - - # Determine the SwiftSyntax shared library files that were built as - # part of earlyswiftsyntax. - list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_SHARED_LIBRARY_PREFIX}" - OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES) - list(TRANSFORM SWIFT_SYNTAX_SHARED_LIBRARIES APPEND - "${CMAKE_SHARED_LIBRARY_SUFFIX}" - OUTPUT_VARIABLE SWIFT_SYNTAX_SHARED_LIBRARIES) - - list(TRANSFORM SWIFT_SYNTAX_MODULES PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}" - OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) - list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES APPEND - "${CMAKE_IMPORT_LIBRARY_SUFFIX}" OUTPUT_VARIABLE - SWIFT_SYNTAX_IMPORT_LIBRARIES) - - # Interface library to collect swiftinterfaces and swiftmodules from - # SwiftSyntax - add_library(swiftSyntaxLibraries INTERFACE) - - # 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 MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD") - # 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() - - if(CMAKE_SYSTEM_NAME MATCHES Windows) - add_custom_command(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} - DEPENDS "${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib}" - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/bin/${sharedlib} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib}) - add_custom_target(copy_swiftSyntaxLibrary_${sharedlib} - DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} - COMMENT "copying ${sharedlib}") - swift_install_in_component(PROGRAMS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${sharedlib} - DESTINATION bin - COMPONENT compiler) - else() - add_custom_command(OUTPUT "${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) - endif() - - add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib}) - endforeach() - - if(CMAKE_SYSTEM_NAME MATCHES Windows) - foreach(implib ${SWIFT_SYNTAX_IMPORT_LIBRARIES}) - add_custom_command(OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} - DEPENDS ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib} - COMMAND "${CMAKE_COMMAND}" -E copy_if_different ${SWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR}/lib/swift/host/${implib} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib}) - add_custom_target(copy_swiftSyntaxLibrary_${implib} - DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} - COMMENT "Copying ${implib}") - swift_install_in_component(PROGRAMS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/windows/${SWIFT_HOST_VARIANT_ARCH}/${implib} - DESTINATION lib - COMPONENT compiler) - add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${implib}) - endforeach() - endif() - - # Copy all of the Swift modules from earlyswiftsyntax so they can be found - # in the same relative place within the build directory as in the final - # toolchain. - list(TRANSFORM SWIFT_SYNTAX_MODULES APPEND ".swiftmodule" - OUTPUT_VARIABLE SWIFT_SYNTAX_MODULE_DIRS) - - foreach(module_dir ${SWIFT_SYNTAX_MODULE_DIRS}) - # Find all of the source module files. - file(GLOB module_files - "${SWIFT_SYNTAX_LIBRARIES_BUILD_DIR}/${module_dir}/*.swiftinterface") - - # Determine the destination module files. - set(dest_module_files) - foreach(full_module_file ${module_files}) - get_filename_component(module_file ${full_module_file} NAME) - list(APPEND dest_module_files - "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${module_file}") - endforeach() - - add_custom_command( - OUTPUT ${dest_module_files} - DEPENDS ${module_files} - COMMAND ${CMAKE_COMMAND} -E make_directory ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir} - COMMAND ${CMAKE_COMMAND} -E copy_if_different ${module_files} ${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/ - ) - - add_custom_target(copy_swiftSyntaxModule_${module_dir} - DEPENDS ${dest_module_files} - 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() - - # Add copied SwiftSyntax libraries to global dependencies. - list(APPEND LLVM_COMMON_DEPENDS swiftSyntaxLibraries) -endif() - add_subdirectory(APIDigester) add_subdirectory(AST) add_subdirectory(ASTGen) diff --git a/lib/Frontend/CMakeLists.txt b/lib/Frontend/CMakeLists.txt index c01fdcf7e174b..ebb9a2aeecabf 100644 --- a/lib/Frontend/CMakeLists.txt +++ b/lib/Frontend/CMakeLists.txt @@ -37,9 +37,9 @@ target_link_libraries(swiftFrontend PRIVATE set_swift_llvm_is_available(swiftFrontend) -if (SWIFT_SWIFT_PARSER) +if (SWIFT_BUILD_SWIFT_SYNTAX) target_compile_definitions(swiftFrontend PRIVATE - SWIFT_SWIFT_PARSER + SWIFT_BUILD_SWIFT_SYNTAX ) endif() diff --git a/lib/Frontend/PrintingDiagnosticConsumer.cpp b/lib/Frontend/PrintingDiagnosticConsumer.cpp index 9f6a8976c3aef..da70fa1f2f177 100644 --- a/lib/Frontend/PrintingDiagnosticConsumer.cpp +++ b/lib/Frontend/PrintingDiagnosticConsumer.cpp @@ -315,7 +315,7 @@ namespace { } } // end anonymous namespace -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX /// Enqueue a diagnostic with ASTGen's diagnostic rendering. static void enqueueDiagnostic( void *queuedDiagnostics, const DiagnosticInfo &info, SourceManager &SM @@ -389,7 +389,7 @@ static SmallVector getSourceBufferStack( } } -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX void PrintingDiagnosticConsumer::queueBuffer( SourceManager &sourceMgr, unsigned bufferID) { QueuedBuffer knownSourceFile = queuedBuffers[bufferID]; @@ -454,7 +454,7 @@ void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM, switch (FormattingStyle) { case DiagnosticOptions::FormattingStyle::Swift: { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX // Use the swift-syntax formatter. auto bufferStack = getSourceBufferStack(SM, Info.Loc); if (!bufferStack.empty()) { @@ -496,7 +496,7 @@ void PrintingDiagnosticConsumer::handleDiagnostic(SourceManager &SM, } void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX if (queuedDiagnostics) { char *renderedString = nullptr; SwiftInt renderedStringLen = 0; diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index 362d0619152da..568d9557fe279 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -1172,7 +1172,7 @@ static void addPoundDirectives(CodeCompletionResultSink &Sink) { Builder.addRightParen(); }); -#ifndef SWIFT_SWIFT_PARSER +#ifndef SWIFT_BUILD_SWIFT_SYNTAX addWithName("warning", CodeCompletionKeywordKind::pound_warning, [&] (CodeCompletionResultBuilder &Builder) { Builder.addLeftParen(); diff --git a/lib/Macros/CMakeLists.txt b/lib/Macros/CMakeLists.txt index 3598a4e917557..23e7de788cd47 100644 --- a/lib/Macros/CMakeLists.txt +++ b/lib/Macros/CMakeLists.txt @@ -33,7 +33,7 @@ function(add_swift_macro_library name) # 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) + if (NOT SWIFT_BUILD_SWIFT_SYNTAX) return() endif() diff --git a/lib/Macros/Sources/ObservationMacros/CMakeLists.txt b/lib/Macros/Sources/ObservationMacros/CMakeLists.txt index 3afd3380125aa..c3deee2c4747a 100644 --- a/lib/Macros/Sources/ObservationMacros/CMakeLists.txt +++ b/lib/Macros/Sources/ObservationMacros/CMakeLists.txt @@ -15,9 +15,9 @@ add_swift_macro_library(ObservationMacros Extensions.swift ObservableMacro.swift SWIFT_DEPENDENCIES - SwiftSyntax::SwiftDiagnostics - SwiftSyntax::SwiftOperators - SwiftSyntax::SwiftSyntaxBuilder - SwiftSyntax::SwiftSyntax - SwiftSyntax::SwiftSyntaxMacros + SwiftDiagnostics + SwiftOperators + SwiftSyntaxBuilder + SwiftSyntax + SwiftSyntaxMacros ) diff --git a/lib/Macros/Sources/SwiftMacros/CMakeLists.txt b/lib/Macros/Sources/SwiftMacros/CMakeLists.txt index 32a798260afdb..9d83b612b4987 100644 --- a/lib/Macros/Sources/SwiftMacros/CMakeLists.txt +++ b/lib/Macros/Sources/SwiftMacros/CMakeLists.txt @@ -13,8 +13,8 @@ add_swift_macro_library(SwiftMacros OptionSetMacro.swift SWIFT_DEPENDENCIES - SwiftSyntax::SwiftDiagnostics - SwiftSyntax::SwiftSyntax - SwiftSyntax::SwiftSyntaxBuilder - SwiftSyntax::SwiftSyntaxMacros + SwiftDiagnostics + SwiftSyntax + SwiftSyntaxBuilder + SwiftSyntaxMacros ) diff --git a/lib/Parse/CMakeLists.txt b/lib/Parse/CMakeLists.txt index 1b66331ad7e6d..8a01e55f893b0 100644 --- a/lib/Parse/CMakeLists.txt +++ b/lib/Parse/CMakeLists.txt @@ -25,35 +25,35 @@ target_link_libraries(swiftParse PRIVATE swiftAST ) -if (SWIFT_SWIFT_PARSER) +if (SWIFT_BUILD_SWIFT_SYNTAX) target_link_libraries(swiftParse PRIVATE - SwiftSyntax::SwiftBasicFormat - SwiftSyntax::SwiftParser - SwiftSyntax::SwiftParserDiagnostics - SwiftSyntax::SwiftDiagnostics - SwiftSyntax::SwiftSyntax - SwiftSyntax::SwiftOperators - SwiftSyntax::SwiftSyntaxBuilder - SwiftSyntax::SwiftSyntaxMacros + SwiftBasicFormat + SwiftParser + SwiftParserDiagnostics + SwiftDiagnostics + SwiftSyntax + SwiftOperators + SwiftSyntaxBuilder + SwiftSyntaxMacros swiftASTGen ) add_dependencies(swiftParse - SwiftSyntax::SwiftBasicFormat - SwiftSyntax::SwiftParser - SwiftSyntax::SwiftParserDiagnostics - SwiftSyntax::SwiftDiagnostics - SwiftSyntax::SwiftSyntax - SwiftSyntax::SwiftOperators - SwiftSyntax::SwiftSyntaxBuilder - SwiftSyntax::SwiftSyntaxMacros + SwiftBasicFormat + SwiftParser + SwiftParserDiagnostics + SwiftDiagnostics + SwiftSyntax + SwiftOperators + SwiftSyntaxBuilder + SwiftSyntaxMacros swiftASTGen ) target_compile_definitions(swiftParse PRIVATE - SWIFT_SWIFT_PARSER + SWIFT_BUILD_SWIFT_SYNTAX ) endif() diff --git a/lib/Parse/ParseDecl.cpp b/lib/Parse/ParseDecl.cpp index 12f2bb72a10cc..50aa486a512aa 100644 --- a/lib/Parse/ParseDecl.cpp +++ b/lib/Parse/ParseDecl.cpp @@ -163,7 +163,7 @@ extern "C" void parseTopLevelSwift(const char *buffer, void *outputContext, void (*)(void *, void *)); -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX static void appendToVector(void *declPtr, void *vecPtr) { auto vec = static_cast *>(vecPtr); auto decl = static_cast(declPtr); @@ -207,7 +207,7 @@ extern "C" void swift_ASTGen_buildTopLevelASTNodes( /// decl-sil-stage [[only in SIL mode] /// \endverbatim void Parser::parseTopLevelItems(SmallVectorImpl &items) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX llvm::Optional existingParsingTransaction; parseSourceFileViaASTGen(items, existingParsingTransaction); #endif @@ -258,7 +258,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl &items) { } } -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX if (existingParsingTransaction) existingParsingTransaction->abort(); @@ -310,7 +310,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl &items) { void *ExportedSourceFileRequest::evaluate(Evaluator &evaluator, const SourceFile *SF) const { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX // The SwiftSyntax parser doesn't (yet?) handle SIL. if (SF->Kind == SourceFileKind::SIL) return nullptr; @@ -343,7 +343,7 @@ void Parser::parseSourceFileViaASTGen( SmallVectorImpl &items, llvm::Optional &transaction, bool suppressDiagnostics) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX const auto &langOpts = Context.LangOpts; // We only need to do parsing if we either have ASTGen enabled, or want the diff --git a/lib/Parse/ParseIfConfig.cpp b/lib/Parse/ParseIfConfig.cpp index ef10f8fdde5b8..58d991841cab3 100644 --- a/lib/Parse/ParseIfConfig.cpp +++ b/lib/Parse/ParseIfConfig.cpp @@ -557,7 +557,7 @@ class EvaluateIfConfigCondition : // Check whether this is any one of the known compiler features. const auto &langOpts = Ctx.LangOpts; -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX const bool hasSwiftSwiftParser = true; #else const bool hasSwiftSwiftParser = false; diff --git a/lib/Parse/ParseType.cpp b/lib/Parse/ParseType.cpp index 7d02b146bf2fd..54548243d43cf 100644 --- a/lib/Parse/ParseType.cpp +++ b/lib/Parse/ParseType.cpp @@ -601,7 +601,7 @@ extern "C" TypeRepr *swift_ASTGen_buildTypeRepr( /// ParserResult Parser::parseType( Diag<> MessageID, ParseTypeReason reason) { - #if SWIFT_SWIFT_PARSER + #if SWIFT_BUILD_SWIFT_SYNTAX auto astGenResult = parseASTFromSyntaxTree( [&](void *exportedSourceFile, const void *sourceLoc) { const void *endLocPtr = nullptr; diff --git a/lib/Sema/CMakeLists.txt b/lib/Sema/CMakeLists.txt index 16494b3ff76d2..6a80e3c20768d 100644 --- a/lib/Sema/CMakeLists.txt +++ b/lib/Sema/CMakeLists.txt @@ -86,10 +86,10 @@ target_link_libraries(swiftSema PRIVATE swiftParse swiftSerialization) -if (SWIFT_SWIFT_PARSER) +if (SWIFT_BUILD_SWIFT_SYNTAX) target_compile_definitions(swiftSema PRIVATE - SWIFT_SWIFT_PARSER + SWIFT_BUILD_SWIFT_SYNTAX ) target_link_libraries(swiftSema PRIVATE swiftASTGen) diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index 0891865a43fcc..61b2c0eae84d5 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -2934,7 +2934,7 @@ namespace { } Expr *visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *expr) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX auto &ctx = cs.getASTContext(); if (ctx.LangOpts.hasFeature(Feature::BuiltinMacros)) { auto expandedType = solution.simplifyType(solution.getType(expr)); diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 882349e9acf49..af0de3c9628d9 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -1356,7 +1356,7 @@ namespace { } Type visitMagicIdentifierLiteralExpr(MagicIdentifierLiteralExpr *expr) { -#ifdef SWIFT_SWIFT_PARSER +#ifdef SWIFT_BUILD_SWIFT_SYNTAX auto &ctx = CS.getASTContext(); if (ctx.LangOpts.hasFeature(Feature::BuiltinMacros)) { auto kind = MagicIdentifierLiteralExpr::getKindString(expr->getKind()) diff --git a/lib/Sema/TypeCheckMacros.cpp b/lib/Sema/TypeCheckMacros.cpp index 5313ab221e60e..6cc8cb36ac735 100644 --- a/lib/Sema/TypeCheckMacros.cpp +++ b/lib/Sema/TypeCheckMacros.cpp @@ -94,7 +94,7 @@ extern "C" bool swift_ASTGen_pluginServerLoadLibraryPlugin( void *handle, const char *libraryPath, const char *moduleName, void *diagEngine); -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX /// Look for macro's type metadata given its external module and type name. static void const * lookupMacroTypeMetadataByExternalName(ASTContext &ctx, StringRef moduleName, @@ -190,7 +190,7 @@ MacroDefinition MacroDefinitionRequest::evaluate( auto sourceFile = macro->getParentSourceFile(); -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX char *externalMacroNamePtr; ptrdiff_t externalMacroNameLength; ptrdiff_t *replacements; @@ -296,7 +296,7 @@ initializeExecutablePlugin(ASTContext &ctx, // FIXME: Ideally this should be done right after invoking the plugin. // But plugin loading is in libAST and it can't link ASTGen symbols. if (!executablePlugin->isInitialized()) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX if (!swift_ASTGen_initializePlugin(executablePlugin, &ctx.Diags)) { return nullptr; } @@ -317,7 +317,7 @@ initializeExecutablePlugin(ASTContext &ctx, // If this is a plugin server, load the library. if (!libraryPath.empty()) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX llvm::SmallString<128> resolvedLibraryPath; auto fs = ctx.SourceMgr.getFileSystem(); if (auto err = fs->getRealPath(libraryPath, resolvedLibraryPath)) { @@ -391,7 +391,7 @@ CompilerPluginLoadRequest::evaluate(Evaluator &evaluator, ASTContext *ctx, static llvm::Optional resolveInProcessMacro(ASTContext &ctx, Identifier moduleName, Identifier typeName, LoadedLibraryPlugin *plugin) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX /// Look for the type metadata given the external module and type names. auto macroMetatype = lookupMacroTypeMetadataByExternalName( ctx, moduleName.str(), typeName.str(), plugin); @@ -415,7 +415,7 @@ static llvm::Optional resolveExecutableMacro(ASTContext &ctx, LoadedExecutablePlugin *executablePlugin, Identifier moduleName, Identifier typeName) { -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX if (auto *execMacro = swift_ASTGen_resolveExecutableMacro( moduleName.str().data(), moduleName.str().size(), typeName.str().data(), typeName.str().size(), executablePlugin)) { @@ -986,7 +986,7 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion, LazyValue discriminator([&]() -> std::string { if (!discriminatorStr.empty()) return discriminatorStr.str(); -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX Mangle::ASTMangler mangler; return mangler.mangleMacroExpansion(expansion); #else @@ -1047,7 +1047,7 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion, return nullptr; } -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX PrettyStackTraceFreestandingMacroExpansion debugStack( "expanding freestanding macro", expansion); @@ -1226,7 +1226,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, LazyValue discriminator([&]() -> std::string { if (!discriminatorStr.empty()) return discriminatorStr.str(); -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX Mangle::ASTMangler mangler; return mangler.mangleAttachedMacroExpansion(attachedTo, attr, role); #else @@ -1304,7 +1304,7 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo, return nullptr; } -#if SWIFT_SWIFT_PARSER +#if SWIFT_BUILD_SWIFT_SYNTAX PrettyStackTraceDecl debugStack("expanding attached macro", attachedTo); auto *astGenAttrSourceFile = attrSourceFile->getExportedSourceFile(); diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index 8544f2a22bcea..8d4414f3c5d36 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -166,7 +166,7 @@ elif "@BOOTSTRAPPING_MODE@" == 'BOOTSTRAPPING': elif "@BOOTSTRAPPING_MODE@" == 'BOOTSTRAPPING-WITH-HOSTLIBS': config.available_features.add('bootstrapping_with_hostlibs_mode') -if '@SWIFT_SWIFT_PARSER@' == 'TRUE': +if '@SWIFT_BUILD_SWIFT_SYNTAX@' == 'TRUE': config.available_features.add('swift_swift_parser') # Let the main config do the real work. diff --git a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake index 2293712165751..4b5a63fef6046 100644 --- a/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake +++ b/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake @@ -25,7 +25,7 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES) # to do it. set(ASKD_BOOTSTRAPPING_MODE ${BOOTSTRAPPING_MODE}) if (NOT ASKD_BOOTSTRAPPING_MODE) - if (SWIFT_SWIFT_PARSER) + if (SWIFT_BUILD_SWIFT_SYNTAX) set(ASKD_BOOTSTRAPPING_MODE HOSTTOOLS) endif() endif() @@ -152,7 +152,7 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES) endif() endif() - if(SWIFT_SWIFT_PARSER) + if(SWIFT_BUILD_SWIFT_SYNTAX) if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) # Add rpath to the host Swift libraries. file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host") @@ -261,7 +261,7 @@ macro(add_sourcekit_library name) endif() # Once the new Swift parser is linked, everything has Swift modules. - if (SWIFT_SWIFT_PARSER AND SOURCEKITLIB_SHARED) + if (SWIFT_BUILD_SWIFT_SYNTAX AND SOURCEKITLIB_SHARED) set(SOURCEKITLIB_HAS_SWIFT_MODULES ON) endif() @@ -365,7 +365,7 @@ macro(add_sourcekit_framework name) set(framework_location "${lib_dir}/${name}.framework") # Once the new Swift parser is linked, everything has Swift modules. - if (SWIFT_SWIFT_PARSER) + if (SWIFT_BUILD_SWIFT_SYNTAX) set(SOURCEKITFW_HAS_SWIFT_MODULES ON) endif() diff --git a/tools/driver/CMakeLists.txt b/tools/driver/CMakeLists.txt index f08e56ee3c2f1..1b350f229d4a5 100644 --- a/tools/driver/CMakeLists.txt +++ b/tools/driver/CMakeLists.txt @@ -4,9 +4,7 @@ # Add additional libraries to which we need to link when the Swift Swift # parser is built in. function(add_swift_parser_link_libraries target) - if(SWIFT_SWIFT_PARSER) - target_link_directories(${target} PRIVATE - ${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH}) + if(SWIFT_BUILD_SWIFT_SYNTAX) target_link_libraries(${target} PRIVATE swiftCore) diff --git a/tools/libSwiftScan/CMakeLists.txt b/tools/libSwiftScan/CMakeLists.txt index 1a99080337f84..ced11bf418416 100644 --- a/tools/libSwiftScan/CMakeLists.txt +++ b/tools/libSwiftScan/CMakeLists.txt @@ -43,7 +43,7 @@ if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND BOOTSTRAPP ) endif() -if(SWIFT_SWIFT_PARSER) +if(SWIFT_BUILD_SWIFT_SYNTAX) if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) # Ensure that we can find the host shared libraries. set_property( diff --git a/tools/swift-plugin-server/CMakeLists.txt b/tools/swift-plugin-server/CMakeLists.txt index 1d1b88b22bd8a..34e8637089521 100644 --- a/tools/swift-plugin-server/CMakeLists.txt +++ b/tools/swift-plugin-server/CMakeLists.txt @@ -1,4 +1,4 @@ -if (SWIFT_SWIFT_PARSER) +if (SWIFT_BUILD_SWIFT_SYNTAX) # _swiftCSwiftPluginServer is just a C support library for swift-plugin-server # Don't bother to create '.a' for that. add_swift_host_library(_swiftCSwiftPluginServer OBJECT @@ -19,9 +19,9 @@ if (SWIFT_SWIFT_PARSER) SWIFT_COMPONENT compiler SWIFT_DEPENDENCIES - SwiftSyntax::SwiftSyntaxMacros - SwiftSyntax::SwiftSyntaxMacroExpansion - SwiftSyntax::SwiftCompilerPluginMessageHandling + SwiftSyntaxMacros + SwiftSyntaxMacroExpansion + SwiftCompilerPluginMessageHandling swiftLLVMJSON ) target_include_directories(swift-plugin-server PRIVATE diff --git a/utils/build-script-impl b/utils/build-script-impl index c7658ae747a0f..abd937bb508fd 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -844,16 +844,6 @@ function set_build_options_for_host() { swift_cmake_options+=( -DCOVERAGE_DB="${COVERAGE_DB}" ) - - if [[ "$(true_false ${SWIFT_EARLYSWIFTSYNTAX})" == "TRUE" ]]; then - early_swiftsyntax_build_dir="$(build_directory ${host} earlyswiftsyntax)" - swift_cmake_options+=( - -DSWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR:PATH="${early_swiftsyntax_build_dir}" - ) - lldb_cmake_options+=( - -DSWIFT_PATH_TO_EARLYSWIFTSYNTAX_BUILD_DIR:PATH="${early_swiftsyntax_build_dir}" - ) - fi } function configure_default_options() { diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py index d3cd28f0e9a55..dfe022a7624ed 100644 --- a/utils/swift_build_support/swift_build_support/build_script_invocation.py +++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py @@ -248,13 +248,15 @@ def convert_to_impl_arguments(self): if args.swift_disable_dead_stripping: args.extra_cmake_options.append('-DSWIFT_DISABLE_DEAD_STRIPPING:BOOL=TRUE') - swift_syntax_src = os.path.join(self.workspace.source_root, - "swift-syntax") - args.extra_cmake_options.append( - '-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE:PATH={}'.format(swift_syntax_src)) - if args.build_early_swiftsyntax: - impl_args += ["--swift-earlyswiftsyntax"] + swift_syntax_src = os.path.join(self.workspace.source_root, + "swift-syntax") + args.extra_cmake_options.append( + '-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE:PATH={}'.format(swift_syntax_src)) + args.extra_cmake_options.append('-DSWIFT_BUILD_SWIFT_SYNTAX:BOOL=TRUE') + if self.args.assertions: + args.extra_cmake_options.append( + '-DSWIFTSYNTAX_ENABLE_ASSERTIONS:BOOL=TRUE') # Then add subproject install flags that either skip building them /or/ # if we are going to build them and install_all is set, we also install @@ -565,9 +567,6 @@ def compute_product_pipelines(self): builder.begin_pipeline() - builder.add_product(products.EarlySwiftSyntax, - is_enabled=self.args.build_early_swiftsyntax) - # If --skip-early-swift-driver is passed in, swift will be built # as usual, but relying on its own C++-based (Legacy) driver. # Otherwise, we build an "early" swift-driver using the host diff --git a/utils/swift_build_support/swift_build_support/products/__init__.py b/utils/swift_build_support/swift_build_support/products/__init__.py index 5f4d65c7ad995..5a382b8cd68c7 100644 --- a/utils/swift_build_support/swift_build_support/products/__init__.py +++ b/utils/swift_build_support/swift_build_support/products/__init__.py @@ -14,7 +14,6 @@ from .cmark import CMark from .curl import LibCurl from .earlyswiftdriver import EarlySwiftDriver -from .earlyswiftsyntax import EarlySwiftSyntax from .foundation import Foundation from .indexstoredb import IndexStoreDB from .libcxx import LibCXX @@ -63,7 +62,6 @@ 'SwiftPM', 'SwiftDriver', 'EarlySwiftDriver', - 'EarlySwiftSyntax', 'XCTest', 'SwiftSyntax', 'SKStressTester', diff --git a/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py b/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py index 48f4e59014f1a..62c5222a54bf3 100644 --- a/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py +++ b/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py @@ -13,7 +13,6 @@ import os import sys -from . import earlyswiftsyntax from . import product from .. import shell from .. import toolchain @@ -64,11 +63,7 @@ def should_build(self, host_target): @classmethod def get_dependencies(cls): - # FIXME: This isn't a real dependency, but is necessary to linearize the - # dependency graph from Swift to EarlySwiftSyntax. If we properly - # express the dependency from Swift -> EarlySwiftSyntax, build_graph.py - # asserts that there are multiple roots to the graph. - return [earlyswiftsyntax.EarlySwiftSyntax] + return [] def should_clean(self, host_target): return self.args.clean_early_swift_driver diff --git a/utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py b/utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py deleted file mode 100644 index 37c1bede9b0bd..0000000000000 --- a/utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py +++ /dev/null @@ -1,82 +0,0 @@ -# swift_build_support/products/earlyswiftsyntax.py --------------*- python -*- -# -# This source file is part of the Swift.org open source project -# -# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors -# Licensed under Apache License v2.0 with Runtime Library Exception -# -# See https://swift.org/LICENSE.txt for license information -# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -# -# ---------------------------------------------------------------------------- - -import sys - -from . import cmake_product -from .. import toolchain - - -# SwiftSyntax is a Swift module used to parse and manipulate Swift syntax. This -# build product is a "Special" SwiftSyntax that gets built with the host -# toolchain that can be linked into the Swift compiler itself, hence it does not -# depend on any other build product of `build-script`. -class EarlySwiftSyntax(cmake_product.CMakeProduct): - @classmethod - def product_source_name(cls): - return "swift-syntax" - - @classmethod - def is_build_script_impl_product(cls): - return False - - @classmethod - def is_before_build_script_impl_product(cls): - return True - - def should_build(self, host_target): - # Temporarily disable for non-darwin since this build never works - # outside of that case currently. - if sys.platform != 'darwin' and sys.platform != 'linux': - return False - - if self.args.build_early_swiftsyntax: - if toolchain.host_toolchain().find_tool("swift") is None: - warn_msg = 'Host toolchain could not locate a '\ - 'compiler to build early swift-syntax.' - print('-- Warning: {}', warn_msg) - return False - else: - return True - return False - - @classmethod - def get_dependencies(cls): - return [] - - def build(self, host_target): - self.cmake_options.define('CMAKE_BUILD_TYPE:STRING', - self.args.swift_build_variant) - self.cmake_options.define('BUILD_SHARED_LIBS:STRING', 'YES') - - self.generate_toolchain_file_for_darwin_or_linux(host_target) - - self.cmake_options.define('CMAKE_INSTALL_PREFIX:PATH', self.args.install_prefix) - self.cmake_options.define('SWIFTSYNTAX_ENABLE_ASSERTIONS:BOOL', - self.args.assertions) - self.build_with_cmake(["all"], self.args.swift_build_variant, []) - - def should_test(self, host_target): - # The normal SwiftSyntax target runs tests through SwiftPM. - return False - - def test(self, host_target): - pass - - def should_install(self, host_target): - # When '--install-swift' is enabled, earlyswiftsyntax libraries are installed - # from 'swift' product. - return (self.should_build(host_target) and self.args.install_swiftsyntax and - "--install-swift" not in self.args.build_script_impl_args) - - def install(self, host_target): - self.install_with_cmake(["install"], self.host_install_destdir(host_target)) From 8909c8a56ea07a15d6cdd3480eff8c474ef65140 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 31 Aug 2023 13:54:19 -0700 Subject: [PATCH 02/13] [CMake] Centralize the logic to get host '-target' tripple And pass the value to 'swift-syntax', so they gets correct deployment target. --- CMakeLists.txt | 1 + cmake/modules/AddPureSwift.cmake | 15 +-------------- cmake/modules/AddSwift.cmake | 22 +++++++++++++--------- test/CMakeLists.txt | 10 +--------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99cff228a7908..6126ba850b90c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1160,6 +1160,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" AND NOT CMAKE_CROSSCOMPILING) set(CMAKE_OSX_DEPLOYMENT_TARGET "") endif() +swift_get_host_triple(SWIFT_HOST_TRIPLE) set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}") set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") if(SWIFT_BUILD_SWIFT_SYNTAX) diff --git a/cmake/modules/AddPureSwift.cmake b/cmake/modules/AddPureSwift.cmake index dd0dcb4412c61..5c31b5a0fbc89 100644 --- a/cmake/modules/AddPureSwift.cmake +++ b/cmake/modules/AddPureSwift.cmake @@ -46,20 +46,7 @@ function(_add_host_swift_compile_options name) $<$:-runtime-compatibility-version> $<$:none>) - # Set the appropriate target triple. - # FIXME: This should be set by CMake. - if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) - set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}") - endif() - - if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID") - set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL}) - endif() - - get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}" - MACCATALYST_BUILD_FLAVOR "" - DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}") - + swift_get_host_triple(target) target_compile_options(${name} PRIVATE $<$:-target;${target}>) _add_host_variant_swift_sanitizer_flags(${name}) endfunction() diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index c7125385a305c..047620f6a88a8 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -112,9 +112,7 @@ function(_add_host_variant_swift_sanitizer_flags target) endif() endfunction() -# Usage: -# _add_host_variant_c_compile_link_flags(name) -function(_add_host_variant_c_compile_link_flags name) +function(swift_get_host_triple out_var) if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}") endif() @@ -123,12 +121,21 @@ function(_add_host_variant_c_compile_link_flags name) set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL}) endif() + get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}" + MACCATALYST_BUILD_FLAVOR "" + DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}") + + set(${out_var} "${target}" PARENT_SCOPE) +endfunction() + +# Usage: +# _add_host_variant_c_compile_link_flags(name) +function(_add_host_variant_c_compile_link_flags name) + swift_get_host_triple(target) + # MSVC and gcc don't understand -target. # clang-cl understands --target. if(CMAKE_C_COMPILER_ID MATCHES "Clang") - get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}" - MACCATALYST_BUILD_FLAVOR "" - DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}") if("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC") # clang-cl options target_compile_options(${name} PRIVATE $<$:--target=${target}>) target_link_options(${name} PRIVATE $<$:--target=${target}>) @@ -139,9 +146,6 @@ function(_add_host_variant_c_compile_link_flags name) endif() if (CMAKE_Swift_COMPILER) - get_target_triple(target target_variant "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}" - MACCATALYST_BUILD_FLAVOR "" - DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}") target_compile_options(${name} PRIVATE $<$:-target;${target}>) _add_host_variant_swift_sanitizer_flags(${name}) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a2998850bb96d..f56d1a2806707 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -211,15 +211,7 @@ normalize_boolean_spelling(SWIFT_ENABLE_BACKTRACING) is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED) # Get 'SWIFT_HOST_TRIPLE' and 'SWIFT_HOST_SDKROOT' for lit.site.cfg.in -if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS) - set(DEPLOYMENT_VERSION "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_DEPLOYMENT_VERSION}") -endif() -if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID") - set(DEPLOYMENT_VERSION ${SWIFT_ANDROID_API_LEVEL}) -endif() -get_target_triple(SWIFT_HOST_TRIPLE SWIFT_HOST_TRIPLE_VARIANT "${SWIFT_HOST_VARIANT_SDK}" "${SWIFT_HOST_VARIANT_ARCH}" - MACCATALYST_BUILD_FLAVOR "" - DEPLOYMENT_VERSION "${DEPLOYMENT_VERSION}") +swift_get_host_triple(SWIFT_HOST_TRIPLE) set(SWIFT_HOST_SDKROOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}") set(profdata_merge_worker From b61538ec6123cf868068cbc7ec41b2b0d24bfc54 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 31 Aug 2023 14:01:55 -0700 Subject: [PATCH 03/13] [CMake] Remove SetRPATH.cmake This used to overwrite the RUNPATH when copying libraries from earlyswiftsyntax directory. Since earlyswiftsyntax is now replaced with FetchContent, we don't need this anymore --- CMakeLists.txt | 1 - cmake/modules/SetRPATH.cmake | 24 ------------------------ 2 files changed, 25 deletions(-) delete mode 100644 cmake/modules/SetRPATH.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6126ba850b90c..70d719df679bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -794,7 +794,6 @@ include(SwiftConfigureSDK) include(SwiftComponents) include(SwiftList) include(AddPureSwift) -include(SetRPATH) # Configure swift include, install, build components. swift_configure_components() diff --git a/cmake/modules/SetRPATH.cmake b/cmake/modules/SetRPATH.cmake deleted file mode 100644 index 76b8b4644e59a..0000000000000 --- a/cmake/modules/SetRPATH.cmake +++ /dev/null @@ -1,24 +0,0 @@ -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 '. -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() From b9ca920fb7d06ba554e1fb5705554b8d8caad7b6 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 5 Sep 2023 13:30:16 -0700 Subject: [PATCH 04/13] [CMake] update for swift-syntax change --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 70d719df679bf..f0b753548c0c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1162,6 +1162,7 @@ endif() swift_get_host_triple(SWIFT_HOST_TRIPLE) set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}") set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") +set(SWIFT_HOST_RUNTIME_DEST_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") if(SWIFT_BUILD_SWIFT_SYNTAX) if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") From 15d1b14d52dc7752e99df3d3a8e5000f32be0680 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Wed, 6 Sep 2023 19:01:23 +0000 Subject: [PATCH 05/13] [CMake] Set correct RPATH for swift-syntax libs in Linux --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0b753548c0c4..7a63395351870 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1163,6 +1163,9 @@ swift_get_host_triple(SWIFT_HOST_TRIPLE) set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}") set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") set(SWIFT_HOST_RUNTIME_DEST_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") +if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD") + set(SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}") +endif() if(SWIFT_BUILD_SWIFT_SYNTAX) if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") From 242188f89df9a368ded98342e53df3c178545737 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Mon, 11 Sep 2023 16:49:21 -0700 Subject: [PATCH 06/13] [CMake] Install swift-syntax libraries --- lib/CMakeLists.txt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 9054a85a5eb41..1e67e5ffc3346 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -12,6 +12,30 @@ # directory. list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets) +# Set up for linking against swift-syntax. +if (SWIFT_BUILD_SWIFT_SYNTAX) + set(SWIFT_SYNTAX_MODULES + SwiftBasicFormat + SwiftParser + SwiftParserDiagnostics + SwiftDiagnostics + SwiftSyntax + SwiftOperators + SwiftSyntaxBuilder + SwiftSyntaxMacros + SwiftSyntaxMacroExpansion + SwiftCompilerPluginMessageHandling + ) + + swift_install_in_component( + TARGETS ${SWIFT_SYNTAX_MODULES} + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" + COMPONENT compiler + ) + # TODO: Install for Windoes + # TODO: Install .swiftmodule +endif() + add_subdirectory(APIDigester) add_subdirectory(AST) add_subdirectory(ASTGen) From a74f6c17210d827a7b153bed89183bd5f7a0b0ac Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Tue, 12 Sep 2023 10:23:26 -0700 Subject: [PATCH 07/13] [CMake] Update swift-syntax libraries installation --- lib/CMakeLists.txt | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 1e67e5ffc3346..6c315cc811562 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,13 +27,39 @@ if (SWIFT_BUILD_SWIFT_SYNTAX) SwiftCompilerPluginMessageHandling ) - swift_install_in_component( - TARGETS ${SWIFT_SYNTAX_MODULES} - DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" - COMPONENT compiler - ) - # TODO: Install for Windoes - # TODO: Install .swiftmodule + if(CMAKE_SYSTEM_NAME MATCHES Windows) + swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES} + DESTINATION "bin" + COMPONENT compiler) + else() + swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES} + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" + COMPONENT compiler) + endif() + + # Install import libraries in Windows. + if(CMAKE_SYSTEM_NAME MATCHES Windows) + list(TRANSFORM SWIFT_SYNTAX_MODULES + PREPEND "${CMAKE_IMPORT_LIBRARY_PREFIX}" + OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) + list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES + APPEND "${CMAKE_IMPORT_LIBRARY_SUFFIX}" + OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) + list(TRANSFORM SWIFT_SYNTAX_IMPORT_LIBRARIES + PREPEND "${SWIFT_HOST_LIBRARIES_DEST_DIR}/" + OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) + swift_install_in_component(PROGRAMS "${SWIFT_SYNTAX_IMPORT_LIBRARIES}" + DESTINATION lib + COMPONENT compiler) + endif() + + foreach(module ${SWIFT_SYNTAX_MODULES}) + set(module_dir "${module}.swiftmodule") + set(module_file "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${SWIFT_HOST_MODULE_TRIPLE}.swiftinterface") + swift_install_in_component(FILES "${module_file}" + DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/${module_dir}" + COMPONENT compiler) + endforeach() endif() add_subdirectory(APIDigester) From 8cb651bb69814cc93330f34a5ba49cd1b89ac491 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Wed, 13 Sep 2023 14:22:49 -0700 Subject: [PATCH 08/13] [CMake] Introduce 'swift-syntax-lib' install component So that swift-syntax host libraries can be installed independently. --- cmake/modules/SwiftComponents.cmake | 9 ++++++++- lib/CMakeLists.txt | 12 ++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cmake/modules/SwiftComponents.cmake b/cmake/modules/SwiftComponents.cmake index 5bfb3c7427693..c29f5286e1a28 100644 --- a/cmake/modules/SwiftComponents.cmake +++ b/cmake/modules/SwiftComponents.cmake @@ -65,11 +65,12 @@ # * toolchain-tools -- a subset of tools that we will install to the OSS toolchain. # * testsuite-tools -- extra tools required to run the Swift testsuite. # * static-mirror-lib -- Build the static mirror library used by SwiftStaticMirror. +# * swift-syntax-lib -- install swift-syntax libraries # * toolchain-dev-tools -- install development tools useful in a shared toolchain # * llvm-toolchain-dev-tools -- install LLVM development tools useful in a shared toolchain # * dev -- headers and libraries required to use Swift compiler as a library. set(_SWIFT_DEFINED_COMPONENTS - "autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;libexec;stdlib;stdlib-experimental;sdk-overlay;static-mirror-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers") + "autolink-driver;back-deployment;compiler;clang-builtin-headers;clang-resource-dir-symlink;clang-builtin-headers-in-clang-resource-dir;libexec;stdlib;stdlib-experimental;sdk-overlay;static-mirror-lib;swift-syntax-lib;editor-integration;tools;testsuite-tools;toolchain-tools;toolchain-dev-tools;llvm-toolchain-dev-tools;dev;license;sourcekit-xpc-service;sourcekit-inproc;swift-remote-mirror;swift-remote-mirror-headers") # The default install components include all of the defined components, except # for the following exceptions. @@ -96,6 +97,12 @@ macro(swift_configure_components) set(SWIFT_INSTALL_COMPONENTS "${_SWIFT_DEFAULT_COMPONENTS}" CACHE STRING "A semicolon-separated list of components to install from the set ${_SWIFT_DEFINED_COMPONENTS}") + # 'compiler' depends on 'swift-syntax-lib' component. + if ("compiler" IN_LIST SWIFT_INSTALL_COMPONENTS AND + NOT "swift-syntax-lib" IN_LIST SWIFT_INSTALL_COMPONENTS) + list(APPEND SWIFT_INSTALL_COMPONENTS "swift-syntax-lib") + endif() + foreach(component ${_SWIFT_DEFINED_COMPONENTS}) add_custom_target(${component}) add_llvm_install_targets(install-${component} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 6c315cc811562..3c580fd824fb0 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -27,14 +27,17 @@ if (SWIFT_BUILD_SWIFT_SYNTAX) SwiftCompilerPluginMessageHandling ) + # Install shared runtime libraries if(CMAKE_SYSTEM_NAME MATCHES Windows) swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES} + RUNTIME DESTINATION "bin" - COMPONENT compiler) + COMPONENT swift-syntax-lib) else() swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES} + LIBRARY DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host" - COMPONENT compiler) + COMPONENT swift-syntax-lib) endif() # Install import libraries in Windows. @@ -50,15 +53,16 @@ if (SWIFT_BUILD_SWIFT_SYNTAX) OUTPUT_VARIABLE SWIFT_SYNTAX_IMPORT_LIBRARIES) swift_install_in_component(PROGRAMS "${SWIFT_SYNTAX_IMPORT_LIBRARIES}" DESTINATION lib - COMPONENT compiler) + COMPONENT swift-syntax-lib) endif() + # Install Swift module interface files. foreach(module ${SWIFT_SYNTAX_MODULES}) set(module_dir "${module}.swiftmodule") set(module_file "${SWIFT_HOST_LIBRARIES_DEST_DIR}/${module_dir}/${SWIFT_HOST_MODULE_TRIPLE}.swiftinterface") swift_install_in_component(FILES "${module_file}" DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host/${module_dir}" - COMPONENT compiler) + COMPONENT swift-syntax-lib) endforeach() endif() From 1dfc10e69a3876047e1caf189526539b08dc2e79 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Mon, 18 Sep 2023 16:28:24 -0700 Subject: [PATCH 09/13] [build-script] Add back --install-swiftsyntax '--install-swift-syntax' is now a sugar of '--install-swift --swift-install-component=swift-syntax-lib' --- .../swift_build_support/build_script_invocation.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/utils/swift_build_support/swift_build_support/build_script_invocation.py b/utils/swift_build_support/swift_build_support/build_script_invocation.py index dfe022a7624ed..ffd97f9b7bcb1 100644 --- a/utils/swift_build_support/swift_build_support/build_script_invocation.py +++ b/utils/swift_build_support/swift_build_support/build_script_invocation.py @@ -445,6 +445,15 @@ def convert_to_impl_arguments(self): os.path.abspath(args.coverage_db) ] + # '--install-swiftsyntax' is a legacy form of 'swift-syntax-lib' + # install component. + if (args.install_swiftsyntax and + '--install-swift' not in args.build_script_impl_args): + impl_args += [ + "--install-swift", + "--swift-install-components=swift-syntax-lib" + ] + if args.llvm_install_components: impl_args += [ "--llvm-install-components=%s" % args.llvm_install_components From f4e7c07c795f6a894f47e85fa96e42088be78fe9 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Wed, 20 Sep 2023 16:53:54 -0700 Subject: [PATCH 10/13] [CMake] Adjust FetchContent of 'swift-syntax' * Move the logic to right before include(lib) because swift-syntax is a "lib" * Use function to limit the scope of variables for FetchContent * Use standard 'CMAKE_*_OUTPUT_DIRECTORY' instead of custom variable names. --- CMakeLists.txt | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a63395351870..53ea435750e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1162,23 +1162,6 @@ endif() swift_get_host_triple(SWIFT_HOST_TRIPLE) set(SWIFT_HOST_MODULE_TRIPLE "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_MODULE}") set(SWIFT_HOST_LIBRARIES_DEST_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/swift/host") -set(SWIFT_HOST_RUNTIME_DEST_DIR "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") -if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD") - set(SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}") -endif() -if(SWIFT_BUILD_SWIFT_SYNTAX) - if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") - message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") - endif() - - set(BUILD_SHARED_LIBS_OLD "${BUILD_SHARED_LIBS}") - set(BUILD_SHARED_LIBS ON) - FetchContent_Declare(SwiftSyntax - SOURCE_DIR "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}" - ) - FetchContent_MakeAvailable(SwiftSyntax) - set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_OLD}") -endif() if(SWIFT_INCLUDE_TOOLS) message(STATUS "Building host Swift tools for ${SWIFT_HOST_VARIANT_SDK} ${SWIFT_HOST_VARIANT_ARCH}") @@ -1332,6 +1315,33 @@ endif() add_subdirectory(include) if(SWIFT_INCLUDE_TOOLS) + # Include 'swift-syntax'. + # This is a function because we want to set some 'CMAKE_*' variables temporarily.' + # TODO: Replace this with 'block()' after CMake 3.25 + function(include_swift_syntax) + if(NOT SWIFT_BUILD_SWIFT_SYNTAX) + return() + endif() + if(NOT EXISTS "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}") + message(SEND_ERROR "swift-syntax is required to build the Swift compiler. Please run update-checkout or specify SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE") + return() + endif() + + set(BUILD_SHARED_LIBS ON) + # All libraries in 'swift-syntax' goes to 'lib/swift/host'. + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}") + if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD") + set(SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}") + endif() + + FetchContent_Declare(SwiftSyntax + SOURCE_DIR "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}" + ) + FetchContent_MakeAvailable(SwiftSyntax) + endfunction() + include_swift_syntax() + add_subdirectory(lib) # SwiftCompilerSources must come before "tools". From f8f7109f7e2ec7499929f3d7cb78d69ae573dade Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 21 Sep 2023 09:59:17 -0700 Subject: [PATCH 11/13] [CMake] Use global SWIFT_HOST_TRIPLE consistently Instead of calling 'get_swift_host_triple()' repeatedly, because it always return the same value. --- cmake/modules/AddPureSwift.cmake | 3 +-- cmake/modules/AddSwift.cmake | 12 +++++------- test/CMakeLists.txt | 3 +-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cmake/modules/AddPureSwift.cmake b/cmake/modules/AddPureSwift.cmake index 5c31b5a0fbc89..44b9525fb69d6 100644 --- a/cmake/modules/AddPureSwift.cmake +++ b/cmake/modules/AddPureSwift.cmake @@ -46,8 +46,7 @@ function(_add_host_swift_compile_options name) $<$:-runtime-compatibility-version> $<$:none>) - swift_get_host_triple(target) - target_compile_options(${name} PRIVATE $<$:-target;${target}>) + target_compile_options(${name} PRIVATE $<$:-target;${SWIFT_HOST_TRIPLE}>) _add_host_variant_swift_sanitizer_flags(${name}) endfunction() diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index 047620f6a88a8..d06a14f404756 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -131,22 +131,20 @@ endfunction() # Usage: # _add_host_variant_c_compile_link_flags(name) function(_add_host_variant_c_compile_link_flags name) - swift_get_host_triple(target) - # MSVC and gcc don't understand -target. # clang-cl understands --target. if(CMAKE_C_COMPILER_ID MATCHES "Clang") if("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC") # clang-cl options - target_compile_options(${name} PRIVATE $<$:--target=${target}>) - target_link_options(${name} PRIVATE $<$:--target=${target}>) + target_compile_options(${name} PRIVATE $<$:--target=${SWIFT_HOST_TRIPLE}>) + target_link_options(${name} PRIVATE $<$:--target=${SWIFT_HOST_TRIPLE}>) else() - target_compile_options(${name} PRIVATE $<$:-target;${target}>) - target_link_options(${name} PRIVATE $<$:-target;${target}>) + target_compile_options(${name} PRIVATE $<$:-target;${SWIFT_HOST_TRIPLE}>) + target_link_options(${name} PRIVATE $<$:-target;${SWIFT_HOST_TRIPLE}>) endif() endif() if (CMAKE_Swift_COMPILER) - target_compile_options(${name} PRIVATE $<$:-target;${target}>) + target_compile_options(${name} PRIVATE $<$:-target;${SWIFT_HOST_TRIPLE}>) _add_host_variant_swift_sanitizer_flags(${name}) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f56d1a2806707..96411667cb4ec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -210,8 +210,7 @@ normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_OBJC_INTEROP) normalize_boolean_spelling(SWIFT_ENABLE_BACKTRACING) is_build_type_optimized("${SWIFT_STDLIB_BUILD_TYPE}" SWIFT_OPTIMIZED) -# Get 'SWIFT_HOST_TRIPLE' and 'SWIFT_HOST_SDKROOT' for lit.site.cfg.in -swift_get_host_triple(SWIFT_HOST_TRIPLE) +# Get 'SWIFT_HOST_SDKROOT' for lit.site.cfg.in set(SWIFT_HOST_SDKROOT "${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH}") set(profdata_merge_worker From 0165f0979f10f599a4a5c976c8c042b9f3805033 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 21 Sep 2023 10:35:31 -0700 Subject: [PATCH 12/13] [CMake] Improve argument list handling of force_target_link_libraries The argument list handling was a hack and confusing. --- cmake/modules/AddPureSwift.cmake | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cmake/modules/AddPureSwift.cmake b/cmake/modules/AddPureSwift.cmake index 44b9525fb69d6..953c607947fc0 100644 --- a/cmake/modules/AddPureSwift.cmake +++ b/cmake/modules/AddPureSwift.cmake @@ -2,17 +2,15 @@ include(macCatalystUtils) # Workaround a cmake bug, see the corresponding function in swift-syntax function(force_target_link_libraries TARGET) - cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN}) - - foreach(DEPENDENCY ${ARGS_PUBLIC}) - target_link_libraries(${TARGET} PRIVATE ${DEPENDENCY}) - add_dependencies(${TARGET} ${DEPENDENCY}) + target_link_libraries(${TARGET} ${ARGN}) + cmake_parse_arguments(ARGS "PUBLIC;PRIVATE;INTERFACE" "" "" ${ARGN}) + foreach(DEPENDENCY ${ARGS_UNPARSED_ARGUMENTS}) string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY}) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift DEPENDS ${DEPENDENCY} - ) + ) target_sources(${TARGET} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift ) From e2625bd396e0c719fa56dccfb968b85c51847ec6 Mon Sep 17 00:00:00 2001 From: Rintaro Ishizaki Date: Thu, 21 Sep 2023 11:34:38 -0700 Subject: [PATCH 13/13] [CMake] Set 'CMAKE_Swift_COMPILER_TARGET' for swift-syntax --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53ea435750e4e..726758e7143d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1327,6 +1327,7 @@ if(SWIFT_INCLUDE_TOOLS) return() endif() + set(CMAKE_Swift_COMPILER_TARGET ${SWIFT_HOST_TRIPLE}) set(BUILD_SHARED_LIBS ON) # All libraries in 'swift-syntax' goes to 'lib/swift/host'. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")