bump(swift): 5.8.1 to 5.9

Also, pull in some upstream patches to get the new Macros feature working.
This commit is contained in:
Finagolfin 2023-09-29 19:27:21 +05:30 committed by finagolfin
parent 837de75d9d
commit 6f442f6476
27 changed files with 7176 additions and 132 deletions

View File

@ -2,8 +2,7 @@ TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-corelibs-libdispatch
TERMUX_PKG_DESCRIPTION="The libdispatch project, for concurrency on multicore hardware"
TERMUX_PKG_LICENSE="Apache-2.0"
TERMUX_PKG_MAINTAINER="@finagolfin"
TERMUX_PKG_VERSION="1:5.8"
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION="1:5.9"
TERMUX_PKG_SRCURL=https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${TERMUX_PKG_VERSION:2}-RELEASE.tar.gz
TERMUX_PKG_SHA256=391d2bcaea22c4aa980400c3a29b3d9991641aa62253b693c0b79c302eafd5a0
TERMUX_PKG_SHA256=db30ccf6b20963112ab3aad256c2e49a18041a9806cf2f05854fe63a90d688c2
TERMUX_PKG_DEPENDS="libc++, libblocksruntime"

View File

@ -0,0 +1,14 @@
diff --git a/dispatch/dispatch.h b/dispatch/dispatch.h
index 0c7bdd4..35cb91d 100644
--- a/dispatch/dispatch.h
+++ b/dispatch/dispatch.h
@@ -39,6 +39,9 @@
#include <stdarg.h>
#include <string.h>
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <unistd.h>
#endif
#include <fcntl.h>

View File

@ -2,7 +2,8 @@ TERMUX_PKG_HOMEPAGE=https://github.com/apple/swift-llbuild
TERMUX_PKG_DESCRIPTION="A low-level build system, used by the Swift Package Manager"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_MAINTAINER="@finagolfin"
TERMUX_PKG_VERSION=5.8
TERMUX_PKG_VERSION=5.9
TERMUX_PKG_SRCURL=https://github.com/apple/swift-llbuild/archive/swift-${TERMUX_PKG_VERSION}-RELEASE.tar.gz
TERMUX_PKG_SHA256=6345ae69ac9b8bb61b61f14871b322f83b1d08f70c261bd9a2f86a998c394c0c
TERMUX_PKG_SHA256=cc8dfb098db4b0210ca5466f59d3e5fc55c4eedcd835263e6eae7dd719ba8203
TERMUX_PKG_DEPENDS="libc++, libandroid-spawn, libsqlite"
TERMUX_PKG_NO_STATICSPLIT=true

View File

@ -0,0 +1,14 @@
diff --git a/products/libllbuild/include/llbuild/buildsystem.h b/products/libllbuild/include/llbuild/buildsystem.h
index d75b9cc3..3c7ccc7b 100644
--- a/products/libllbuild/include/llbuild/buildsystem.h
+++ b/products/libllbuild/include/llbuild/buildsystem.h
@@ -40,6 +40,9 @@ typedef HANDLE FD;
#else
#include <sys/types.h>
#endif // defined(__linux__) || defined(__GNU__)
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <unistd.h>
typedef pid_t llbuild_pid_t;
typedef int FD;

View File

@ -0,0 +1,56 @@
diff --git a/swift-corelibs-libdispatch/dispatch/dispatch.h b/swift-corelibs-libdispatch/dispatch/dispatch.h
index 0c7bdd4..35cb91d 100644
--- a/swift-corelibs-libdispatch/dispatch/dispatch.h
+++ b/swift-corelibs-libdispatch/dispatch/dispatch.h
@@ -39,6 +39,9 @@
#include <stdarg.h>
#include <string.h>
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <unistd.h>
#endif
#include <fcntl.h>
diff --git a/llbuild/products/libllbuild/include/llbuild/buildsystem.h b/llbuild/products/libllbuild/include/llbuild/buildsystem.h
index d75b9cc3..3c7ccc7b 100644
--- a/llbuild/products/libllbuild/include/llbuild/buildsystem.h
+++ b/llbuild/products/libllbuild/include/llbuild/buildsystem.h
@@ -40,6 +40,9 @@ typedef HANDLE FD;
#else
#include <sys/types.h>
#endif // defined(__linux__) || defined(__GNU__)
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <unistd.h>
typedef pid_t llbuild_pid_t;
typedef int FD;
diff --git a/swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h b/swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
index fb8ddab..4553ab0 100644
--- a/swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
+++ b/swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
@@ -17,6 +17,9 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <time.h>
/**
diff --git a/swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h b/swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
index 652fb89..c10e8ce 100644
--- a/swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
+++ b/swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
@@ -60,6 +60,9 @@
#include "CCryptoBoringSSL_base.h"
+#if defined(__ANDROID__)
+#include <signal.h>
+#endif
#include <time.h>
#include "CCryptoBoringSSL_bio.h"

View File

@ -2,14 +2,13 @@ TERMUX_PKG_HOMEPAGE=https://swift.org/
TERMUX_PKG_DESCRIPTION="Swift is a high-performance system programming language"
TERMUX_PKG_LICENSE="Apache-2.0, NCSA"
TERMUX_PKG_MAINTAINER="@finagolfin"
TERMUX_PKG_VERSION=5.8.1
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION=5.9
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=f65381a9dfea4579323e5aff04d4224f2d8f505fcc6e3e83022e734d4f54575f
TERMUX_PKG_SHA256=2f57327bfab410b3d1e0aff36ece0b9768c5813004d96e9e0f0c1bd0342c4f73
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_DEPENDS="clang, libandroid-glob, libandroid-posix-semaphore, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild, swift-sdk-${TERMUX_ARCH/_/-}"
TERMUX_PKG_DEPENDS="clang, libandroid-glob, libandroid-posix-semaphore, libandroid-spawn, libcurl, libicu, libicu-static, libsqlite, libuuid, libxml2, libdispatch, llbuild, pkg-config, swift-sdk-${TERMUX_ARCH/_/-}"
TERMUX_PKG_BUILD_DEPENDS="rsync"
TERMUX_PKG_BLACKLISTED_ARCHES="i686"
TERMUX_PKG_NO_STATICSPLIT=true
@ -21,8 +20,8 @@ TERMUX_PKG_FORCE_CMAKE=true
TERMUX_CMAKE_BUILD=Ninja
SWIFT_COMPONENTS="autolink-driver;compiler;clang-resource-dir-symlink;swift-remote-mirror;license;sourcekit-inproc;static-mirror-lib;stdlib;sdk-overlay"
SWIFT_TOOLCHAIN_FLAGS="-RA --llvm-targets-to-build='X86;ARM;AArch64' -j $TERMUX_MAKE_PROCESSES"
SWIFT_PATH_FLAGS="--build-subdir=. --install-destdir=/ --install-prefix=$TERMUX_PREFIX"
SWIFT_TOOLCHAIN_FLAGS="-RA --llvm-targets-to-build='X86;ARM;AArch64' -j $TERMUX_MAKE_PROCESSES --install-prefix=$TERMUX_PREFIX"
SWIFT_PATH_FLAGS="--build-subdir=. --install-destdir=/"
SWIFT_BUILD_FLAGS="$SWIFT_TOOLCHAIN_FLAGS $SWIFT_PATH_FLAGS"
SWIFT_ARCH=$TERMUX_ARCH
@ -36,35 +35,43 @@ termux_step_post_get_source() {
mv .temp swift
declare -A library_checksums
library_checksums[swift-cmark]=89ad876b686192b806c61b390b076cf3cbb6459af6acdd3e93cd1e3d8a74c7f6
library_checksums[llvm-project]=f4b6a4b1589d48fa2295d2709b99d1bfbbc6bfb2778dc72a4d72da3c25ff5d92
library_checksums[swift-experimental-string-processing]=83714d2178d2a02de35e75dbe11ff2443695a65aaf1136e5a7b9f152716e75a6
library_checksums[swift-syntax]=5885ad4e0ac448c6d4be85b17c5dd28e825aedf3664cf1b928017fb81938f52a
library_checksums[swift-corelibs-libdispatch]=ec27aabf9b0500ad2abcc53b8902a7673d9871106097851ce226e2aa817d1b0e
library_checksums[swift-corelibs-foundation]=b71505ae557a15481c05bbfaaeee83047e109c285ce4c4c7e06ba79b1aea3f2c
library_checksums[swift-corelibs-xctest]=194180362ba8a18f60f4cc371ada705be2a51d317364055b17024bf9ae405e26
library_checksums[swift-llbuild]=2df6fa3d92a351df97f228148405462e3aebcd4f0077b17e0ee5f5514575aa68
library_checksums[swift-argument-parser]=a4d4c08cf280615fe6e00752ef60e28e76f07c25eb4706a9269bf38135cd9c3f
library_checksums[swift-cmark]=1cd65148e5cbaa097e43709eaac8c4632e1c7cf83b1cd5031ef5dc8d4202a7d5
library_checksums[llvm-project]=80b0b2178efbef4be4ece9e428b7a7f02f8cafc879f886d8602c77f3b54703c4
library_checksums[swift-experimental-string-processing]=fcd8c52d1fbeded100fe88747bfd0578293133678d04beedec2a9f28aa1ec0a9
library_checksums[swift-syntax]=c7a693e917d21f6fa816f0bbb054468fb93d6c37dda9110669026f1203e6dbe5
library_checksums[swift-corelibs-libdispatch]=db30ccf6b20963112ab3aad256c2e49a18041a9806cf2f05854fe63a90d688c2
library_checksums[swift-corelibs-foundation]=24779a0f4e9ad545fbd59aaeb191c10ecc36b71c46394cf56ca5e6096ef89627
library_checksums[swift-corelibs-xctest]=f70044d3522d8d45d6a8bba6522987765a7de5dcbe8b11f12acc8600042a9c52
library_checksums[swift-llbuild]=cc8dfb098db4b0210ca5466f59d3e5fc55c4eedcd835263e6eae7dd719ba8203
library_checksums[swift-argument-parser]=44782ba7180f924f72661b8f457c268929ccd20441eac17301f18eff3b91ce0c
library_checksums[Yams]=ec1ad699c30f0db45520006c63a88cc1c946a7d7b36dff32a96460388c0a4af2
library_checksums[swift-collections]=575cf0f88d9068411f9acc6e3ca5d542bef1cc9e87dc5d69f7b5a1d5aec8c6b6
library_checksums[swift-crypto]=84cec042505e1c5bf3dd14a1bb18d0c06c5a9435b7b10a69709101b602285ff5
library_checksums[swift-crypto]=a7b2f5c4887ccd728cdff5d1162b4d4d36bd6c2df9c0c31d5b9b73d341c5c1bb
library_checksums[swift-system]=865b8c380455eef27e73109835142920c60ae4c4f4178a3d12ad04acc83f1371
library_checksums[swift-driver]=576ba0b330f2dc1fde6979dcecfccbb13c43d76b118bc8b43ecef9e62332df84
library_checksums[swift-tools-support-core]=914c697ded28be930f5afc844bc5712d2f47c14c83fae945ecca0f49af200f70
library_checksums[swift-package-manager]=51967163d971aac66f9667d2a9387da3c25b70118bc1e82cef309759f7b1d272
library_checksums[indexstore-db]=d9ff209be9a43109a80f1b2948fd34f203e1d55a944b1a2ea34439a75e218dc1
library_checksums[sourcekit-lsp]=abc341ac3e05c01fe93949cdd72ee9aefc3b785a9f91ead32169764a1af6625e
library_checksums[swift-asn1]=d4470d61788194abbd60ed73965ee0722cc25037e83d41226a8a780088ba524e
library_checksums[swift-certificates]=d7699ce91d65a622c1b9aaa0235cbbbd1be4ddc42a90fce007ff74bef50e8985
library_checksums[swift-driver]=e51199f694a2e2bc10e153acb3f8af94531d877e1db8bd483a9258cf6d3540dc
library_checksums[swift-tools-support-core]=dc84bfc05239ae863d82651637afb0551c6340a06dcb60f6fec685fefbab9077
library_checksums[swift-package-manager]=f9a589ee585b40405edb7944ed57effda62abbbae83989c7bf485ecdd4dfae16
library_checksums[indexstore-db]=dc50698dd5b226b15678ec35d662cbe54c69e1a4e492f14d673cb17cee0bed82
library_checksums[sourcekit-lsp]=eff0ae4a428a178aa32c6659f9eb9ad6a9b13be4c0cfd164588f70f268d5d6cd
for library in "${!library_checksums[@]}"; do \
GH_ORG="apple"
if [ "$library" = "swift-argument-parser" ]; then
SRC_VERSION="1.0.3"
SRC_VERSION="1.2.2"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-asn1" ]; then
SRC_VERSION="0.7.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-certificates" ]; then
SRC_VERSION="0.4.1"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-collections" ]; then
SRC_VERSION="1.0.1"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-crypto" ]; then
SRC_VERSION="2.2.3"
SRC_VERSION="2.5.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-system" ]; then
SRC_VERSION="1.1.1"
@ -102,10 +109,10 @@ termux_step_host_build() {
local CLANGXX=$(command -v clang++)
# The Ubuntu CI may not have clang/clang++ in its path so explicitly set it
# to clang-14 instead.
# to clang-15 instead.
if [ -z "$CLANG" ]; then
CLANG=$(command -v clang-14)
CLANGXX=$(command -v clang++-14)
CLANG=$(command -v clang-15)
CLANGXX=$(command -v clang++-15)
fi
# Natively compile llvm-tblgen and some other files needed later.
@ -136,15 +143,13 @@ termux_step_make() {
SWIFT_BUILD_ROOT=$TERMUX_PKG_BUILDDIR $TERMUX_PKG_SRCDIR/swift/utils/build-script \
$SWIFT_BUILD_FLAGS --xctest -b -p --swift-driver --sourcekit-lsp \
--android-api-level $TERMUX_PKG_API_LEVEL --skip-early-swiftsyntax \
--build-swift-static-stdlib --swift-install-components=$SWIFT_COMPONENTS \
--llvm-install-components=IndexStore --install-llvm --install-swift \
--install-libdispatch --install-foundation --install-xctest --install-llbuild \
--install-swiftpm --install-swift-driver --install-sourcekit-lsp
--android-api-level $TERMUX_PKG_API_LEVEL --build-swift-static-stdlib \
--swift-install-components=$SWIFT_COMPONENTS --llvm-install-components=IndexStore \
--install-llvm --install-swift --install-libdispatch --install-foundation \
--install-xctest --install-llbuild --install-swiftpm --install-swift-driver --install-sourcekit-lsp
}
termux_step_make_install() {
rm $TERMUX_PREFIX/lib/swift/pm/llbuild/libllbuild.so
rm $TERMUX_PREFIX/lib/swift/android/lib{dispatch,BlocksRuntime}.so
mv $TERMUX_PREFIX/lib/swift/android/lib[^_]*.so $TERMUX_PREFIX/opt/ndk-multilib/$TERMUX_ARCH-linux-android*/lib
mv $TERMUX_PREFIX/lib/swift/android/lib*.a $TERMUX_PREFIX/lib/swift/android/$SWIFT_ARCH

