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 2eeaf61e37423..e052c618fe5f8 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.
@@ -697,10 +698,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")
@@ -800,7 +800,6 @@ include(SwiftConfigureSDK)
 include(SwiftComponents)
 include(SwiftList)
 include(AddPureSwift)
-include(SetRPATH)
 
 # Configure swift include, install, build components.
 swift_configure_components()
@@ -836,7 +835,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
@@ -844,6 +843,14 @@ elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_SWIFT_PARSER)
   set(SWIFT_EXEC_FOR_SWIFT_MODULES "${CMAKE_Swift_COMPILER}")
 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()
+
 if(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|.*-WITH-HOSTLIBS")
   if(SWIFT_ENABLE_ARRAY_COW_CHECKS)
     message(STATUS "array COW checks disabled when building the swift modules with host libraries")
@@ -950,25 +957,6 @@ if(XCODE)
   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()
-  endif()
-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.
@@ -1169,13 +1157,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")
@@ -1326,6 +1318,35 @@ 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()
+
+    file(TO_CMAKE_PATH "${SWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE}" swift_syntax_path)
+    FetchContent_Declare(SwiftSyntax
+      SOURCE_DIR "${swift_syntax_path}"
+    )
+    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 ad177634dbca9..2fed86ca12abf 100644
--- a/swift/cmake/modules/AddPureSwift.cmake
+++ b/swift/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
     )
@@ -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()
 
   if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component)
     add_dependencies(${APSHT_SWIFT_COMPONENT} ${name})
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index e0fb5de09f257..58f94846fa699 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -113,9 +113,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()
@@ -124,26 +122,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()
@@ -439,7 +441,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()
@@ -576,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.*")
@@ -654,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()
 
@@ -700,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.
   #
@@ -922,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()
 
@@ -961,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/swift/cmake/modules/AddSwiftUnittests.cmake b/swift/cmake/modules/AddSwiftUnittests.cmake
index 45acb9bf10698..78a84e6ec5821 100644
--- a/swift/cmake/modules/AddSwiftUnittests.cmake
+++ b/swift/cmake/modules/AddSwiftUnittests.cmake
@@ -111,10 +111,31 @@ function(add_swift_unittest test_dirname)
     endif()
   endif()
 
-  if (SWIFT_SWIFT_PARSER AND NOT ASU_IS_TARGET_TEST)
+  file(RELATIVE_PATH relative_lib_path "${CMAKE_CURRENT_BINARY_DIR}" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")
+
+  if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
+    set_property(
+      TARGET ${test_dirname}
+      APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}")
+  elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
+    set_property(
+      TARGET ${test_dirname}
+      APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}")
+  endif()
+
+  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)
+    _add_swift_runtime_link_flags(${test_dirname} "${relative_lib_path}" "")
+
+    if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
+      set_property(
+        TARGET ${test_dirname}
+        APPEND PROPERTY INSTALL_RPATH "@executable_path/${relative_lib_path}/swift/host")
+    elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
+      set_property(
+        TARGET ${test_dirname}
+        APPEND PROPERTY INSTALL_RPATH "$ORIGIN/${relative_lib_path}/swift/host")
+    endif()
   endif()
 endfunction()
 
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 c8793e6d10ecb..5c7af5d85ee12 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 b80782f838e52..2628124156dfd 100644
--- a/swift/lib/ASTGen/CMakeLists.txt
+++ b/swift/lib/ASTGen/CMakeLists.txt
@@ -24,15 +24,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 7d61c18522a1c..8c59a9292688f 100644
--- a/swift/lib/CMakeLists.txt
+++ b/swift/lib/CMakeLists.txt
@@ -16,9 +16,7 @@ list(APPEND LLVM_COMMON_DEPENDS intrinsics_gen clang-tablegen-targets)
 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,130 +30,43 @@ 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)
-
-  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()
-
+  # Install shared runtime libraries
   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()
+    swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES}
+                               RUNTIME
+                               DESTINATION "bin"
+                               COMPONENT swift-syntax-lib)
+  else()
+    swift_install_in_component(TARGETS ${SWIFT_SYNTAX_MODULES}
+                               LIBRARY
+                               DESTINATION "lib${LLVM_LIBDIR_SUFFIX}/swift/host"
+                               COMPONENT swift-syntax-lib)
   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
