termux-packages/packages/swift/swift-move-syntax-build.patch

1366 lines
55 KiB
Diff

From 62b0c38c93e0feb589b1e9b915831f45118a3ace
From: Ben Barham <ben_barham@apple.com>
Date: Tue, 16 May 2023 16:25:12 -0700
Subject: [PATCH 1/7] [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.
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index 9a460b731d019..726758e7143d3 100644
--- a/swift/CMakeLists.txt
+++ b/swift/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($<$<COMPILE_LANGUAGE:CXX>:-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)
@@ -794,7 +794,6 @@ include(SwiftConfigureSDK)
include(SwiftComponents)
include(SwiftList)
include(AddPureSwift)
-include(SetRPATH)
# Configure swift include, install, build components.
swift_configure_components()
@@ -830,7 +829,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 +837,11 @@ elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER)
set(SWIFT_SDKS "OSX")
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()
@@ -1171,13 +1159,17 @@ 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_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")
@@ -1323,6 +1315,34 @@ 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(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}")
+ 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/../..")
+ 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".
diff --git a/swift/cmake/modules/AddPureSwift.cmake b/swift/cmake/modules/AddPureSwift.cmake
index 6c79fdcf351ce..953c607947fc0 100644
--- a/swift/cmake/modules/AddPureSwift.cmake
+++ b/swift/cmake/modules/AddPureSwift.cmake
@@ -2,18 +2,14 @@ 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})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
DEPENDS ${DEPENDENCY}
- )
+ )
target_sources(${TARGET} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
)
@@ -46,21 +44,7 @@ function(_add_host_swift_compile_options name)
$<$<COMPILE_LANGUAGE:Swift>:-runtime-compatibility-version>
$<$<COMPILE_LANGUAGE:Swift>: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}")
-
- target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${target}>)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE}>)
_add_host_variant_swift_sanitizer_flags(${name})
endfunction()
@@ -121,7 +105,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 +180,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 +220,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 +233,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 +254,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 +314,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()
# Export this target.
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index b55f7d8071656..d06a14f404756 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/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,26 +121,30 @@ 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)
# 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 $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:--target=${target}>)
- target_link_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:--target=${target}>)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:--target=${SWIFT_HOST_TRIPLE}>)
+ target_link_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:--target=${SWIFT_HOST_TRIPLE}>)
else()
- target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-target;${target}>)
- target_link_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-target;${target}>)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-target;${SWIFT_HOST_TRIPLE}>)
+ target_link_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-target;${SWIFT_HOST_TRIPLE}>)
endif()
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 $<$<COMPILE_LANGUAGE:Swift>:-target;${target}>)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE}>)
_add_host_variant_swift_sanitizer_flags(${name})
endif()
@@ -442,7 +444,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 +580,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
endif()
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 +658,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 +704,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 +926,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 +965,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/swift/cmake/modules/AddSwiftUnittests.cmake b/swift/cmake/modules/AddSwiftUnittests.cmake
index b3ed5ef8a391f..78a84e6ec5821 100644
--- a/swift/cmake/modules/AddSwiftUnittests.cmake
+++ b/swift/cmake/modules/AddSwiftUnittests.cmake
@@ -123,7 +123,7 @@ function(add_swift_unittest test_dirname)
endif()
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} "../../lib" "")
set_property(TARGET ${test_dirname} PROPERTY BUILD_WITH_INSTALL_RPATH OFF)
diff --git a/swift/cmake/modules/SetRPATH.cmake b/swift/cmake/modules/SetRPATH.cmake
deleted file mode 100644
index 76b8b4644e59a..0000000000000
--- a/swift/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 <scirpt>'.
-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()
diff --git a/swift/cmake/modules/SwiftComponents.cmake b/swift/cmake/modules/SwiftComponents.cmake
index 5bfb3c7427693..c29f5286e1a28 100644
--- a/swift/cmake/modules/SwiftComponents.cmake
+++ b/swift/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/swift/lib/AST/CMakeLists.txt b/swift/lib/AST/CMakeLists.txt
index 9e5590b7315db..4bf20a642f0f8 100644
--- a/swift/lib/AST/CMakeLists.txt
+++ b/swift/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/swift/lib/ASTGen/CMakeLists.txt b/swift/lib/ASTGen/CMakeLists.txt
index f5d4a899cec73..736970051e359 100644
--- a/swift/lib/ASTGen/CMakeLists.txt
+++ b/swift/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
${ASTGen_Swift_dependencies}
)
diff --git a/swift/lib/CMakeLists.txt b/swift/lib/CMakeLists.txt
index 7a6f55c80406f..3c580fd824fb0 100644
--- a/swift/lib/CMakeLists.txt
+++ b/swift/lib/CMakeLists.txt
@@ -13,9 +13,7 @@
list(APPEND LLVM_COMMON_DEPENDS swift-ast-generated-headers)
# 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.
+if (SWIFT_BUILD_SWIFT_SYNTAX)
set(SWIFT_SYNTAX_MODULES
SwiftBasicFormat
SwiftParser
@@ -32,104 +30,39 @@ if (SWIFT_SWIFT_PARSER)
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)
-
- # 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()
-
- 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
- )
-
- add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxLibrary_${sharedlib})
+ 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()
-
- # 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)
diff --git a/swift/lib/Frontend/CMakeLists.txt b/swift/lib/Frontend/CMakeLists.txt
index c01fdcf7e174b..ebb9a2aeecabf 100644
--- a/swift/lib/Frontend/CMakeLists.txt
+++ b/swift/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/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp b/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp
index 9f6a8976c3aef..da70fa1f2f177 100644
--- a/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp
+++ b/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp
@@ -315,7 +315,7 @@ 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<unsigned, 1> 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,
currentSnippet.reset();
}
-#if SWIFT_SWIFT_PARSER
+#if SWIFT_BUILD_SWIFT_SYNTAX
if (queuedDiagnostics) {
char *renderedString = nullptr;
ptrdiff_t renderedStringLen = 0;
diff --git a/swift/lib/IDE/CodeCompletion.cpp b/swift/lib/IDE/CodeCompletion.cpp
index 362d0619152da..568d9557fe279 100644
--- a/swift/lib/IDE/CodeCompletion.cpp
+++ b/swift/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/swift/lib/Macros/CMakeLists.txt b/swift/lib/Macros/CMakeLists.txt
index 3598a4e917557..23e7de788cd47 100644
--- a/swift/lib/Macros/CMakeLists.txt
+++ b/swift/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/swift/lib/Macros/Sources/ObservationMacros/CMakeLists.txt b/swift/lib/Macros/Sources/ObservationMacros/CMakeLists.txt
index 3afd3380125aa..c3deee2c4747a 100644
--- a/swift/lib/Macros/Sources/ObservationMacros/CMakeLists.txt
+++ b/swift/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/swift/lib/Macros/Sources/SwiftMacros/CMakeLists.txt b/swift/lib/Macros/Sources/SwiftMacros/CMakeLists.txt
index 32a798260afdb..9d83b612b4987 100644
--- a/swift/lib/Macros/Sources/SwiftMacros/CMakeLists.txt
+++ b/swift/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/swift/lib/Parse/CMakeLists.txt b/swift/lib/Parse/CMakeLists.txt
index 1b66331ad7e6d..8a01e55f893b0 100644
--- a/swift/lib/Parse/CMakeLists.txt
+++ b/swift/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/swift/lib/Parse/ParseDecl.cpp b/swift/lib/Parse/ParseDecl.cpp
index 12f2bb72a10cc..50aa486a512aa 100644
--- a/swift/lib/Parse/ParseDecl.cpp
+++ b/swift/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<SmallVectorImpl<ASTNode> *>(vecPtr);
auto decl = static_cast<Decl *>(declPtr);
@@ -207,7 +207,7 @@ extern "C" void swift_ASTGen_buildTopLevelASTNodes(
/// decl-sil-stage [[only in SIL mode]
/// \endverbatim
void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
-#if SWIFT_SWIFT_PARSER
+#if SWIFT_BUILD_SWIFT_SYNTAX
llvm::Optional<DiagnosticTransaction> existingParsingTransaction;
parseSourceFileViaASTGen(items, existingParsingTransaction);
#endif
@@ -258,7 +258,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &items) {
}
}
-#if SWIFT_SWIFT_PARSER
+#if SWIFT_BUILD_SWIFT_SYNTAX
if (existingParsingTransaction)
existingParsingTransaction->abort();
@@ -310,7 +310,7 @@ void Parser::parseTopLevelItems(SmallVectorImpl<ASTNode> &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<ASTNode> &items,
llvm::Optional<DiagnosticTransaction> &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/swift/lib/Parse/ParseIfConfig.cpp b/swift/lib/Parse/ParseIfConfig.cpp
index ef10f8fdde5b8..58d991841cab3 100644
--- a/swift/lib/Parse/ParseIfConfig.cpp
+++ b/swift/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/swift/lib/Parse/ParseType.cpp b/swift/lib/Parse/ParseType.cpp
index 7d02b146bf2fd..54548243d43cf 100644
--- a/swift/lib/Parse/ParseType.cpp
+++ b/swift/lib/Parse/ParseType.cpp
@@ -601,7 +601,7 @@ extern "C" TypeRepr *swift_ASTGen_buildTypeRepr(
///
ParserResult<TypeRepr> Parser::parseType(
Diag<> MessageID, ParseTypeReason reason) {
- #if SWIFT_SWIFT_PARSER
+ #if SWIFT_BUILD_SWIFT_SYNTAX
auto astGenResult = parseASTFromSyntaxTree<TypeRepr>(
[&](void *exportedSourceFile, const void *sourceLoc) {
const void *endLocPtr = nullptr;
diff --git a/swift/lib/Sema/CMakeLists.txt b/swift/lib/Sema/CMakeLists.txt
index 16494b3ff76d2..6a80e3c20768d 100644
--- a/swift/lib/Sema/CMakeLists.txt
+++ b/swift/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/swift/lib/Sema/CSApply.cpp b/swift/lib/Sema/CSApply.cpp
index 0891865a43fcc..61b2c0eae84d5 100644
--- a/swift/lib/Sema/CSApply.cpp
+++ b/swift/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/swift/lib/Sema/CSGen.cpp b/swift/lib/Sema/CSGen.cpp
index 882349e9acf49..af0de3c9628d9 100644
--- a/swift/lib/Sema/CSGen.cpp
+++ b/swift/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/swift/lib/Sema/TypeCheckMacros.cpp b/swift/lib/Sema/TypeCheckMacros.cpp
index 5313ab221e60e..6cc8cb36ac735 100644
--- a/swift/lib/Sema/TypeCheckMacros.cpp
+++ b/swift/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<ExternalMacroDefinition>
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<ExternalMacroDefinition>
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<std::string> 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<std::string> 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/swift/test/CMakeLists.txt b/swift/test/CMakeLists.txt
index a2998850bb96d..96411667cb4ec 100644
--- a/swift/test/CMakeLists.txt
+++ b/swift/test/CMakeLists.txt
@@ -210,16 +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
-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}")
+# 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
diff --git a/swift/test/lit.site.cfg.in b/swift/test/lit.site.cfg.in
index 8544f2a22bcea..8d4414f3c5d36 100644
--- a/swift/test/lit.site.cfg.in
+++ b/swift/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/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
index 2293712165751..4b5a63fef6046 100644
--- a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake
+++ b/swift/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)
message(FATAL_ERROR "Unknown ASKD_BOOTSTRAPPING_MODE '${ASKD_BOOTSTRAPPING_MODE}'")
endif()
- if(SWIFT_SWIFT_PARSER)
+ if(SWIFT_BUILD_SWIFT_SYNTAX)
# Add rpath to the host Swift libraries.
file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
list(APPEND RPATH_LIST "$ORIGIN/${relative_hostlib_path}")
@@ -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/swift/tools/driver/CMakeLists.txt b/swift/tools/driver/CMakeLists.txt
index f08e56ee3c2f1..1b350f229d4a5 100644
--- a/swift/tools/driver/CMakeLists.txt
+++ b/swift/tools/driver/CMakeLists.txt
@@ -4,7 +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)
+ if(SWIFT_BUILD_SWIFT_SYNTAX)
target_link_libraries(${target}
PRIVATE swiftCore)
diff --git a/swift/tools/libSwiftScan/CMakeLists.txt b/swift/tools/libSwiftScan/CMakeLists.txt
index 1a99080337f84..ced11bf418416 100644
--- a/swift/tools/libSwiftScan/CMakeLists.txt
+++ b/swift/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/swift/tools/swift-plugin-server/CMakeLists.txt b/swift/tools/swift-plugin-server/CMakeLists.txt
index 1d1b88b22bd8a..34e8637089521 100644
--- a/swift/tools/swift-plugin-server/CMakeLists.txt
+++ b/swift/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)
swiftDemangling
$<TARGET_OBJECTS:_swiftCSwiftPluginServer>
SWIFT_DEPENDENCIES
- SwiftSyntax::SwiftSyntaxMacros
- SwiftSyntax::SwiftSyntaxMacroExpansion
- SwiftSyntax::SwiftCompilerPluginMessageHandling
+ SwiftSyntaxMacros
+ SwiftSyntaxMacroExpansion
+ SwiftCompilerPluginMessageHandling
swiftLLVMJSON
)
target_include_directories(swift-plugin-server PRIVATE
diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index c7658ae747a0f..abd937bb508fd 100755
--- a/swift/utils/build-script-impl
+++ b/swift/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/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
index d3cd28f0e9a55..ffd97f9b7bcb1 100644
--- a/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
+++ b/swift/utils/swift_build_support/swift_build_support/build_script_invocation.py
@@ -248,13 +248,15 @@ def convert_to_impl_arguments(self):
args.extra_cmake_options.append(
'-DSWIFT_BACK_DEPLOY_CONCURRENCY: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
@@ -443,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
@@ -565,9 +576,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/swift/utils/swift_build_support/swift_build_support/products/__init__.py b/swift/utils/swift_build_support/swift_build_support/products/__init__.py
index 5f4d65c7ad995..5a382b8cd68c7 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/__init__.py
+++ b/swift/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/swift/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py b/swift/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py
index 48f4e59014f1a..62c5222a54bf3 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/earlyswiftdriver.py
+++ b/swift/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/swift/utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py b/swift/utils/swift_build_support/swift_build_support/products/earlyswiftsyntax.py
deleted file mode 100644
index 37c1bede9b0bd..0000000000000
--- a/swift/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):
- # The artifacts are copied to build directory of 'swift' and are
- # installed as a part of 'swift' product.
- return False
-
- def install(self, host_target):
- # No-op.
- pass