View File

@ -8,6 +8,6 @@ index 469ef62f1a9d..218f5af748f4 100644
case ToolChain::CST_Libcxx:
- CmdArgs.push_back("-lc++");
+ CmdArgs.push_back("-lc++_shared");
if (Args.hasArg(options::OPT_fexperimental_library))
CmdArgs.push_back("-lc++experimental");
break;
case ToolChain::CST_Libstdcxx:

View File

@ -1,16 +1,3 @@
diff --git a/cmark/src/CMakeLists.txt b/cmark/src/CMakeLists.txt
index faabffa..65e23cc 100644
--- a/cmark/src/CMakeLists.txt
+++ b/cmark/src/CMakeLists.txt
@@ -162,7 +162,7 @@ if(CMARK_SHARED OR CMARK_STATIC)
set(CMARK_TARGETS_FILE ${CMAKE_CURRENT_BINARY_DIR}/cmarkTargets.cmake)
export(TARGETS ${CMARK_INSTALL} FILE ${CMARK_TARGETS_FILE})
- if(CMARK_THREADING AND NOT APPLE AND NOT MSVC)
+ if(CMARK_THREADING AND NOT APPLE AND NOT MSVC AND NOT ANDROID)
if(CMARK_SHARED)
target_link_libraries(${LIBRARY} pthread)
endif(CMARK_SHARED)
diff --git a/llvm-project/clang/runtime/CMakeLists.txt b/llvm-project/clang/runtime/CMakeLists.txt
index 61b1c60bf590..5b0d10a67699 100644
--- a/llvm-project/clang/runtime/CMakeLists.txt
@ -44,19 +31,6 @@ index 1bcfc0734785..ddb77c91b22d 100644
install(DIRECTORY ../../include/indexstore
COMPONENT IndexStore
diff --git a/llvm-project/llvm/CMakeLists.txt b/llvm-project/llvm/CMakeLists.txt
index a888c4177fa5..6788a62fa8bd 100644
--- a/llvm-project/llvm/CMakeLists.txt
+++ b/llvm-project/llvm/CMakeLists.txt
@@ -625,7 +625,7 @@ option (LLVM_ENABLE_SPHINX "Use Sphinx to generate llvm documentation." OFF)
option (LLVM_ENABLE_OCAMLDOC "Build OCaml bindings documentation." ON)
option (LLVM_ENABLE_BINDINGS "Build bindings." ON)
-if(UNIX)
+if(UNIX AND CMAKE_SIZEOF_VOID_P GREATER_EQUAL 8)
set(LLVM_ENABLE_ONDISK_CAS_default ON)
else()
set(LLVM_ENABLE_ONDISK_CAS_default OFF)
diff --git a/llvm-project/cmake/Modules/HandleCompilerRT.cmake b/llvm-project/cmake/Modules/HandleCompilerRT.cmake
index ac9e0871489d..b495cbfb5c2e 100644
--- a/llvm-project/cmake/Modules/HandleCompilerRT.cmake

View File

@ -0,0 +1,12 @@
diff --git a/swift/utils/swift_build_support/swift_build_support/products/llvm.py b/swift/utils/swift_build_support/swift_build_support/products/llvm.py
index 744dca10fca..7b5932882f2 100644
--- a/swift/utils/swift_build_support/swift_build_support/products/llvm.py
+++ b/swift/utils/swift_build_support/swift_build_support/products/llvm.py
@@ -231,6 +231,7 @@ class LLVM(cmake_product.CMakeProduct):
if self.args.skip_build or not self.args.build_llvm:
build_targets = ['llvm-tblgen', 'clang-resource-headers',
+ 'clang-pseudo-gen', 'clang-tidy-confusable-chars-gen',
'intrinsics_gen', 'clang-tablegen-targets']
if not self.args.build_toolchain_only:
build_targets.extend([

View File

@ -1,22 +0,0 @@
diff --git a/swift/include/swift/AST/Expr.h b/swift/include/swift/AST/Expr.h
index 77695508386..719513b494f 100644
--- a/swift/include/swift/AST/Expr.h
+++ b/swift/include/swift/AST/Expr.h
@@ -3306,7 +3306,7 @@ public:
/// this array will be empty
ArrayRef<ConversionPair> getArgumentConversions() const {
return {getTrailingObjects<ConversionPair>(),
- Bits.ErasureExpr.NumArgumentConversions };
+ static_cast<size_t>(Bits.ErasureExpr.NumArgumentConversions) };
}
/// Retrieve the conversion expressions mapping requirements from any
@@ -3316,7 +3316,7 @@ public:
/// this array will be empty
MutableArrayRef<ConversionPair> getArgumentConversions() {
return {getTrailingObjects<ConversionPair>(),
- Bits.ErasureExpr.NumArgumentConversions };
+ static_cast<size_t>(Bits.ErasureExpr.NumArgumentConversions) };
}
void setArgumentConversion(unsigned i, const ConversionPair &p) {

View File

@ -0,0 +1,740 @@
From dba94bdbd4f4b1e9b3b271409cbc5d1bb49ddaf3
From: Doug Gregor <dgregor@apple.com>
Date: Fri, 19 May 2023 15:02:42 -0700
Subject: [PATCH] [ASTGen] Add experimental feature to use ASTGen in lieu
of parsing types
Introduce a new experimental feature `ASTGenTypes` that uses ASTGen to
translate the Swift syntax tree (produced by the new Swift parser)
into C++ `TypeRepr` nodes instead of having the C++ parser create the
nodes.
The approach here is to intercept the C++ parser's `parseType`
operation to find the Swift syntax node at the given position (where
the lexer currently is) and have ASTGen translate that into the
corresponding C++ AST node. Then, we spin the lexer forward to the
token immediately following the end of the syntax node and continue
parsing.
diff --git a/swift/include/swift/AST/CASTBridging.h b/swift/include/swift/AST/CASTBridging.h
index 4699a291a1f..dd24e573561 100644
--- a/swift/include/swift/AST/CASTBridging.h
+++ b/swift/include/swift/AST/CASTBridging.h
@@ -112,6 +112,70 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
BridgedBuiltinExternalMacro
} BridgedMacroDefinitionKind;
+/// Bridged parameter specifiers
+typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedAttributedTypeSpecifier : long {
+ BridgedAttributedTypeSpecifierInOut,
+ BridgedAttributedTypeSpecifierBorrowing,
+ BridgedAttributedTypeSpecifierConsuming,
+ BridgedAttributedTypeSpecifierLegacyShared,
+ BridgedAttributedTypeSpecifierLegacyOwned,
+ BridgedAttributedTypeSpecifierConst,
+ BridgedAttributedTypeSpecifierIsolated,
+} BridgedAttributedTypeSpecifier;
+
+
+// Bridged type attribute kinds, which mirror TypeAttrKind exactly.
+typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long {
+ BridgedTypeAttrKind_autoclosure,
+ BridgedTypeAttrKind_convention,
+ BridgedTypeAttrKind_noescape,
+ BridgedTypeAttrKind_escaping,
+ BridgedTypeAttrKind_differentiable,
+ BridgedTypeAttrKind_noDerivative,
+ BridgedTypeAttrKind_async,
+ BridgedTypeAttrKind_Sendable,
+ BridgedTypeAttrKind_unchecked,
+ BridgedTypeAttrKind__local,
+ BridgedTypeAttrKind__noMetadata,
+ BridgedTypeAttrKind__opaqueReturnTypeOf,
+ BridgedTypeAttrKind_block_storage,
+ BridgedTypeAttrKind_box,
+ BridgedTypeAttrKind_dynamic_self,
+ BridgedTypeAttrKind_sil_weak,
+ BridgedTypeAttrKind_sil_unowned,
+ BridgedTypeAttrKind_sil_unmanaged,
+ BridgedTypeAttrKind_error,
+ BridgedTypeAttrKind_out,
+ BridgedTypeAttrKind_direct,
+ BridgedTypeAttrKind_in,
+ BridgedTypeAttrKind_inout,
+ BridgedTypeAttrKind_inout_aliasable,
+ BridgedTypeAttrKind_in_guaranteed,
+ BridgedTypeAttrKind_in_constant,
+ BridgedTypeAttrKind_pack_owned,
+ BridgedTypeAttrKind_pack_guaranteed,
+ BridgedTypeAttrKind_pack_inout,
+ BridgedTypeAttrKind_pack_out,
+ BridgedTypeAttrKind_owned,
+ BridgedTypeAttrKind_unowned_inner_pointer,
+ BridgedTypeAttrKind_guaranteed,
+ BridgedTypeAttrKind_autoreleased,
+ BridgedTypeAttrKind_callee_owned,
+ BridgedTypeAttrKind_callee_guaranteed,
+ BridgedTypeAttrKind_objc_metatype,
+ BridgedTypeAttrKind_opened,
+ BridgedTypeAttrKind_pack_element,
+ BridgedTypeAttrKind_pseudogeneric,
+ BridgedTypeAttrKind_yields,
+ BridgedTypeAttrKind_yield_once,
+ BridgedTypeAttrKind_yield_many,
+ BridgedTypeAttrKind_captures_generics,
+ BridgedTypeAttrKind_moveOnly,
+ BridgedTypeAttrKind_thin,
+ BridgedTypeAttrKind_thick,
+ BridgedTypeAttrKind_Count
+} BridgedTypeAttrKind;
+
#ifdef __cplusplus
extern "C" {
@@ -261,6 +325,19 @@ void *ImplicitlyUnwrappedOptionalTypeRepr_create(void *ctx, void *base,
void *exclamationLoc);
void *MetatypeTypeRepr_create(void *ctx, void *baseType, void *typeLoc);
void *ProtocolTypeRepr_create(void *ctx, void *baseType, void *protoLoc);
+
+BridgedTypeAttrKind getBridgedTypeAttrKindFromString(
+ const unsigned char * _Nullable str, long len);
+
+typedef void *BridgedTypeAttributes;
+BridgedTypeAttributes BridgedTypeAttributes_create(void);
+void BridgedTypeAttributes_addSimpleAttr(
+ BridgedTypeAttributes typeAttributes, BridgedTypeAttrKind kind, void *atLoc, void *attrLoc);
+void *AttributedTypeRepr_create(void *ctx, void *base, BridgedTypeAttributes typeAttributes);
+
+void *AttributedTypeSpecifierRepr_create(
+ void *ctx, void *base, BridgedAttributedTypeSpecifier specifier, void *specifierLoc);
+void *VarargTypeRepr_create(void *ctx, void *base, void *ellipsisLocPtr);
void *PackExpansionTypeRepr_create(void *ctx, void *base, void *repeatLoc);
void *TupleTypeRepr_create(void *ctx, BridgedArrayRef elements, void *lParenLoc,
void *rParenLoc);
@@ -269,8 +346,9 @@ void *MemberTypeRepr_create(void *ctx, void *baseComponent,
void *GenericIdentTypeRepr_create(void *ctx, BridgedIdentifier name,
void *nameLoc, BridgedArrayRef genericArgs,
void *lAngle, void *rAngle);
+void *EmptyCompositionTypeRepr_create(void *ctx, void *anyLoc);
void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types,
- void *firstTypeLoc);
+ void *firstTypeLoc, void *firstAmpLoc);
void *FunctionTypeRepr_create(void *ctx, void *argsTy, void *_Nullable asyncLoc,
void *_Nullable throwsLoc, void *arrowLoc,
void *returnType);
diff --git a/swift/include/swift/Basic/Features.def b/swift/include/swift/Basic/Features.def
index d3b6ed2519f..d0884deafe4 100644
--- a/swift/include/swift/Basic/Features.def
+++ b/swift/include/swift/Basic/Features.def
@@ -184,6 +184,10 @@ EXPERIMENTAL_FEATURE(ImplicitSome, false)
/// corresponding syntax tree.
EXPERIMENTAL_FEATURE(ParserASTGen, false)
+/// Use the syntax tree produced by the Swift (swift-syntax) parser for type
+/// parsing, using ASTGen to translate them into AST nodes.
+EXPERIMENTAL_FEATURE(ASTGenTypes, false)
+
/// Parse using the Swift (swift-syntax) parser and use ASTGen to generate the
/// corresponding syntax tree.
EXPERIMENTAL_FEATURE(BuiltinMacros, false)
diff --git a/swift/include/swift/Parse/Parser.h b/swift/include/swift/Parse/Parser.h
index a1ac3666776..2ba8c645833 100644
--- a/swift/include/swift/Parse/Parser.h
+++ b/swift/include/swift/Parse/Parser.h
@@ -24,6 +24,7 @@
#include "swift/AST/LayoutConstraint.h"
#include "swift/AST/ParseRequests.h"
#include "swift/AST/Pattern.h"
+#include "swift/AST/SourceFile.h"
#include "swift/AST/Stmt.h"
#include "swift/Basic/OptionSet.h"
#include "swift/Config.h"
@@ -1343,6 +1344,50 @@ public:
/// Get the location for a type error.
SourceLoc getTypeErrorLoc() const;
+ /// Callback function used for creating a C++ AST from the syntax node at the given source location.
+ ///
+ /// The arguments to this callback are the source file to pass into ASTGen (the exported source file)
+ /// and the source location pointer to pass into ASTGen (to find the syntax node).
+ ///
+ /// The callback returns the new AST node and the ending location of the syntax node. If the AST node
+ /// is NULL, something went wrong.
+ template<typename T>
+ using ASTFromSyntaxTreeCallback = std::pair<T*, const void *>(
+ void *sourceFile, const void *sourceLoc
+ );
+
+ /// Parse by constructing a C++ AST node from the Swift syntax tree via ASTGen.
+ template<typename T>
+ ParserResult<T> parseASTFromSyntaxTree(
+ llvm::function_ref<ASTFromSyntaxTreeCallback<T>> body
+ ) {
+ if (!Context.LangOpts.hasFeature(Feature::ASTGenTypes))
+ return nullptr;
+
+ auto exportedSourceFile = SF.getExportedSourceFile();
+ if (!exportedSourceFile)
+ return nullptr;
+
+ // Perform the translation.
+ auto sourceLoc = Tok.getLoc().getOpaquePointerValue();
+ T* astNode;
+ const void *endLocPtr;
+ std::tie(astNode, endLocPtr) = body(exportedSourceFile, sourceLoc);
+
+ if (!astNode) {
+ assert(false && "Could not build AST node from syntax tree");
+ return nullptr;
+ }
+
+ // Reset the lexer to the ending location.
+ StringRef contents =
+ SourceMgr.extractText(SourceMgr.getRangeForBuffer(L->getBufferID()));
+ L->resetToOffset((const char *)endLocPtr - contents.data());
+ L->lex(Tok);
+
+ return makeParserResult(astNode);
+ }
+
//===--------------------------------------------------------------------===//
// Type Parsing
diff --git a/swift/lib/AST/ASTPrinter.cpp b/swift/lib/AST/ASTPrinter.cpp
index 7f24711916c..474e62aa8dc 100644
--- a/swift/lib/AST/ASTPrinter.cpp
+++ b/swift/lib/AST/ASTPrinter.cpp
@@ -3364,6 +3364,10 @@ static bool usesFeatureParserASTGen(Decl *decl) {
return false;
}
+static bool usesFeatureASTGenTypes(Decl *decl) {
+ return false;
+}
+
static bool usesFeatureBuiltinMacros(Decl *decl) {
return false;
}
diff --git a/swift/lib/AST/CASTBridging.cpp b/swift/lib/AST/CASTBridging.cpp
index 5b935d4cebb..2f7c14fd1a2 100644
--- a/swift/lib/AST/CASTBridging.cpp
+++ b/swift/lib/AST/CASTBridging.cpp
@@ -119,6 +119,15 @@ void SwiftDiagnostic_finish(BridgedDiagnostic diagPtr) {
BridgedIdentifier
SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str,
long len) {
+ if (len == 1 && str[0] == '_')
+ return BridgedIdentifier();
+
+ // If this was a back-ticked identifier, drop the back-ticks.
+ if (len >= 2 && str[0] == '`' && str[len-1] == '`') {
+ ++str;
+ len -= 2;
+ }
+
return const_cast<void *>(
static_cast<ASTContext *>(ctx)
->getIdentifier(
@@ -484,6 +493,87 @@ void *PackExpansionTypeRepr_create(void *ctx, void *base, void *repeatLoc) {
getSourceLocFromPointer(repeatLoc), (TypeRepr *)base);
}
+static BridgedTypeAttrKind bridgeTypeAttrKind(TypeAttrKind kind) {
+ switch (kind) {
+#define TYPE_ATTR(X) case TAK_##X: return BridgedTypeAttrKind_##X;
+#include "swift/AST/Attr.def"
+ case TAK_Count: return BridgedTypeAttrKind_Count;
+ }
+}
+
+static TypeAttrKind bridgeTypeAttrKind(BridgedTypeAttrKind kind) {
+ switch (kind) {
+#define TYPE_ATTR(X) case BridgedTypeAttrKind_##X: return TAK_##X;
+#include "swift/AST/Attr.def"
+ case BridgedTypeAttrKind_Count: return TAK_Count;
+ }
+}
+
+BridgedTypeAttrKind getBridgedTypeAttrKindFromString(
+ const unsigned char *str, intptr_t len) {
+ return bridgeTypeAttrKind(
+ TypeAttributes::getAttrKindFromString(StringRef((const char *)str, len)));
+}
+
+BridgedTypeAttributes BridgedTypeAttributes_create() {
+ return new TypeAttributes();
+}
+
+void BridgedTypeAttributes_addSimpleAttr(
+ BridgedTypeAttributes typeAttributesPtr, BridgedTypeAttrKind kind,
+ void *atLoc, void *attrLoc
+) {
+ TypeAttributes *typeAttributes = (TypeAttributes *)typeAttributesPtr;
+ typeAttributes->setAttr(
+ bridgeTypeAttrKind(kind), getSourceLocFromPointer(attrLoc));
+ if (typeAttributes->AtLoc.isInvalid())
+ typeAttributes->AtLoc = getSourceLocFromPointer(atLoc);
+}
+
+void *AttributedTypeRepr_create(
+ void *ctx, void *base, BridgedTypeAttributes typeAttributesPtr) {
+ TypeAttributes *typeAttributes = (TypeAttributes *)typeAttributesPtr;
+ if (typeAttributes->empty())
+ return base;
+
+ ASTContext &Context = *static_cast<ASTContext *>(ctx);
+ auto attributedType =
+ new (Context) AttributedTypeRepr(*typeAttributes, (TypeRepr *)base);
+ delete typeAttributes;
+ return attributedType;
+}
+
+void *AttributedTypeSpecifierRepr_create(
+ void *ctx, void *base, BridgedAttributedTypeSpecifier specifier, void *specifierLoc
+) {
+ ASTContext &Context = *static_cast<ASTContext *>(ctx);
+ SourceLoc loc = getSourceLocFromPointer(specifierLoc);
+ TypeRepr *baseType = (TypeRepr *)base;
+ switch (specifier) {
+ case BridgedAttributedTypeSpecifierInOut:
+ return new (Context) OwnershipTypeRepr(baseType, ParamSpecifier::InOut, loc);
+ case BridgedAttributedTypeSpecifierBorrowing:
+ return new (Context) OwnershipTypeRepr(baseType, ParamSpecifier::Borrowing, loc);
+ case BridgedAttributedTypeSpecifierConsuming:
+ return new (Context) OwnershipTypeRepr(baseType, ParamSpecifier::Consuming, loc);
+ case BridgedAttributedTypeSpecifierLegacyShared:
+ return new (Context) OwnershipTypeRepr(baseType, ParamSpecifier::LegacyShared, loc);
+ case BridgedAttributedTypeSpecifierLegacyOwned:
+ return new (Context) OwnershipTypeRepr(baseType, ParamSpecifier::LegacyOwned, loc);
+ case BridgedAttributedTypeSpecifierConst:
+ return new (Context) CompileTimeConstTypeRepr(baseType, loc);
+ case BridgedAttributedTypeSpecifierIsolated:
+ return new (Context) IsolatedTypeRepr(baseType, loc);
+ }
+}
+
+void *VarargTypeRepr_create(void *ctx, void *base, void *ellipsisLocPtr) {
+ ASTContext &Context = *static_cast<ASTContext *>(ctx);
+ SourceLoc ellipsisLoc = getSourceLocFromPointer(ellipsisLocPtr);
+ TypeRepr *baseType = (TypeRepr *)base;
+ return new (Context) VarargTypeRepr(baseType, ellipsisLoc);
+}
+
void *TupleTypeRepr_create(void *ctx, BridgedArrayRef elements, void *lParenLoc,
void *rParenLoc) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
@@ -518,12 +608,21 @@ void *MemberTypeRepr_create(void *ctx, void *baseComponent,
memberComponents);
}
-void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef types,
- void *firstTypeLoc) {
+void *EmptyCompositionTypeRepr_create(void *ctx, void *anyLocPtr) {
+ ASTContext &Context = *static_cast<ASTContext *>(ctx);
+ SourceLoc anyLoc = getSourceLocFromPointer(anyLocPtr);
+ return CompositionTypeRepr::createEmptyComposition(Context, anyLoc);
+}
+
+void *CompositionTypeRepr_create(void *ctx, BridgedArrayRef typesPtr,
+ void *firstTypeLoc, void *firstAmpLocPtr) {
ASTContext &Context = *static_cast<ASTContext *>(ctx);
SourceLoc firstType = getSourceLocFromPointer(firstTypeLoc);
- return CompositionTypeRepr::create(Context, getArrayRef<TypeRepr *>(types),
- firstType, SourceRange{});
+ SourceLoc firstAmpLoc = getSourceLocFromPointer(firstAmpLocPtr);
+ auto types = getArrayRef<TypeRepr *>(typesPtr);
+ return CompositionTypeRepr::create(
+ Context, types, firstType,
+ SourceRange{firstAmpLoc, types.back()->getEndLoc()});
}
void *FunctionTypeRepr_create(void *ctx, void *argsTy, void *_Nullable asyncLoc,
diff --git a/swift/lib/ASTGen/Sources/ASTGen/Macros.swift b/swift/lib/ASTGen/Sources/ASTGen/Macros.swift
index 4ee025884bd..81e355f475d 100644
--- a/swift/lib/ASTGen/Sources/ASTGen/Macros.swift
+++ b/swift/lib/ASTGen/Sources/ASTGen/Macros.swift
@@ -627,10 +627,11 @@ func expandFreestandingMacroInProcess(
}
/// Retrieve a syntax node in the given source file, with the given type.
-private func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
+func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
sourceFilePtr: UnsafeRawPointer,
sourceLocationPtr: UnsafePointer<UInt8>?,
- type: Node.Type
+ type: Node.Type,
+ wantOutermost: Bool = false
) -> Node? {
guard let sourceLocationPtr = sourceLocationPtr else {
return nil
@@ -656,16 +657,45 @@ private func findSyntaxNodeInSourceFile<Node: SyntaxProtocol>(
}
var currentSyntax = Syntax(token)
+ var resultSyntax: Node? = nil
while let parentSyntax = currentSyntax.parent {
if let typedParent = parentSyntax.as(type) {
- return typedParent
+ resultSyntax = typedParent
+ break
}
currentSyntax = parentSyntax
}
- print("unable to find node: \(token.debugDescription)")
- return nil
+ // If we didn't find anything, complain and fail.
+ guard var resultSyntax else {
+ print("unable to find node: \(token.debugDescription)")
+ return nil
+ }
+
+ // If we want the outermost node, keep looking.
+ // FIXME: This is VERY SPECIFIC to handling of types. We must be able to
+ // do better.
+ if wantOutermost {
+ while let parentSyntax = resultSyntax.parent {
+ // Look through type compositions.
+ if let compositionElement = parentSyntax.as(CompositionTypeElementSyntax.self),
+ let compositionList = compositionElement.parent?.as(CompositionTypeElementListSyntax.self),
+ let typedParent = compositionList.parent?.as(type) {
+ resultSyntax = typedParent
+ continue
+ }
+
+ guard let typedParent = parentSyntax.as(type),
+ typedParent.position == resultSyntax.position else {
+ break
+ }
+
+ resultSyntax = typedParent
+ }
+ }
+
+ return resultSyntax
}
@_cdecl("swift_ASTGen_expandAttachedMacro")
diff --git a/swift/lib/ASTGen/Sources/ASTGen/Types.swift b/swift/lib/ASTGen/Sources/ASTGen/Types.swift
index eb2be48a8a8..82bbca53bf4 100644
--- a/swift/lib/ASTGen/Sources/ASTGen/Types.swift
+++ b/swift/lib/ASTGen/Sources/ASTGen/Types.swift
@@ -6,6 +6,11 @@ extension ASTGenVisitor {
public func visit(_ node: SimpleTypeIdentifierSyntax) -> ASTNode {
let loc = self.base.advanced(by: node.position.utf8Offset).raw
+ // If this is the bare 'Any' keyword, produce an empty composition type.
+ if node.name.tokenKind == .keyword(.Any) && node.genericArgumentClause == nil {
+ return .type(EmptyCompositionTypeRepr_create(self.ctx, loc))
+ }
+
var text = node.name.text
let id = text.withUTF8 { buf in
return SwiftASTContext_getIdentifier(ctx, buf.baseAddress, buf.count)
@@ -19,7 +24,7 @@ extension ASTGenVisitor {
let rAngle = self.base.advanced(by: generics.rightAngleBracket.position.utf8Offset).raw
return .type(
generics.arguments.map({
- self.visit($0.argumentType)
+ self.visit($0.argumentType).rawValue
}).withBridgedArrayRef {
genericArgs in
GenericIdentTypeRepr_create(
@@ -46,7 +51,7 @@ extension ASTGenVisitor {
let lAngle = self.base.advanced(by: generics.leftAngleBracket.position.utf8Offset).raw
let rAngle = self.base.advanced(by: generics.rightAngleBracket.position.utf8Offset).raw
reverseMemberComponents.append(
- generics.arguments.map({ self.visit($0.argumentType) }).withBridgedArrayRef {
+ generics.arguments.map({ self.visit($0.argumentType).rawValue }).withBridgedArrayRef {
genericArgs in
GenericIdentTypeRepr_create(self.ctx, name, nameLoc, genericArgs, lAngle, rAngle)
})
@@ -123,9 +128,11 @@ extension ASTGenVisitor {
assert(node.elements.count > 1)
let types = node.elements.map { visit($0.type) }.map { $0.rawValue }
let firstTypeLoc = self.base.advanced(by: node.elements.first!.type.position.utf8Offset).raw
+ let firstAmpOffset = node.elements.first?.ampersand.map { $0.position.utf8Offset } ?? 0
+ let firstAmpLoc = self.base.advanced(by: firstAmpOffset).raw
return .type(
types.withBridgedArrayRef { types in
- return CompositionTypeRepr_create(self.ctx, types, firstTypeLoc)
+ return CompositionTypeRepr_create(self.ctx, types, firstTypeLoc, firstAmpLoc)
})
}
@@ -161,8 +168,77 @@ extension ASTGenVisitor {
}
public func visit(_ node: AttributedTypeSyntax) -> ASTNode {
- // FIXME: Respect the attributes
- return visit(node.baseType)
+ var type = visit(node.baseType)
+
+ // Handle specifiers.
+ if let specifier = node.specifier {
+ let specifierLoc = self.base.advanced(by: specifier.position.utf8Offset).raw
+
+ let kind: BridgedAttributedTypeSpecifier
+ switch specifier.tokenKind {
+ case .keyword(.inout): kind = .inOut
+ case .keyword(.borrowing): kind = .borrowing
+ case .keyword(.consuming): kind = .consuming
+ case .keyword(.__shared): kind = .legacyShared
+ case .keyword(.__owned): kind = .legacyOwned
+ case .keyword(._const): kind = .const
+ case .keyword(.isolated): kind = .isolated
+ default: fatalError("unhandled specifier \(specifier.debugDescription)")
+ }
+
+ type = .type(AttributedTypeSpecifierRepr_create(self.ctx, type.rawValue, kind, specifierLoc))
+ }
+
+ // Handle type attributes.
+ if let attributes = node.attributes {
+ let typeAttributes = BridgedTypeAttributes_create()
+ for attributeElt in attributes {
+ // FIXME: Ignoring #ifs entirely. We want to provide a filtered view,
+ // but we don't have that ability right now.
+ guard case let .attribute(attribute) = attributeElt else {
+ continue
+ }
+
+ // Only handle simple attribute names right now.
+ guard let identType = attribute.attributeName.as(SimpleTypeIdentifierSyntax.self) else {
+ continue
+ }
+
+ let nameSyntax = identType.name
+ var name = nameSyntax.text
+ let typeAttrKind = name.withUTF8 { buf in
+ getBridgedTypeAttrKindFromString(buf.baseAddress, buf.count)
+ }
+ let atLoc = self.base.advanced(by: attribute.atSignToken.position.utf8Offset).raw
+ let attrLoc = self.base.advanced(by: nameSyntax.position.utf8Offset).raw
+ switch typeAttrKind {
+ // SIL attributes
+ // FIXME: Diagnose if not in SIL mode? Or should that move to the
+ // type checker?
+ case .out, .in, .owned, .unowned_inner_pointer, .guaranteed,
+ .autoreleased, .callee_owned, .callee_guaranteed, .objc_metatype,
+ .sil_weak, .sil_unowned, .inout, .block_storage, .box,
+ .dynamic_self, .sil_unmanaged, .error, .direct, .inout_aliasable,
+ .in_guaranteed, .in_constant, .captures_generics, .moveOnly:
+ fallthrough
+
+ case .autoclosure, .escaping, .noescape, .noDerivative, .async,
+ .sendable, .unchecked, ._local, ._noMetadata, .pack_owned,
+ .pack_guaranteed, .pack_inout, .pack_out, .pseudogeneric,
+ .yields, .yield_once, .yield_many, .thin, .thick, .count:
+ BridgedTypeAttributes_addSimpleAttr(typeAttributes, typeAttrKind, atLoc, attrLoc)
+
+ case .opened, .pack_element, .differentiable, .convention,
+ ._opaqueReturnTypeOf:
+ // FIXME: These require more complicated checks
+ break
+ }
+ }
+
+ type = .type(AttributedTypeRepr_create(self.ctx, type.rawValue, typeAttributes))
+ }
+
+ return type
}
}
@@ -186,7 +262,13 @@ extension ASTGenVisitor {
self.base.advanced(by: $0.position.utf8Offset).raw
}
let colonLoc = element.colon.map { self.base.advanced(by: $0.position.utf8Offset).raw }
- let type = visit(element.type).rawValue
+
+ var type = visit(element.type).rawValue
+ if let ellipsis = element.ellipsis {
+ let ellipsisLoc = self.base.advanced(by: ellipsis.positionAfterSkippingLeadingTrivia.utf8Offset).raw
+ type = VarargTypeRepr_create(self.ctx, type, ellipsisLoc)
+ }
+
let trailingCommaLoc = element.trailingComma.map {
self.base.advanced(by: $0.position.utf8Offset).raw
}
@@ -207,3 +289,37 @@ extension ASTGenVisitor {
}
}
}
+
+@_cdecl("swift_ASTGen_buildTypeRepr")
+@usableFromInline
+func buildTypeRepr(
+ sourceFilePtr: UnsafeRawPointer,
+ typeLocPtr: UnsafePointer<UInt8>,
+ dc: UnsafeMutableRawPointer,
+ ctx: UnsafeMutableRawPointer,
+ endTypeLocPtr: UnsafeMutablePointer<UnsafePointer<UInt8>?>
+) -> UnsafeMutableRawPointer? {
+ let sourceFile = sourceFilePtr.bindMemory(
+ to: ExportedSourceFile.self, capacity: 1
+ )
+
+ // Find the type syntax node.
+ guard let typeSyntax = findSyntaxNodeInSourceFile(
+ sourceFilePtr: sourceFilePtr,
+ sourceLocationPtr: typeLocPtr,
+ type: TypeSyntax.self,
+ wantOutermost: true
+ ) else {
+ // FIXME: Produce an error
+ return nil
+ }
+
+ // Fill in the end location.
+ endTypeLocPtr.pointee = sourceFile.pointee.buffer.baseAddress!.advanced(by: typeSyntax.endPosition.utf8Offset)
+
+ // Convert the type syntax node.
+ let typeReprNode = ASTGenVisitor(ctx: ctx, base: sourceFile.pointee.buffer.baseAddress!, declContext: dc)
+ .visit(typeSyntax)
+
+ return typeReprNode.rawValue
+}
diff --git a/swift/lib/Parse/ParseType.cpp b/swift/lib/Parse/ParseType.cpp
index 98a1cb0a4fc..97c88da9bbd 100644
--- a/swift/lib/Parse/ParseType.cpp
+++ b/swift/lib/Parse/ParseType.cpp
@@ -582,6 +582,14 @@ ParserResult<TypeRepr> Parser::parseTypeScalar(
constLoc));
}
+/// Build a TypeRepr for AST node for the type at the given source location in the specified file.
+///
+/// \param sourceLoc The source location at which to start processing a type.
+/// \param endSourceLoc Will receive the source location immediately following the type.
+extern "C" TypeRepr *swift_ASTGen_buildTypeRepr(
+ void *sourceFile, const void *_Nullable sourceLoc,
+ void *declContext, void *astContext, const void *_Nullable *endSourceLoc);
+
/// parseType
/// type:
/// type-scalar
@@ -592,6 +600,32 @@ ParserResult<TypeRepr> Parser::parseTypeScalar(
///
ParserResult<TypeRepr> Parser::parseType(
Diag<> MessageID, ParseTypeReason reason) {
+ #if SWIFT_SWIFT_PARSER
+ auto astGenResult = parseASTFromSyntaxTree<TypeRepr>(
+ [&](void *exportedSourceFile, const void *sourceLoc) {
+ const void *endLocPtr = nullptr;
+ TypeRepr *typeRepr = swift_ASTGen_buildTypeRepr(
+ exportedSourceFile, Tok.getLoc().getOpaquePointerValue(),
+ CurDeclContext, &Context, &endLocPtr);
+ return std::make_pair(typeRepr, endLocPtr);
+ });
+ if (astGenResult.isNonNull()) {
+ // Note: there is a representational difference between the swift-syntax
+ // tree and the C++ parser tree regarding variadic parameters. In the
+ // swift-syntax tree, the ellipsis is part of the parameter declaration.
+ // In the C++ parser tree, the ellipsis is part of the type. Account for
+ // this difference by consuming the ellipsis here.
+ if (Tok.isEllipsis()) {
+ Tok.setKind(tok::ellipsis);
+ SourceLoc ellipsisLoc = consumeToken();
+ return makeParserResult(astGenResult,
+ new (Context) VarargTypeRepr(astGenResult.get(), ellipsisLoc));
+ }
+
+ return astGenResult;
+ }
+ #endif
+
// Parse pack expansion 'repeat T'
if (Tok.is(tok::kw_repeat)) {
SourceLoc repeatLoc = consumeToken(tok::kw_repeat);
diff --git a/swift/test/ASTGen/types.swift b/swift/test/ASTGen/types.swift
new file mode 100644
index 00000000000..f6eddfe1ed6
--- /dev/null
+++ b/swift/test/ASTGen/types.swift
@@ -0,0 +1,41 @@
+// RUN: %target-typecheck-verify-swift -enable-experimental-feature ASTGenTypes
+
+// -enable-experimental-feature requires an asserts build
+// REQUIRES: asserts
+
+protocol P { }
+protocol Q { }
+typealias PQ = P & Q
+
+func test7(_ b: inout Bool) {
+ b = true
+}
+
+struct X { struct `Protocol` { } }
+
+func test10(_: X.`Protocol`) { }
+
+func test11(_: Int...) { }
+func test11a() {
+ test11(1, 2, 3, 4, 5)
+}
+
+typealias VAFunc = (Int, Int...) -> Int
+func testVAFunc(a: Int, f: VAFunc) {
+ _ = f(a, a, a, a, a)
+}
+
+func test12(_ producer: @escaping @autoclosure () -> Int) {
+ _ = producer()
+}
+func test12a(i: Int) {
+ test12(i)
+}
+
+func test13(body: (_ value: Int) -> Void, i: Int) {
+ body(i)
+}
+
+func test14() {
+ _ = Array<Array<Array<Int>>>().count
+}
diff --git a/swift/test/ASTGen/verify-parse.swift b/swift/test/ASTGen/verify-parse.swift
index ec5004eb129..9bdc36cb4f0 100644
--- a/swift/test/ASTGen/verify-parse.swift
+++ b/swift/test/ASTGen/verify-parse.swift
@@ -1,8 +1,9 @@
// RUN: %target-run-simple-swift(-enable-experimental-feature SwiftParser -enable-experimental-feature ParserASTGen)
+// RUN: %target-run-simple-swift(-enable-experimental-feature ASTGenTypes)
// REQUIRES: executable_test
-// -enable-experimental-feature requires and asserts build
+// -enable-experimental-feature requires an asserts build
// REQUIRES: asserts
func test1(x: Int, fn: (Int) -> Int) -> Int {
@@ -25,11 +26,11 @@ func test3(y: Int) -> Int {
return x
}
-func test4(_ b: Bool) -> Int {
- if b { 0 } else { 1 }
+func test4(_ b: [Bool]) -> Int {
+ if b.isEmpty { 0 } else { 1 }
}
-func test5(_ b: Bool) -> Int {
+func test5(_ b: Swift.Bool) -> Int {
return if b { 0 } else { 1 }
}
@@ -37,3 +38,12 @@ func test6(_ b: Bool) -> Int {
let x = if b { 0 } else { 1 }
return x
}
+
+func test7(_ b: inout Bool) {
+ // b = true
+}
+
+func test8(_ i: _const Int) {
+}
+
+func test9(_ value: Any) { }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -7,9 +7,9 @@ index aabc3f2e..168f939c 100644
if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
target_link_options(llbuildSwift PRIVATE "SHELL:-no-toolchain-stdlib-rpath")
- set_target_properties(llbuildSwift PROPERTIES
- INSTALL_RPATH "$ORIGIN:$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
- INSTALL_RPATH "$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
+# set_target_properties(llbuildSwift PROPERTIES
+ # INSTALL_RPATH "$ORIGIN:$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
+ # INSTALL_RPATH "$ORIGIN/../../$<LOWER_CASE:${CMAKE_SYSTEM_NAME}>")
endif()
endif()
set_target_properties(llbuildSwift PROPERTIES
@ -58,7 +58,7 @@ diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 92c368a86..e9d43b599 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -744,7 +744,7 @@ def get_swiftpm_env_cmd(args):
@@ -746,7 +746,7 @@ def get_swiftpm_env_cmd(args):
env_cmd.append("SWIFTCI_USE_LOCAL_DEPS=1")
env_cmd.append("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target)

View File

@ -3,9 +3,6 @@ TERMUX_SUBPKG_INCLUDE="
lib/swift/android/aarch64/*.swiftdoc
lib/swift/android/aarch64/*.swiftmodule
lib/swift/android/aarch64/glibc.modulemap
lib/swift/android/aarch64/libcxxshim.h
lib/swift/android/aarch64/libcxxshim.modulemap
lib/swift/android/aarch64/libswiftCompatibilityBytecodeLayouts.a
lib/swift/android/aarch64/libswiftCxx.a
lib/swift/android/aarch64/SwiftGlibc.h
lib/swift/android/aarch64/swiftrt.o

View File

@ -3,9 +3,6 @@ TERMUX_SUBPKG_INCLUDE="
lib/swift/android/armv7/*.swiftdoc
lib/swift/android/armv7/*.swiftmodule
lib/swift/android/armv7/glibc.modulemap
lib/swift/android/armv7/libcxxshim.h
lib/swift/android/armv7/libcxxshim.modulemap
lib/swift/android/armv7/libswiftCompatibilityBytecodeLayouts.a
lib/swift/android/armv7/libswiftCxx.a
lib/swift/android/armv7/SwiftGlibc.h
lib/swift/android/armv7/swiftrt.o

View File

@ -3,9 +3,6 @@ TERMUX_SUBPKG_INCLUDE="
lib/swift/android/x86_64/*.swiftdoc
lib/swift/android/x86_64/*.swiftmodule
lib/swift/android/x86_64/glibc.modulemap
lib/swift/android/x86_64/libcxxshim.h
lib/swift/android/x86_64/libcxxshim.modulemap
lib/swift/android/x86_64/libswiftCompatibilityBytecodeLayouts.a
lib/swift/android/x86_64/libswiftCxx.a
lib/swift/android/x86_64/SwiftGlibc.h
lib/swift/android/x86_64/swiftrt.o

View File

@ -0,0 +1,500 @@
From 9ee52eea768af39f4ccbc1939d1385d70bb0ef37
From: Ben Barham <ben_barham@apple.com>
Date: Tue, 16 May 2023 16:25:36 -0700
Subject: [PATCH 1/4] [CMake] Updates to allow inclusion using FetchContent
Various updates that allow swift-syntax to be included using
FetchContent.
Mostly this is just not replacing `target_link_libraries` since that is
a global replacement, but we also now use a couple of variables from the
swift if they're set (eg. `SWIFT_HOST_LIBRARIES_DEST_DIR` and
`SWIFT_HOST_MODULE_TRIPLE`).
diff --git a/swift-syntax/CMakeLists.txt b/swift-syntax/CMakeLists.txt
index aadf062ae5..c5a697ccc0 100644
--- a/swift-syntax/CMakeLists.txt
+++ b/swift-syntax/CMakeLists.txt
@@ -15,11 +15,28 @@ project(SwiftSyntax LANGUAGES C Swift)
set(SWIFT_VERSION 5)
set(CMAKE_Swift_LANGUAGE_VERSION ${SWIFT_VERSION})
+if(CMAKE_VERSION VERSION_LESS 3.21)
+ get_property(parent_dir DIRECTORY PROPERTY PARENT_DIRECTORY)
+ if(NOT parent_dir)
+ set(PROJECT_IS_TOP_LEVEL TRUE)
+ endif()
+endif()
+
# The subdirectory into which host libraries will be installed.
set(SWIFT_HOST_LIBRARIES_SUBDIRECTORY "swift/host")
-set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
-set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
+if(SWIFT_HOST_LIBRARIES_DEST_DIR)
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
+else()
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
+endif()
+if(SWIFT_HOST_RUNTIME_DEST_DIR)
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${SWIFT_HOST_RUNTIME_DEST_DIR}")
+else()
+ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
+endif()
set(CMAKE_MACOSX_RPATH YES)
@@ -49,22 +65,25 @@ if (NOT SWIFT_SUPPORTS_DISABLE_IMPLICIT_STRING_PROCESSING_MODULE_IMPORT)
endif()
# Determine the module triple.
-# FIXME: This is a hack. It's all a hack. Windows isn't setting
-# CMAKE_Swift_COMPILER_TARGET.
-if(CMAKE_Swift_COMPILER_TARGET)
- string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_MODULE_TRIPLE
- ${CMAKE_Swift_COMPILER_TARGET})
-elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
- if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
- set(SWIFT_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
- elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
- set(SWIFT_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
+if("${SWIFT_HOST_MODULE_TRIPLE}" STREQUAL "")
+ # FIXME: This is a hack. It's all a hack. Windows isn't setting
+ # CMAKE_Swift_COMPILER_TARGET.
+ if(CMAKE_Swift_COMPILER_TARGET)
+ string(REGEX REPLACE "macosx[0-9]+([.][0-9]+)?" "macos" SWIFT_HOST_MODULE_TRIPLE
+ ${CMAKE_Swift_COMPILER_TARGET})
+ elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64")
+ set(SWIFT_HOST_MODULE_TRIPLE "x86_64-unknown-windows-msvc")
+ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64")
+ set(SWIFT_HOST_MODULE_TRIPLE "aarch64-unknown-windows-msvc")
+ else()
+ message(FATAL_ERROR "Unrecognized architecture for Windows host")
+ endif()
else()
- message(FATAL_ERROR "Unrecognized architecture for Windows host")
+ message(FATAL_ERROR "Host module triple required")
endif()
endif()
-
-message(STATUS "Module triple: ${SWIFT_MODULE_TRIPLE}")
+message(STATUS "Module triple: ${SWIFT_HOST_MODULE_TRIPLE}")
# Force single-threaded-only syntax trees to eliminate the Darwin
# dependency in the compiler.
@@ -79,9 +98,9 @@ endif()
add_subdirectory(Sources)
-export(EXPORT SwiftSyntaxTargets
- FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftSyntaxTargets.cmake"
- NAMESPACE SwiftSyntax::
-)
-
-add_subdirectory(cmake/modules)
+if(PROJECT_IS_TOP_LEVEL)
+ export(EXPORT SwiftSyntaxTargets
+ FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/SwiftSyntaxTargets.cmake"
+ NAMESPACE SwiftSyntax::
+ )
+endif()
diff --git a/swift-syntax/Sources/CMakeLists.txt b/swift-syntax/Sources/CMakeLists.txt
index 3b317b0891..a6f6c9f5bc 100644
--- a/swift-syntax/Sources/CMakeLists.txt
+++ b/swift-syntax/Sources/CMakeLists.txt
@@ -6,31 +6,6 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-# cmake generation for Swift adds an order only dependency, which matches how C-family languages
-# works. In that case, however, ninja (and presumably other generators) will rebuild on header
-# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
-# ABI/API of B changes.
-#
-# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
-# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
-# seem to be being tracked.
-#
-# Remove once rdar://102202478 is fixed.
-function(target_link_libraries TARGET)
- cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
-
- _target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
- foreach(DEPENDENCY ${ARGS_PUBLIC})
- 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
- )
- endforeach()
-endfunction()
-
add_subdirectory(SwiftBasicFormat)
add_subdirectory(SwiftSyntax)
add_subdirectory(SwiftDiagnostics)
diff --git a/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt b/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
index 4c6c2dcb82..05859828e7 100644
--- a/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftBasicFormat/CMakeLists.txt
@@ -6,12 +6,12 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftBasicFormat
+add_swift_syntax_library(SwiftBasicFormat
BasicFormat.swift
generated/BasicFormat+Extensions.swift
SyntaxProtocol+Formatted.swift
Trivia+FormatExtensions.swift
)
-target_link_libraries(SwiftBasicFormat PUBLIC
+target_link_swift_syntax_libraries(SwiftBasicFormat PUBLIC
SwiftSyntax)
diff --git a/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt b/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
index c6e7c42432..f01fc1f2f1 100644
--- a/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftCompilerPluginMessageHandling/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftCompilerPluginMessageHandling
+add_swift_syntax_library(SwiftCompilerPluginMessageHandling
CompilerPluginMessageHandler.swift
Diagnostics.swift
Macros.swift
@@ -15,7 +15,7 @@ add_swift_host_library(SwiftCompilerPluginMessageHandling
PluginMessages.swift
)
-target_link_libraries(SwiftCompilerPluginMessageHandling PUBLIC
+target_link_swift_syntax_libraries(SwiftCompilerPluginMessageHandling PUBLIC
SwiftSyntax
SwiftBasicFormat
SwiftDiagnostics
diff --git a/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt b/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
index 05281ea0bf..9807022350 100644
--- a/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftDiagnostics/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftDiagnostics
+add_swift_syntax_library(SwiftDiagnostics
Diagnostic.swift
DiagnosticsFormatter.swift
FixIt.swift
@@ -16,5 +16,5 @@ add_swift_host_library(SwiftDiagnostics
Note.swift
)
-target_link_libraries(SwiftDiagnostics PUBLIC
+target_link_swift_syntax_libraries(SwiftDiagnostics PUBLIC
SwiftSyntax)
diff --git a/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt b/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
index 309fd3efa3..3909d29315 100644
--- a/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftIDEUtils/CMakeLists.txt
@@ -6,11 +6,11 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftIDEUtils
+add_swift_syntax_library(SwiftIDEUtils
generated/SyntaxClassification.swift
Syntax+Classifications.swift
SyntaxClassifier.swift
)
-target_link_libraries(SwiftIDEUtils PUBLIC
+target_link_swift_syntax_libraries(SwiftIDEUtils PUBLIC
SwiftSyntax)
diff --git a/swift-syntax/Sources/SwiftOperators/CMakeLists.txt b/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
index 886590411b..998b51abb6 100644
--- a/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftOperators/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftOperators
+add_swift_syntax_library(SwiftOperators
Operator.swift
OperatorError+Diagnostics.swift
OperatorError.swift
@@ -19,7 +19,7 @@ add_swift_host_library(SwiftOperators
SyntaxSynthesis.swift
)
-target_link_libraries(SwiftOperators PUBLIC
+target_link_swift_syntax_libraries(SwiftOperators PUBLIC
SwiftSyntax
SwiftDiagnostics
SwiftParser)
diff --git a/swift-syntax/Sources/SwiftParser/CMakeLists.txt b/swift-syntax/Sources/SwiftParser/CMakeLists.txt
index ae849ac9de..c5cce15b45 100644
--- a/swift-syntax/Sources/SwiftParser/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftParser/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftParser
+add_swift_syntax_library(SwiftParser
Attributes.swift
Availability.swift
CharacterInfo.swift
@@ -52,6 +52,6 @@ add_swift_host_library(SwiftParser
Lexer/UnicodeScalarExtensions.swift
)
-target_link_libraries(SwiftParser PUBLIC
+target_link_swift_syntax_libraries(SwiftParser PUBLIC
SwiftSyntax
SwiftDiagnostics)
diff --git a/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt b/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
index 91be323333..d73590bb0f 100644
--- a/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftParserDiagnostics/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftParserDiagnostics
+add_swift_syntax_library(SwiftParserDiagnostics
DiagnosticExtensions.swift
LexerDiagnosticMessages.swift
MissingNodesError.swift
@@ -23,7 +23,7 @@ add_swift_host_library(SwiftParserDiagnostics
generated/TokenNameForDiagnostics.swift
)
-target_link_libraries(SwiftParserDiagnostics PUBLIC
+target_link_swift_syntax_libraries(SwiftParserDiagnostics PUBLIC
SwiftBasicFormat
SwiftDiagnostics
SwiftParser
diff --git a/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
index 90c10e098b..5e59ce0e23 100644
--- a/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftSyntax/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftSyntax
+add_swift_syntax_library(SwiftSyntax
AbsolutePosition.swift
Assert.swift
BumpPtrAllocator.swift
diff --git a/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
index 36f5f1c900..38858cee6f 100644
--- a/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftSyntaxBuilder/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftSyntaxBuilder
+add_swift_syntax_library(SwiftSyntaxBuilder
ConvenienceInitializers.swift
Indenter.swift
ResultBuilderExtensions.swift
@@ -30,7 +30,7 @@ add_swift_host_library(SwiftSyntaxBuilder
target_compile_options(SwiftSyntaxBuilder PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-D;SWIFTSYNTAX_NO_OSLOG_DEPENDENCY>)
-target_link_libraries(SwiftSyntaxBuilder PUBLIC
+target_link_swift_syntax_libraries(SwiftSyntaxBuilder PUBLIC
SwiftBasicFormat
SwiftParser
SwiftParserDiagnostics
diff --git a/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
index ad311fa5ee..d1a635f337 100644
--- a/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftSyntaxMacroExpansion/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_swift_host_library(SwiftSyntaxMacroExpansion
+add_swift_syntax_library(SwiftSyntaxMacroExpansion
BasicMacroExpansionContext.swift
FunctionParameterUtils.swift
MacroExpansion.swift
@@ -8,7 +8,7 @@ add_swift_host_library(SwiftSyntaxMacroExpansion
Syntax+MacroEvaluation.swift
)
-target_link_libraries(SwiftSyntaxMacroExpansion PUBLIC
+target_link_swift_syntax_libraries(SwiftSyntaxMacroExpansion PUBLIC
SwiftSyntax
SwiftSyntaxMacros
)
diff --git a/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt b/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
index 757b5eba93..d4dd2270d2 100644
--- a/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
+++ b/swift-syntax/Sources/SwiftSyntaxMacros/CMakeLists.txt
@@ -6,7 +6,7 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
-add_swift_host_library(SwiftSyntaxMacros
+add_swift_syntax_library(SwiftSyntaxMacros
MacroProtocols/AccessorMacro.swift
MacroProtocols/AttachedMacro.swift
MacroProtocols/CodeItemMacro.swift
@@ -24,6 +24,6 @@ add_swift_host_library(SwiftSyntaxMacros
MacroExpansionContext.swift
)
-target_link_libraries(SwiftSyntaxMacros PUBLIC
+target_link_swift_syntax_libraries(SwiftSyntaxMacros PUBLIC
SwiftSyntaxBuilder
)
diff --git a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
index 6428f80638..951c2d2e05 100644
--- a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
+++ b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
@@ -6,22 +6,44 @@
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
+# cmake generation for Swift adds an order only dependency, which matches how C-family languages
+# works. In that case, however, ninja (and presumably other generators) will rebuild on header
+# changes. That's not the case for Swift, and thus if A -> B, A is not being rebuilt when the
+# ABI/API of B changes.
+#
+# For now workaround this by touching a file whenever B is rebuilt and then compiling that file as
+# part of A. Ideally this file would be generated by each of the targets, but that dependency didn't
+# seem to be being tracked.
+#
+# Remove once rdar://102202478 is fixed.
+function(target_link_swift_syntax_libraries TARGET)
+ cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
+
+ target_link_libraries(${TARGET} PUBLIC ${ARGS_PUBLIC})
+ foreach(DEPENDENCY ${ARGS_PUBLIC})
+ 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
+ )
+ endforeach()
+endfunction()
+
# Add a new host library with the given name.
-function(add_swift_host_library name)
+function(add_swift_syntax_library name)
set(ASHL_SOURCES ${ARGN})
# Create the library target.
add_library(${name} ${ASHL_SOURCES})
- # Add this to the list of exported targets.
- set_property(GLOBAL APPEND PROPERTY SWIFTSYNTAX_EXPORTS ${name})
-
# Determine where Swift modules will be built and installed.
set(module_dir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(module_base "${module_dir}/${name}.swiftmodule")
- set(module_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftmodule")
- set(module_interface_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftinterface")
- set(module_sourceinfo_file "${module_base}/${SWIFT_MODULE_TRIPLE}.swiftsourceinfo")
+ set(module_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftmodule")
+ set(module_interface_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftinterface")
+ set(module_sourceinfo_file "${module_base}/${SWIFT_HOST_MODULE_TRIPLE}.swiftsourceinfo")
# Add a custom target to create the module directory.
add_custom_command(
@@ -61,6 +83,18 @@ function(add_swift_host_library name)
-emit-module-interface-path;${module_interface_file}
>)
+ if(SWIFT_HOST_TRIPLE)
+ target_compile_options("${name}" PRIVATE
+ $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE};>
+ )
+ endif()
+
+ if(LLVM_USE_LINKER)
+ target_link_options(${name} PRIVATE
+ "-use-ld=${LLVM_USE_LINKER}"
+ )
+ endif()
+
# NOTE: workaround for CMake not setting up include flags yet
set_target_properties(${name} PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES ${module_dir}
@@ -70,31 +104,39 @@ function(add_swift_host_library name)
BUILD_WITH_INSTALL_RPATH YES
)
+ if(SWIFT_HOST_LIBRARIES_RPATH)
+ # Don't add builder's stdlib RPATH automatically.
+ target_compile_options(${name} PRIVATE -no-toolchain-stdlib-rpath)
+ set_property(TARGET ${name}
+ PROPERTY INSTALL_RPATH "${SWIFT_HOST_LIBRARIES_RPATH}"
+ )
+ endif()
+
get_target_property(lib_type ${name} TYPE)
if(lib_type STREQUAL SHARED_LIBRARY)
if (CMAKE_SYSTEM_NAME STREQUAL Darwin)
# Allow install_name_tool to update paths (for rdar://109473564)
set_property(TARGET ${name} APPEND_STRING PROPERTY
LINK_FLAGS " -Xlinker -headerpad_max_install_names")
- elseif (CMAKE_SYSTEM_NAME STREQUAL Linux)
- # Make some room to update paths.
- set_property(TARGET ${name} APPEND PROPERTY
- INSTALL_RPATH ":::::::::::::::::::::::::::::::::::::::::::::::::::::::")
endif()
endif()
- # Install this target
- install(TARGETS ${name}
- EXPORT SwiftSyntaxTargets
- ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
- LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
- RUNTIME DESTINATION bin
- )
+ if(PROJECT_IS_TOP_LEVEL)
+ # Install this target
+ install(TARGETS ${name}
+ EXPORT SwiftSyntaxTargets
+ ARCHIVE DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
+ LIBRARY DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
+ RUNTIME DESTINATION bin
+ )
- # Install the module files.
- install(
- DIRECTORY ${module_base}
- DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
- FILES_MATCHING PATTERN "*.swiftinterface"
- )
+ # Install the module files.
+ install(
+ DIRECTORY ${module_base}
+ DESTINATION lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}
+ FILES_MATCHING PATTERN "*.swiftinterface"
+ )
+ else()
+ set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
+ endif()
endfunction()
diff --git a/swift-syntax/cmake/modules/CMakeLists.txt b/swift-syntax/cmake/modules/CMakeLists.txt
deleted file mode 100644
index 069c64c0af..0000000000
--- a/swift-syntax/cmake/modules/CMakeLists.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-get_property(SWIFTSYNTAX_EXPORTS GLOBAL PROPERTY SWIFTSYNTAX_EXPORTS)
-export(TARGETS ${SWIFTSYNTAX_EXPORTS}
- FILE ${CMAKE_CURRENT_BINARY_DIR}/SwiftSyntaxConfig.cmake
- NAMESPACE SwiftSyntax::)

View File

@ -0,0 +1,152 @@
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index 28dfded4ecc..45c68998bec 100644
--- a/swift/CMakeLists.txt
+++ b/swift/CMakeLists.txt
@@ -950,7 +950,7 @@ 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")
+ if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD" AND NOT BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS|OFF")
message(WARNING "Force setting BOOTSTRAPPING=HOSTTOOLS because Swift parser integration is enabled")
set(BOOTSTRAPPING_MODE "HOSTTOOLS")
endif()
@@ -1345,6 +1345,9 @@ if(SWIFT_INCLUDE_TOOLS)
FetchContent_MakeAvailable(SwiftSyntax)
endfunction()
include_swift_syntax()
+ if (NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
+ add_dependencies(SwiftSyntax swift-stdlib-android-${SWIFT_HOST_VARIANT_ARCH})
+ endif()
add_subdirectory(lib)
diff --git a/swift/cmake/modules/AddPureSwift.cmake b/swift/cmake/modules/AddPureSwift.cmake
index dc58b8fa0f6..37e9f817471 100644
--- a/swift/cmake/modules/AddPureSwift.cmake
+++ b/swift/cmake/modules/AddPureSwift.cmake
@@ -44,6 +44,12 @@ function(_add_host_swift_compile_options name)
$<$<COMPILE_LANGUAGE:Swift>:none>)
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE}>)
+ if (NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
+ swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-resource-dir;${SWIFTLIB_DIR};>
+ $<$<COMPILE_LANGUAGE:Swift>:-sdk;${SWIFT_SDK_ANDROID_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH};>
+ $<$<COMPILE_LANGUAGE:Swift>:-tools-directory;${tools_path};>)
+ endif()
_add_host_variant_swift_sanitizer_flags(${name})
endfunction()
@@ -76,7 +76,7 @@ function(_set_pure_swift_link_flags name relpath_to_lib_dir)
APPEND PROPERTY INSTALL_RPATH
# At runtime, use swiftCore in the current just-built toolchain.
# NOTE: This relies on the ABI being the same as the builder.
- "$ORIGIN/${relpath_to_lib_dir}/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}"
+ "$ORIGIN/${relpath_to_lib_dir}"
)
# NOTE: At this point we don't have any pure swift executables/shared
# libraries required for building runtime/stdlib. So we don't need to add
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index ecdea6de266..777ea384050 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -442,7 +442,11 @@ endfunction()
function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
if(NOT BOOTSTRAPPING_MODE)
if (SWIFT_BUILD_SWIFT_SYNTAX)
- set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
+ if (NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
+ set(ASRLF_BOOTSTRAPPING_MODE "CROSSCOMPILE")
+ else()
+ set(ASRLF_BOOTSTRAPPING_MODE "HOSTTOOLS")
+ endif()
else()
return()
endif()
diff --git a/swift/stdlib/cmake/modules/SwiftSource.cmake b/swift/stdlib/cmake/modules/SwiftSource.cmake
--- a/swift/stdlib/cmake/modules/SwiftSource.cmake
+++ b/swift/stdlib/cmake/modules/SwiftSource.cmake
@@ -777,7 +777,7 @@
endif()
set(swift_compiler_tool_dep)
- if(SWIFT_INCLUDE_TOOLS AND NOT ${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE")
+ if(SWIFT_INCLUDE_TOOLS AND NOT ${BOOTSTRAPPING_MODE} STREQUAL "CROSSCOMPILE" AND "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
# Depend on the binary itself, in addition to the symlink.
set(swift_compiler_tool_dep "swift-frontend${target_suffix}")
endif()
diff --git a/swift/tools/libStaticMirror/CMakeLists.txt b/swift/tools/libStaticMirror/CMakeLists.txt
index 1b8c563b05a..463faab64de 100644
--- a/swift/tools/libStaticMirror/CMakeLists.txt
+++ b/swift/tools/libStaticMirror/CMakeLists.txt
@@ -28,6 +28,9 @@ add_llvm_symbol_exports(libStaticMirror ${LLVM_EXPORTED_SYMBOL_FILE})
# Adds -dead_strip option
add_link_opts(libStaticMirror)
+if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
+ target_link_options(libStaticMirror PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc")
+endif()
add_dependencies(static-mirror-lib libStaticMirror)
swift_install_in_component(TARGETS libStaticMirror
diff --git a/swift/tools/libSwiftScan/CMakeLists.txt b/swift/tools/libSwiftScan/CMakeLists.txt
index 1a99080337f..163a8d45690 100644
--- a/swift/tools/libSwiftScan/CMakeLists.txt
+++ b/swift/tools/libSwiftScan/CMakeLists.txt
@@ -66,6 +66,9 @@ add_llvm_symbol_exports(libSwiftScan ${LLVM_EXPORTED_SYMBOL_FILE})
# Adds -dead_strip option
add_link_opts(libSwiftScan)
+if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
+ target_link_options(libSwiftScan PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc")
+endif()
add_dependencies(compiler libSwiftScan)
diff --git a/swift/tools/swift-plugin-server/CMakeLists.txt b/swift/tools/swift-plugin-server/CMakeLists.txt
index a21b79ed260..5b591a30514 100644
--- a/swift/tools/swift-plugin-server/CMakeLists.txt
+++ b/swift/tools/swift-plugin-server/CMakeLists.txt
@@ -11,16 +11,21 @@ if (SWIFT_BUILD_SWIFT_SYNTAX)
Sources/CSwiftPluginServer/include
)
- add_pure_swift_host_tool(swift-plugin-server
+ add_swift_host_tool(swift-plugin-server SWIFT_COMPONENT compiler)
+ add_pure_swift_host_library(SwiftPluginServer STATIC
Sources/swift-plugin-server/swift-plugin-server.swift
- DEPENDENCIES
+ )
+ target_include_directories(SwiftPluginServer PUBLIC
+ Sources/CSwiftPluginServer/include
+ )
+ target_link_libraries(swift-plugin-server PRIVATE
swiftDemangling
$<TARGET_OBJECTS:_swiftCSwiftPluginServer>
- SWIFT_DEPENDENCIES
SwiftSyntaxMacros
SwiftSyntaxMacroExpansion
SwiftCompilerPluginMessageHandling
swiftLLVMJSON
+ SwiftPluginServer
)
target_include_directories(swift-plugin-server PRIVATE
Sources/CSwiftPluginServer/include
diff --git a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
index 951c2d2e..1157ec66 100644
--- a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
+++ b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake
@@ -87,6 +87,12 @@ function(add_swift_syntax_library name)
target_compile_options("${name}" PRIVATE
$<$<COMPILE_LANGUAGE:Swift>:-target;${SWIFT_HOST_TRIPLE};>
)
+ if (NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
+ swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path)
+ target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:Swift>:-resource-dir;${SWIFTLIB_DIR};>
+ $<$<COMPILE_LANGUAGE:Swift>:-sdk;${SWIFT_SDK_ANDROID_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH};>
+ $<$<COMPILE_LANGUAGE:Swift>:-tools-directory;${tools_path};>)
+ endif()
endif()
if(LLVM_USE_LINKER)

View File

@ -0,0 +1,32 @@
commit 1a7d44a11d4f06882c4a563b67e1f1b864c4c794
Author: John McCall <rjmccall@apple.com>
Date: Tue Jul 18 13:21:12 2023 -0400
Diagnose attempts to reabstract variadic function types in unimplementable ways.
diff --git a/swift/include/swift/AST/CASTBridging.h b/swift/include/swift/AST/CASTBridging.h
index 69f017855d7..6cb23ad4c85 100644
--- a/swift/include/swift/AST/CASTBridging.h
+++ b/swift/include/swift/AST/CASTBridging.h
@@ -190,6 +190,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long {
BridgedTypeAttrKind_opened,
BridgedTypeAttrKind_pack_element,
BridgedTypeAttrKind_pseudogeneric,
+ BridgedTypeAttrKind_unimplementable,
BridgedTypeAttrKind_yields,
BridgedTypeAttrKind_yield_once,
BridgedTypeAttrKind_yield_many,
diff --git a/swift/lib/ASTGen/Sources/ASTGen/Types.swift b/swift/lib/ASTGen/Sources/ASTGen/Types.swift
index 34a185fe13f..89eec154f03 100644
--- a/swift/lib/ASTGen/Sources/ASTGen/Types.swift
+++ b/swift/lib/ASTGen/Sources/ASTGen/Types.swift
@@ -222,7 +222,8 @@ extension ASTGenVisitor {
case .autoclosure, .escaping, .noescape, .noDerivative, .async,
.sendable, .unchecked, ._local, ._noMetadata, .pack_owned,
.pack_guaranteed, .pack_inout, .pack_out, .pseudogeneric,
- .yields, .yield_once, .yield_many, .thin, .thick, .count:
+ .yields, .yield_once, .yield_many, .thin, .thick, .count,
+ .unimplementable:
TypeAttributes_addSimpleAttr(typeAttributes, typeAttrKind, atLoc, attrLoc)
case .opened, .pack_element, .differentiable, .convention,

View File

@ -2,7 +2,7 @@ diff --git a/swift/utils/build-script-impl b/swift/utils/build-script-impl
index b1d060328bc..218c9215260 100755
--- a/swift/utils/build-script-impl
+++ b/swift/utils/build-script-impl
@@ -1854,6 +1854,9 @@ for host in "${ALL_HOSTS[@]}"; do
@@ -1769,6 +1769,9 @@ for host in "${ALL_HOSTS[@]}"; do
"${cmake_options[@]}"
-DLLVM_TABLEGEN=$(build_directory "${LOCAL_HOST}" llvm)/bin/llvm-tblgen
-DSWIFT_INCLUDE_TEST_BINARIES:BOOL=FALSE
@ -12,10 +12,24 @@ index b1d060328bc..218c9215260 100755
)
fi
@@ -1784,6 +1784,13 @@ for host in "${ALL_HOSTS[@]}"; do
native_swift_tools_path="${NATIVE_SWIFT_TOOLS_PATH}"
fi
+ if [[ $(is_cross_tools_host ${host}) && "${host}" != "macosx-"* ]] ; then
+ cmake_options=(
+ "${cmake_options[@]}"
+ -DCMAKE_Swift_COMPILER:PATH="${native_swift_tools_path}/swiftc"
+ )
+ fi
+
if [ "${BUILD_LLVM}" == "0" ] ; then
cmake_options=(
"${cmake_options[@]}"
@@ -2035,6 +2035,7 @@ for host in "${ALL_HOSTS[@]}"; do
-DSWIFT_BUILD_RUNTIME_WITH_HOST_COMPILER:BOOL=$(true_false "${BUILD_RUNTIME_WITH_HOST_COMPILER}")
-DLIBDISPATCH_CMAKE_BUILD_TYPE:STRING="${LIBDISPATCH_BUILD_TYPE}"
-DSWIFT_PATH_TO_SWIFT_SYNTAX_SOURCE:PATH="${SWIFT_SYNTAX_SOURCE_DIR}"
-DSWIFT_ENABLE_BACKTRACING:BOOL=$(true_false "${SWIFT_ENABLE_BACKTRACING}")
+ -DSWIFT_CLANG_RESOURCE_DIR_SYMLINK_INSTALL_TARGET:STRING="../clang/${TERMUX_CLANG_VERSION}"
"${swift_cmake_options[@]}"
)

View File

@ -0,0 +1,19 @@
diff --git a/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift b/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
index 9e2529d00..ef22cbefa 100644
--- a/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
+++ b/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
@@ -308,14 +308,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
args += self.buildParameters.linkerFlags
args += self.stripInvalidArguments(self.buildParameters.swiftCompilerFlags)
- // Add toolchain's libdir at the very end (even after the user -Xlinker arguments).
- //
- // This will allow linking to libraries shipped in the toolchain.
- let toolchainLibDir = try buildParameters.toolchain.toolchainLibDir
- if self.fileSystem.isDirectory(toolchainLibDir) {
- args += ["-L", toolchainLibDir.pathString]
- }
-
// Library search path for the toolchain's copy of SwiftSyntax.
#if BUILD_MACROS_AS_DYLIBS
if product.type == .macro {

View File

@ -1,21 +0,0 @@
This breaks cross-compilation of Swift packages after moving the runtime libraries to $PREFIX/lib.
diff --git a/swiftpm/Sources/Build/BuildPlan.swift b/swiftpm/Sources/Build/BuildPlan.swift
index 08104f1cf..de93111c5 100644
--- a/swiftpm/Sources/Build/BuildPlan.swift
+++ b/swiftpm/Sources/Build/BuildPlan.swift
@@ -1538,15 +1538,6 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
// User arguments (from -Xlinker and -Xswiftc) should follow generated arguments to allow user overrides
args += buildParameters.linkerFlags
args += stripInvalidArguments(buildParameters.swiftCompilerFlags)
-
- // Add toolchain's libdir at the very end (even after the user -Xlinker arguments).
- //
- // This will allow linking to libraries shipped in the toolchain.
- let toolchainLibDir = try buildParameters.toolchain.toolchainLibDir
- if self.fileSystem.isDirectory(toolchainLibDir) {
- args += ["-L", toolchainLibDir.pathString]
- }
-
return args
}

View File

@ -14,11 +14,11 @@ diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 085056de..1ded1a90 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -827,6 +827,7 @@ def get_swiftpm_flags(args):
if '-android' in args.build_target:
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
build_flags.extend(["-Xlinker", "-landroid-spawn"])
+ build_flags.extend(["--pkg-config-path", os.path.join(os.path.split(args.cross_compile_config)[0], 'lib/pkgconfig')])
@@ -834,6 +834,7 @@ def get_swiftpm_flags(args):
build_flags += ["--arch", "x86_64", "--arch", "arm64"]
elif cross_compile_hosts.startswith('android-'):
build_flags.extend(["--destination", args.cross_compile_config])
+ build_flags.extend(["--pkg-config-path", os.path.join(os.path.split(args.cross_compile_config)[0], "lib/pkgconfig")])
else:
error("cannot cross-compile for %s" % cross_compile_hosts)
cross_compile_hosts = args.cross_compile_hosts
if cross_compile_hosts:

View File

@ -5,8 +5,8 @@ fi
install_path=$install_path/lib
for so in Foundation FoundationNetworking FoundationXML XCTest swiftCore swiftDispatch \
swiftDistributed swiftGlibc swiftRegexBuilder swiftRemoteMirror swiftSwiftOnoneSupport \
swift_Concurrency swift_Differentiation swift_RegexParser swift_StringProcessing
swiftDistributed swiftGlibc swiftObservation swiftRegexBuilder swiftRemoteMirror \
swiftSwiftOnoneSupport swift_Concurrency swift_Differentiation swift_RegexParser swift_StringProcessing
do
@COMMAND@
done

View File

@ -19,7 +19,7 @@ termux_setup_swift() {
termux_download \
https://download.swift.org/swift-$TERMUX_SWIFT_VERSION-release/ubuntu2204/swift-$TERMUX_SWIFT_VERSION-$SWIFT_RELEASE/$SWIFT_BIN.tar.gz \
$SWIFT_TAR \
2eb8105db0288443bda214b4b84d898970d1fecf08f0f5dcd5bd45bef528a4f7
bca015e9d727ca39385d7e5b5399f46302d54a02218d40d1c3063662ffc6b42f
(cd $TERMUX_PKG_TMPDIR ; tar xf $SWIFT_TAR ; mv $SWIFT_BIN $SWIFT_FOLDER; rm $SWIFT_TAR)
fi