-    )
+  # 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 swift-syntax-lib)
+  endif()
 
-    add_dependencies(swiftSyntaxLibraries copy_swiftSyntaxModule_${module_dir})
+  # 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 swift-syntax-lib)
   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 21ef5231ce3ac..a75be05e4feef 100644
--- a/swift/lib/Frontend/CMakeLists.txt
+++ b/swift/lib/Frontend/CMakeLists.txt
@@ -34,9 +34,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 eaa246940ccd0..f3e2e53834ce2 100644
--- a/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp
+++ b/swift/lib/Frontend/PrintingDiagnosticConsumer.cpp
@@ -964,7 +964,7 @@ static void annotateSnippetWithInfo(SourceManager &SM,
   }
 }
 
-#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
@@ -1038,7 +1038,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];
@@ -1103,7 +1103,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()) {
@@ -1190,7 +1190,7 @@ void PrintingDiagnosticConsumer::flush(bool includeTrailingBreak) {
     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 2cc7a2477e979..e76e64b6af883 100644
--- a/swift/lib/IDE/CodeCompletion.cpp
+++ b/swift/lib/IDE/CodeCompletion.cpp
@@ -1142,7 +1142,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 cdae5b4443322..98344c7c98582 100644
--- a/swift/lib/Parse/ParseDecl.cpp
+++ b/swift/lib/Parse/ParseDecl.cpp
@@ -162,7 +162,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(void *sourceFile,
 ///     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 f3cdbffcbfc18..4f95db5553219 100644
--- a/swift/lib/Sema/CMakeLists.txt
+++ b/swift/lib/Sema/CMakeLists.txt
@@ -87,10 +87,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 77b0d7e2cd3a9..8317b9027c832 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 f50b7d8fee110..037ad6db8bdff 100644
--- a/swift/lib/Sema/CSGen.cpp
+++ b/swift/lib/Sema/CSGen.cpp
@@ -1267,7 +1267,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 9d599b54c4b95..4861eb726b27e 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)) {
@@ -380,7 +380,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);
@@ -404,7 +404,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)) {
@@ -975,7 +975,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
@@ -1036,7 +1036,7 @@ evaluateFreestandingMacro(FreestandingMacroExpansion *expansion,
       return nullptr;
     }
 
-#if SWIFT_SWIFT_PARSER
+#if SWIFT_BUILD_SWIFT_SYNTAX
     PrettyStackTraceFreestandingMacroExpansion debugStack(
         "expanding freestanding macro", expansion);
 
@@ -1215,7 +1215,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
@@ -1294,7 +1294,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 d2d5f71ded49a..52ea7dc00842a 100644
--- a/swift/test/CMakeLists.txt
+++ b/swift/test/CMakeLists.txt
@@ -205,18 +205,10 @@ normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_UNICODE_DATA)
 normalize_boolean_spelling(SWIFT_ENABLE_DISPATCH)
 normalize_boolean_spelling(SWIFT_STDLIB_ENABLE_OBJC_INTEROP)
 normalize_boolean_spelling(SWIFT_ENABLE_BACKTRACING)
+normalize_boolean_spelling(SWIFT_BUILD_SWIFT_SYNTAX)
 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/IDE/complete_pound_expr.swift b/swift/test/IDE/complete_pound_expr.swift
index bb074a1ab0d26..4bfd862f00d68 100644
--- a/swift/test/IDE/complete_pound_expr.swift
+++ b/swift/test/IDE/complete_pound_expr.swift
@@ -1,7 +1,7 @@
 // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=POUND_EXPR_1 | %FileCheck %s -check-prefix=POUND_EXPR_INTCONTEXT
 // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=POUND_EXPR_2 | %FileCheck %s -check-prefix=POUND_EXPR_STRINGCONTEXT
 // RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=POUND_EXPR_3 | %FileCheck %s -check-prefix=POUND_EXPR_SELECTORCONTEXT
-// REQUIRES: objc_interop
+// REQUIRES: objc_interop, swift_swift_parser
 
 import ObjectiveC
 
diff --git a/swift/test/Macros/extension_macro_plugin.swift b/swift/test/Macros/extension_macro_plugin.swift
index 5204d9c74fb4b..eaf90a366c231 100644
--- a/swift/test/Macros/extension_macro_plugin.swift
+++ b/swift/test/Macros/extension_macro_plugin.swift
@@ -1,5 +1,4 @@
-// FIXME: Swift parser is not enabled on Linux CI yet.
-// REQUIRES: OS=macosx
+// REQUIRES: swift_swift_parser
 
 // RUN: %empty-directory(%t)
 // RUN: %empty-directory(%t/plugins)
@@ -13,7 +12,7 @@
 // RUN:   %S/Inputs/syntax_macro_definitions.swift \
 // RUN:   -g -no-toolchain-stdlib-rpath
 
-// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
+// RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
 // RUN:   -typecheck -verify \
 // RUN:   -swift-version 5 -enable-experimental-feature ExtensionMacros \
 // RUN:   -external-plugin-path %t/plugins#%swift-plugin-server \
diff --git a/swift/test/Macros/macro_plugin_server.swift b/swift/test/Macros/macro_plugin_server.swift
index dfdd12874b30a..91d45c30e1c82 100644
--- a/swift/test/Macros/macro_plugin_server.swift
+++ b/swift/test/Macros/macro_plugin_server.swift
@@ -1,5 +1,4 @@
-// FIXME: Swift parser is not enabled on Linux CI yet.
-// REQUIRES: OS=macosx
+// REQUIRES: swift_swift_parser
 
 // RUN: %empty-directory(%t)
 // RUN: %empty-directory(%t/plugins)
@@ -21,7 +20,7 @@
 // RUN:   %S/Inputs/evil_macro_definitions.swift \
 // RUN:   -g -no-toolchain-stdlib-rpath
 
-// RUN: SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
+// RUN: env SWIFT_DUMP_PLUGIN_MESSAGING=1 %swift-target-frontend \
 // RUN:   -typecheck -verify \
 // RUN:   -swift-version 5 -enable-experimental-feature Macros \
 // RUN:   -external-plugin-path %t/plugins#%swift-plugin-server \
@@ -33,9 +32,9 @@
 
 // CHECK: ->(plugin:[[#PID1:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION:]]}}}
 // CHECK-NEXT: <-(plugin:[[#PID1]]) {"getCapabilityResult":{"capability":{"features":["load-plugin-library"],"protocolVersion":[[#PROTOCOL_VERSION]]}}}
-// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
+// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"{{.*}}MacroDefinition.{{dylib|so|dll}}","moduleName":"MacroDefinition"}}
 // CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
-// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
+// CHECK-NEXT: ->(plugin:[[#PID1]]) {"loadPluginLibrary":{"libraryPath":"{{.*}}EvilMacros.{{dylib|so|dll}}","moduleName":"EvilMacros"}}
 // CHECK-NEXT: <-(plugin:[[#PID1]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
 // CHECK-NEXT: ->(plugin:[[#PID1]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(a + b)"}}}
 // CHECK-NEXT: <-(plugin:[[#PID1]]) {"expandMacroResult":{"diagnostics":[],"expandedSource":"(a + b, \"a + b\")"}}
@@ -44,9 +43,9 @@
 
 // CHECK: ->(plugin:[[#PID2:]]) {"getCapability":{"capability":{"protocolVersion":[[#PROTOCOL_VERSION]]}}}
 // CHECK-NEXT: <-(plugin:[[#PID2]]) {"getCapabilityResult":{"capability":{"features":["load-plugin-library"],"protocolVersion":[[#PROTOCOL_VERSION]]}}}
-// CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libMacroDefinition.dylib","moduleName":"MacroDefinition"}}
+// CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"{{.*}}MacroDefinition.{{dylib|so|dll}}","moduleName":"MacroDefinition"}}
 // CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
-// CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"BUILD_DIR{{.*}}plugins/libEvilMacros.dylib","moduleName":"EvilMacros"}}
+// CHECK-NEXT: ->(plugin:[[#PID2]]) {"loadPluginLibrary":{"libraryPath":"{{.*}}EvilMacros.{{dylib|so|dll}}","moduleName":"EvilMacros"}}
 // CHECK-NEXT: <-(plugin:[[#PID2]]) {"loadPluginLibraryResult":{"diagnostics":[],"loaded":true}}
 // CHECK-NEXT: ->(plugin:[[#PID2]]) {"expandFreestandingMacro":{"discriminator":"${{.*}}","macro":{"moduleName":"MacroDefinition","name":"stringify","typeName":"StringifyMacro"},"macroRole":"expression","syntax":{"kind":"expression","location":{{{.+}}},"source":"#stringify(b + a)"}}}
 // CHECK-NEXT: <-(plugin:[[#PID2]]) {"expandMacroResult":{"diagnostics":[],"expandedSource":"(b + a, \"b + a\")"}}
diff --git a/swift/test/lit.site.cfg.in b/swift/test/lit.site.cfg.in
index 06af9476c7f12..740a08c33bc7b 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 5514431eea9ce..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()
@@ -115,12 +115,6 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
                    LINK_FLAGS " -lobjc ")
 
     endif() # HAS_SWIFT_MODULES AND ASKD_BOOTSTRAPPING_MODE
-
-    if(SWIFT_SWIFT_PARSER)
-      # Add rpath to the host Swift libraries.
-      file(RELATIVE_PATH relative_hostlib_path "${path}" "${SWIFTLIB_DIR}/host")
-      list(APPEND RPATH_LIST "@loader_path/${relative_hostlib_path}")
-    endif()
   elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD" AND HAS_SWIFT_MODULES AND ASKD_BOOTSTRAPPING_MODE)
     set(swiftrt "swiftImageRegistrationObject${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_OBJECT_FORMAT}-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}")
     if(ASKD_BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|CROSSCOMPILE")
@@ -156,18 +150,22 @@ function(add_sourcekit_swift_runtime_link_flags target path HAS_SWIFT_MODULES)
     else()
       message(FATAL_ERROR "Unknown ASKD_BOOTSTRAPPING_MODE '${ASKD_BOOTSTRAPPING_MODE}'")
     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")
+      list(APPEND RPATH_LIST "@loader_path/${relative_hostlib_path}")
+    elseif(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD")
       # 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}")
+    else()
+      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})
     endif()
-  else()
-    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})
-  endif()
 
-  if(SWIFT_SWIFT_PARSER)
     # For the "end step" of bootstrapping configurations on Darwin, need to be
     # able to fall back to the SDK directory for libswiftCore et al.
     if (BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
@@ -263,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()
 
@@ -367,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()
 
@@ -439,7 +437,6 @@ macro(add_sourcekit_framework name)
     file(RELATIVE_PATH relative_lib_path
       "${framework_location}/Versions/A" "${SOURCEKIT_LIBRARY_OUTPUT_INTDIR}")
     list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}")
-    list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}/swift/host")
 
     set_target_properties(${name} PROPERTIES
                           BUILD_WITH_INSTALL_RPATH TRUE
@@ -475,7 +472,6 @@ macro(add_sourcekit_framework name)
     file(RELATIVE_PATH relative_lib_path
       "${framework_location}" "${SOURCEKIT_LIBRARY_OUTPUT_INTDIR}")
     list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}")
-    list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}/swift/host")
 
     set_target_properties(${name} PROPERTIES
                           BUILD_WITH_INSTALL_RPATH TRUE
@@ -567,7 +563,6 @@ macro(add_sourcekit_xpc_service name framework_target)
 
   file(RELATIVE_PATH relative_lib_path "${xpc_bin_dir}" "${lib_dir}")
   list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}")
-  list(APPEND RPATH_LIST "@loader_path/${relative_lib_path}/swift/host")
 
   # Add rpath for sourcekitdInProc
   # lib/${framework_target}.framework/Versions/A/XPCServices/${name}.xpc/Contents/MacOS/${name}
diff --git a/swift/tools/driver/CMakeLists.txt b/swift/tools/driver/CMakeLists.txt
index 9c2e5ed6486a9..f6ceb3dae63d8 100644
--- a/swift/tools/driver/CMakeLists.txt
+++ b/swift/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/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)
     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/swift/utils/build-script-impl b/swift/utils/build-script-impl
index 4a243bd7cab5e..4d388a96e3ed1 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -836,16 +836,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 4d70897286f6a..166c5ea02cced 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
@@ -251,13 +251,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
@@ -446,6 +448,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
@@ -568,9 +579,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 40fd43960af40..3294929bd1585 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
@@ -15,7 +15,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
@@ -65,7 +64,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,83 +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.cmake_options.define('SWIFT_MODULE_ABI_NAME_PREFIX:STRING', 'Compiler')
-        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))
