bump(swift): 5.9.2 to 5.10

This commit is contained in:
Finagolfin 2024-03-06 06:27:00 +05:30 committed by finagolfin
parent 189d3d5c49
commit 68f281f257
20 changed files with 6777 additions and 7682 deletions

View File

@ -2,9 +2,8 @@ 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.9"
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION="1:5.10"
TERMUX_PKG_SRCURL=https://github.com/apple/swift-corelibs-libdispatch/archive/swift-${TERMUX_PKG_VERSION:2}-RELEASE.tar.gz
TERMUX_PKG_SHA256=db30ccf6b20963112ab3aad256c2e49a18041a9806cf2f05854fe63a90d688c2
TERMUX_PKG_SHA256=16e088cf12654d22658879710b9694a6fad1c94d5e5d0c597741b71fbcb3e034
TERMUX_PKG_AUTO_UPDATE=false
TERMUX_PKG_DEPENDS="libc++, libblocksruntime"

View File

@ -2,9 +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.9
TERMUX_PKG_REVISION=1
TERMUX_PKG_VERSION=5.10
TERMUX_PKG_SRCURL=https://github.com/apple/swift-llbuild/archive/swift-${TERMUX_PKG_VERSION}-RELEASE.tar.gz
TERMUX_PKG_SHA256=cc8dfb098db4b0210ca5466f59d3e5fc55c4eedcd835263e6eae7dd719ba8203
TERMUX_PKG_SHA256=ae8962d59244abac157c02813d05e1c077915bbd6022fe9fb62040806ac8dc55
TERMUX_PKG_DEPENDS="libc++, libandroid-spawn, libsqlite"
TERMUX_PKG_NO_STATICSPLIT=true

View File

@ -2,10 +2,10 @@ 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.9.2
TERMUX_PKG_VERSION=5.10
SWIFT_RELEASE="RELEASE"
TERMUX_PKG_SRCURL=https://github.com/apple/swift/archive/swift-$TERMUX_PKG_VERSION-$SWIFT_RELEASE.tar.gz
TERMUX_PKG_SHA256=5b93c737c24ba7d861e0777800740eaa9ccddfa2a6a4326bd47dbc5aa9ae8379
TERMUX_PKG_SHA256=874c3b6668fb138db35c9f1c63570dafacac8476a6094b17764a51a45a1b69a2
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, pkg-config, swift-sdk-${TERMUX_ARCH/_/-}"
@ -35,43 +35,44 @@ termux_step_post_get_source() {
mv .temp swift
declare -A library_checksums
library_checksums[swift-cmark]=658f4eb94f271e68af4ae07f4214f58d36dfc8edd7fc17ac44e8c85bec984337
library_checksums[llvm-project]=9df7cacc0107202dcdee8025d5cec9fe413f164e28921372acc61fddd78ed473
library_checksums[swift-experimental-string-processing]=3abc4225789e19defae966f7d9a712c77a5c0366f1d44d37df671048fe62daf6
library_checksums[swift-syntax]=b1918519f5bc6c7820f14242adfe26d9520a91896349a486359d9809b4e89351
library_checksums[swift-corelibs-libdispatch]=b1f3e46ed248df6a3456d20bc23b2d8a12b740a40185d81b668b1d31735cadf2
library_checksums[swift-corelibs-foundation]=e58c529ababd547cf0b205fc0820ccce38a033664625c271110b564f2554dd44
library_checksums[swift-corelibs-xctest]=7f0d21ce0bb15ed5275b0d6e5ee1747344d9756c9f1913a644a0b2142ee1fb19
library_checksums[swift-llbuild]=44bcb0f8c6fa6cccdc16b7e75c996987568d8fde3caf8bc83c24a2e10383406f
library_checksums[swift-argument-parser]=44782ba7180f924f72661b8f457c268929ccd20441eac17301f18eff3b91ce0c
library_checksums[swift-cmark]=6b7377e78b59410f8f3993cd6b83fe35fd097369a5cf89aa77c0e8b86d2218ee
library_checksums[llvm-project]=107e88150257e0c12333b4c43baa371a4252118e4977a69f5a16c566ee9f2cd3
library_checksums[swift-experimental-string-processing]=542fa52af41287772ff36a18f4a8971e0aec07dbf4c59400e6d3422ab42d46df
library_checksums[swift-syntax]=bec161cf707758d34d208c8e00bc338603094b489a9388caff79db1af3af20c7
library_checksums[swift-corelibs-libdispatch]=16e088cf12654d22658879710b9694a6fad1c94d5e5d0c597741b71fbcb3e034
library_checksums[swift-corelibs-foundation]=e25700bffc439b36c5c9acf169332c0dd9805fcd91cd570b4ce96163b70bae5b
library_checksums[swift-corelibs-xctest]=b298316185270ac43ecdaf4c2fbd4329af51a18b174650510d7526238e9ca6fa
library_checksums[swift-llbuild]=ae8962d59244abac157c02813d05e1c077915bbd6022fe9fb62040806ac8dc55
library_checksums[swift-argument-parser]=4a10bbef290a2167c5cc340b39f1f7ff6a8cf4e1b5433b68548bf5f1e542e908
library_checksums[Yams]=ec1ad699c30f0db45520006c63a88cc1c946a7d7b36dff32a96460388c0a4af2
library_checksums[swift-collections]=575cf0f88d9068411f9acc6e3ca5d542bef1cc9e87dc5d69f7b5a1d5aec8c6b6
library_checksums[swift-crypto]=a7b2f5c4887ccd728cdff5d1162b4d4d36bd6c2df9c0c31d5b9b73d341c5c1bb
library_checksums[swift-collections]=d0f584b197860db26fd939175c9d1a7badfe7b89949b4bd52d4f626089776e0a
library_checksums[swift-crypto]=5c860c0306d0393ff06268f361aaf958656e1288353a0e23c3ad20de04319154
library_checksums[swift-system]=865b8c380455eef27e73109835142920c60ae4c4f4178a3d12ad04acc83f1371
library_checksums[swift-asn1]=d4470d61788194abbd60ed73965ee0722cc25037e83d41226a8a780088ba524e
library_checksums[swift-certificates]=d7699ce91d65a622c1b9aaa0235cbbbd1be4ddc42a90fce007ff74bef50e8985
library_checksums[swift-driver]=e4db5194e99ebbd605a14b86965b301b5a060482ecd1c5c94a4a099de5754e35
library_checksums[swift-tools-support-core]=e0ab6f07998865549ad4bff34c91a3947a50a0085890d2d32605dfff296980c8
library_checksums[swift-package-manager]=132ae4908fa9c8f10265585f593dc748a021a18b11d6a1881e22d2db2dd1e162
library_checksums[indexstore-db]=a907c8fce27e718c179f6a92b73df62675e44b86612116468ff6ebd3f2997b31
library_checksums[sourcekit-lsp]=0db3e5c56f2889a3be2ff4e9b5a285085459dee6f821c0cdf513eb5c9cc94ae4
library_checksums[swift-asn1]=e0da995ae53e6fcf8251887f44d4030f6600e2f8f8451d9c92fcaf52b41b6c35
library_checksums[swift-certificates]=fcaca458aab45ee69b0f678b72c2194b15664cc5f6f5e48d0e3f62bc5d1202ca
library_checksums[swift-driver]=51a48f1f277f4c5f87b8e1f08668e99ecd74f9fbee359ccde502cbb839eb7128
library_checksums[swift-tools-support-core]=36bb714e46966bdc48e9835e9440508f30f6c9d0b4479a1cebae0ab9f5952bb9
library_checksums[swift-package-manager]=857391656ef94e7ef249b5d05d6a4226c2ec070ddbdd182d7dac92de748ff526
library_checksums[indexstore-db]=b701755b9ecef2363b8f91ad3d1f8677d78f06e81857a10de9a835c72176c241
library_checksums[sourcekit-lsp]=e69f11068546ba1ee0015c68d3dbde0d053f1574ca643dd8d43e1d9dbc4cb2d7
for library in "${!library_checksums[@]}"; do \
GH_ORG="apple"
if [ "$library" = "swift-argument-parser" ]; then
SRC_VERSION="1.2.2"
SRC_VERSION="1.2.3"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-asn1" ]; then
SRC_VERSION="0.7.0"
SRC_VERSION="1.0.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-collections" ]; then
SRC_VERSION="1.0.5"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-crypto" ]; then
SRC_VERSION="2.5.0"
SRC_VERSION="3.0.0"
TAR_NAME=$SRC_VERSION
elif [ "$library" = "swift-system" ]; then
SRC_VERSION="1.1.1"
@ -133,7 +134,7 @@ termux_step_make() {
SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android
--android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_ARCH
--build-toolchain-only --skip-local-build --skip-local-host-install
--cross-compile-hosts=android-$SWIFT_ARCH --bootstrapping=off
--cross-compile-hosts=android-$SWIFT_ARCH
--cross-compile-deps-path=$(dirname $TERMUX_PREFIX)
--native-swift-tools-path=$SWIFT_BINDIR
--native-clang-tools-path=$SWIFT_BINDIR

View File

@ -205,93 +205,3 @@ index 4d6577d0..aa22dade 100644
messages = constructJobSignalledMessages(job: job, error: errorMessage, output: output,
signal: signal, pid: pid).map {
ParsableMessage(name: job.kind.rawValue, kind: .signalled($0))
diff --git a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
index b33b1c6..cd2ce5b 100644
--- a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
@@ -491,8 +491,8 @@ private struct LocalFileSystem: FileSystem {
func readFileContents(_ path: AbsolutePath) throws -> ByteString {
// Open the file.
- let fp = fopen(path.pathString, "rb")
- if fp == nil {
+ let fpo = fopen(path.pathString, "rb")
+ guard let fp = fpo else {
throw FileSystemError(errno: errno, path)
}
defer { fclose(fp) }
@@ -521,8 +521,8 @@ private struct LocalFileSystem: FileSystem {
func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws {
// Open the file.
- let fp = fopen(path.pathString, "wb")
- if fp == nil {
+ let fpo = fopen(path.pathString, "wb")
+ guard let fp = fpo else {
throw FileSystemError(errno: errno, path)
}
defer { fclose(fp) }
diff --git a/swift-tools-support-core/Sources/TSCBasic/Process.swift b/swift-tools-support-core/Sources/TSCBasic/Process.swift
index 6c8aa11..71d829c 100644
--- a/swift-tools-support-core/Sources/TSCBasic/Process.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/Process.swift
@@ -144,6 +144,9 @@ public final class Process {
/// The current OS does not support the workingDirectory API.
case workingDirectoryNotSupported
+
+ /// The stdin could not be opened.
+ case stdinNotOpening
}
public enum OutputRedirection {
@@ -677,7 +680,10 @@ public final class Process {
var stdinPipe: [Int32] = [-1, -1]
try open(pipe: &stdinPipe)
- let stdinStream = try LocalFileOutputByteStream(filePointer: fdopen(stdinPipe[1], "wb"), closeOnDeinit: true)
+ guard let fp = fdopen(stdinPipe[1], "wb") else {
+ throw Process.Error.stdinNotOpening
+ }
+ let stdinStream = try LocalFileOutputByteStream(filePointer: fp, closeOnDeinit: true)
// Dupe the read portion of the remote to 0.
posix_spawn_file_actions_adddup2(&fileActions, stdinPipe[0], 0)
@@ -1258,6 +1264,8 @@ extension Process.Error: CustomStringConvertible {
return "could not find executable for '\(program)'"
case .workingDirectoryNotSupported:
return "workingDirectory is not supported in this platform"
+ case .stdinNotOpening:
+ return "could not open stdin on this platform"
}
}
}
diff --git a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
index aee907e..2047d22 100644
--- a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
@@ -790,7 +790,11 @@ public final class LocalFileOutputByteStream: FileOutputByteStream {
override final func writeImpl(_ bytes: ArraySlice<UInt8>) {
bytes.withUnsafeBytes { bytesPtr in
while true {
+ #if os(Android)
+ let n = fwrite(bytesPtr.baseAddress!, 1, bytesPtr.count, filePointer)
+ #else
let n = fwrite(bytesPtr.baseAddress, 1, bytesPtr.count, filePointer)
+ #endif
if n < 0 {
if errno == EINTR { continue }
errorDetected(code: errno)
diff --git a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
index 59610b6..2797c71 100644
--- a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
+++ b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
@@ -24,7 +24,7 @@ public final class PseudoTerminal {
if openpty(&primary, &secondary, nil, nil, nil) != 0 {
return nil
}
- guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w"), closeOnDeinit: false) else {
+ guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w")!, closeOnDeinit: false) else {
return nil
}
self.outStream = outStream

View File

@ -44,27 +44,6 @@ index ac9e0871489d..b495cbfb5c2e 100644
RESULT_VARIABLE had_error
OUTPUT_VARIABLE library_file
)
diff --git a/llvm-project/llvm/cmake/modules/FindTerminfo.cmake b/llvm-project/llvm/cmake/modules/FindTerminfo.cmake
index 65edb80fa6..d02a445021 100644
--- a/llvm-project/llvm/cmake/modules/FindTerminfo.cmake
+++ b/llvm-project/llvm/cmake/modules/FindTerminfo.cmake
@@ -14,15 +14,7 @@
find_library(Terminfo_LIBRARIES NAMES terminfo tinfo curses ncurses ncursesw)
if(Terminfo_LIBRARIES)
- include(CMakePushCheckState)
- include(CheckCSourceCompiles)
- cmake_push_check_state()
- list(APPEND CMAKE_REQUIRED_LIBRARIES ${Terminfo_LIBRARIES})
- check_c_source_compiles("
- int setupterm(char *term, int filedes, int *errret);
- int main() { return setupterm(0, 0, 0); }"
- Terminfo_LINKABLE)
- cmake_pop_check_state()
+ set(Terminfo_LINKABLE 1)
endif()
include(FindPackageHandleStandardArgs)
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index b7503ecdd6..c643c2c9a5 100644
--- a/swift/CMakeLists.txt
@ -78,7 +57,24 @@ index b7503ecdd6..c643c2c9a5 100644
set(SWIFT_BUILD_HOST_DISPATCH TRUE)
endif()
@@ -976,7 +976,8 @@ if (LLVM_ENABLE_DOXYGEN)
@@ -857,7 +857,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|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()
@@ -1187,6 +1187,7 @@ if(SWIFT_INCLUDE_TOOLS)
message(STATUS " Assertions: ${LLVM_ENABLE_ASSERTIONS}")
message(STATUS " LTO: ${SWIFT_TOOLS_ENABLE_LTO}")
message(STATUS " Bootstrapping: ${BOOTSTRAPPING_MODE}")
+ message(STATUS " C++ Bridging: ${BRIDGING_MODE}")
message(STATUS " Swift parser: ${SWIFT_BUILD_SWIFT_SYNTAX}")
message(STATUS "")
else()
@@ -1279,7 +1280,8 @@ if (LLVM_ENABLE_DOXYGEN)
message(STATUS "Doxygen: enabled")
endif()
@ -88,6 +84,16 @@ index b7503ecdd6..c643c2c9a5 100644
include(Libdispatch)
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/SwiftCompilerSources/CMakeLists.txt b/swift/SwiftCompilerSources/CMakeLists.txt
index f4a2eb2dddc..61a2548cf77 100644
--- a/swift/SwiftCompilerSources/CMakeLists.txt
@ -111,19 +117,47 @@ index f4a2eb2dddc..61a2548cf77 100644
endforeach()
# Create a static library containing all module object files.
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,13 @@ 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};>)
+ add_dependencies(${name} swift-stdlib-android-${SWIFT_HOST_VARIANT_ARCH})
+ endif()
_add_host_variant_swift_sanitizer_flags(${name})
endfunction()
diff --git a/swift/cmake/modules/AddSwift.cmake b/swift/cmake/modules/AddSwift.cmake
index a448bcb23c4..0ddbac17a52 100644
--- a/swift/cmake/modules/AddSwift.cmake
+++ b/swift/cmake/modules/AddSwift.cmake
@@ -526,7 +526,7 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
# installed host toolchain.
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
@@ -548,7 +548,7 @@
get_filename_component(swift_bin_dir ${SWIFT_EXEC_FOR_SWIFT_MODULES} DIRECTORY)
get_filename_component(swift_dir ${swift_bin_dir} DIRECTORY)
endif()
- set(host_lib_dir "${swift_dir}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
+ set(host_lib_dir "${SWIFT_BINARY_DIR}/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
set(swiftrt "${host_lib_dir}/${SWIFT_HOST_VARIANT_ARCH}/swiftrt.o")
set(host_lib_arch_dir "${host_lib_dir}/${SWIFT_HOST_VARIANT_ARCH}")
target_link_libraries(${target} PRIVATE ${swiftrt})
set(swiftrt "${host_lib_arch_dir}/swiftrt${CMAKE_C_OUTPUT_EXTENSION}")
@@ -606,6 +606,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
endif()
endif()
endif()
+ if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID")
+ target_link_options(${target} PRIVATE "SHELL:-Xlinker -z -Xlinker nostart-stop-gc")
+ endif()
endif()
set_property(TARGET ${target} PROPERTY BUILD_WITH_INSTALL_RPATH YES)
diff --git a/swift/localization/CMakeLists.txt b/swift/localization/CMakeLists.txt
index 07a3585a66c..461a98b6856 100644
--- a/swift/localization/CMakeLists.txt
@ -138,18 +172,6 @@ index 07a3585a66c..461a98b6856 100644
PATTERN "*.strings"
)
+endif()
diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
index 25a79d145fb..74a838e2075 100644
--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
@@ -462,6 +462,7 @@ function(_add_target_variant_link_flags)
list(APPEND link_libraries "dl" "log")
# We need to add the math library, which is linked implicitly by libc++
list(APPEND result "-lm")
+ list(APPEND result "-fno-openmp-implicit-rpath")
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
list(APPEND result "-resource-dir=${RESOURCE_DIR}")
diff --git a/swift/stdlib/cmake/modules/SwiftSource.cmake b/swift/stdlib/cmake/modules/SwiftSource.cmake
index 4bc312f7f89..d71f6408d9f 100644
--- a/swift/stdlib/cmake/modules/SwiftSource.cmake
@ -236,6 +258,46 @@ index 11cda641cc2..bd2cb152725 100644
compiler
)
+endif()
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
@@ -1,28 +1,19 @@
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
- Sources/CSwiftPluginServer/PluginServer.cpp
- )
- target_link_libraries(_swiftCSwiftPluginServer PRIVATE
- swiftDemangling
+ add_swift_host_tool(swift-plugin-server SWIFT_COMPONENT compiler Sources/CSwiftPluginServer/PluginServer.cpp)
+ add_pure_swift_host_library(SwiftPluginServer STATIC
+ Sources/swift-plugin-server/swift-plugin-server.swift
)
- target_include_directories(_swiftCSwiftPluginServer PUBLIC
+ target_include_directories(SwiftPluginServer PUBLIC
Sources/CSwiftPluginServer/include
)
-
- add_pure_swift_host_tool(swift-plugin-server
- Sources/swift-plugin-server/swift-plugin-server.swift
- DEPENDENCIES
+ target_link_libraries(SwiftPluginServer PRIVATE SwiftCompilerPluginMessageHandling)
+ target_link_libraries(swift-plugin-server PRIVATE
swiftDemangling
- $<TARGET_OBJECTS:_swiftCSwiftPluginServer>
- SWIFT_COMPONENT
- compiler
- SWIFT_DEPENDENCIES
SwiftSyntaxMacros
SwiftSyntaxMacroExpansion
SwiftCompilerPluginMessageHandling
swiftLLVMJSON
+ SwiftPluginServer
)
target_include_directories(swift-plugin-server PRIVATE
Sources/CSwiftPluginServer/include
diff --git a/swift-corelibs-xctest/CMakeLists.txt b/swift-corelibs-xctest/CMakeLists.txt
index 531e7c0..589930f 100644
--- a/swift-corelibs-xctest/CMakeLists.txt
@ -248,11 +310,20 @@ index 531e7c0..589930f 100644
endif()
endif()
set_target_properties(XCTest PROPERTIES
@@ -69,7 +69,6 @@ set_target_properties(XCTest PROPERTIES
if(ENABLE_TESTING)
enable_testing()
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>:-wmo>)
endif()
+ 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()
- enable_language(C)
find_package(LLVM CONFIG)
if(LLVM_FOUND)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
if(LLVM_USE_LINKER)
target_link_options(${name} PRIVATE

View File

@ -0,0 +1,27 @@
commit 8e11ec10b769ee4de04159a05d5e701a712694cc
Date: Fri Nov 10 15:56:03 2023 +0530
Revert 'Add missing dependency (#1414)'
The llbuild executable is not a dependency of this library.
diff --git a/swift-driver/Package.swift b/swift-driver/Package.swift
index f09f530d..0e1c989c 100644
--- a/swift-driver/Package.swift
+++ b/swift-driver/Package.swift
@@ -145,7 +145,6 @@ if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
]
package.targets.first(where: { $0.name == "SwiftDriverExecution" })!.dependencies += [
.product(name: "llbuildSwift", package: "swift-llbuild"),
- .product(name: "llbuild", package: "swift-llbuild"),
]
} else {
// In Swift CI, use a local path to llbuild to interoperate with tools
@@ -155,7 +154,6 @@ if ProcessInfo.processInfo.environment["SWIFT_DRIVER_LLBUILD_FWK"] == nil {
]
package.targets.first(where: { $0.name == "SwiftDriverExecution" })!.dependencies += [
.product(name: "llbuildSwift", package: "llbuild"),
- .product(name: "llbuild", package: "llbuild"),
]
}
}

View File

@ -1,740 +0,0 @@
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,
SwiftInt 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, SwiftInt(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

File diff suppressed because it is too large Load Diff

View File

@ -26,6 +26,32 @@ index bd31bec..737c8c3 100755
# SwiftPM will otherwise try to compile against GNU strerror_r on
# Android and fail.
'-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt
index 93096ad07b9..27b7fe4b98d 100644
--- a/swift/CMakeLists.txt
+++ b/swift/CMakeLists.txt
@@ -1366,7 +1368,7 @@ if(SWIFT_INCLUDE_TOOLS)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}")
if(SWIFT_HOST_VARIANT_SDK MATCHES "LINUX|ANDROID|OPENBSD|FREEBSD")
- set(SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}")
+ set(SWIFT_HOST_LIBRARIES_RPATH "$ORIGIN;$ORIGIN/../..")
endif()
# Add unique ABI prefix to swift-syntax libraries so that compiler libraries (e.g. sourcekitdInProc)
# can be used from tools that has its own swift-syntax libraries as SwiftPM dependencies.
diff --git a/swift/cmake/modules/AddPureSwift.cmake b/swift/cmake/modules/AddPureSwift.cmake
index ee668f96903..61397d3910e 100644
--- a/swift/cmake/modules/AddPureSwift.cmake
+++ b/swift/cmake/modules/AddPureSwift.cmake
@@ -65,7 +71,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-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt b/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt
index b1c84350..35413f0b 100644
--- a/swift-corelibs-foundation/Sources/Tools/plutil/CMakeLists.txt

View File

@ -1,16 +0,0 @@
diff --git a/swift/stdlib/public/runtime/CrashHandlerLinux.cpp b/swift/stdlib/public/runtime/CrashHandlerLinux.cpp
index ff44dbe7541..2f386278975 100644
--- a/swift/stdlib/public/runtime/CrashHandlerLinux.cpp
+++ b/swift/stdlib/public/runtime/CrashHandlerLinux.cpp
@@ -243,7 +243,11 @@ handle_fatal_signal(int signum,
#elif defined(__arm64__) || defined(__aarch64__)
pc = (void *)(ctx->uc_mcontext.pc);
#elif defined(__arm__)
+#if defined(__ANDROID__)
+ pc = (void *)(ctx->uc_mcontext.arm_pc);
+#else
pc = (void *)(ctx->uc_mcontext.gprs[15]);
+#endif
#endif
_swift_displayCrashMessage(signum, pc);

View File

@ -1,498 +0,0 @@
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,12 +15,25 @@ 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}")
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
+if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
+ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
+endif()
+if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
+ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib/${SWIFT_HOST_LIBRARIES_SUBDIRECTORY}")
+endif()
+if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
+ 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

@ -1,164 +0,0 @@
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,13 @@ 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};>)
+ add_dependencies(${name} swift-stdlib-android-${SWIFT_HOST_VARIANT_ARCH})
+ 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
@@ -1,28 +1,19 @@
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
- Sources/CSwiftPluginServer/PluginServer.cpp
- )
- target_link_libraries(_swiftCSwiftPluginServer PRIVATE
- swiftDemangling
+ add_swift_host_tool(swift-plugin-server SWIFT_COMPONENT compiler Sources/CSwiftPluginServer/PluginServer.cpp)
+ add_pure_swift_host_library(SwiftPluginServer STATIC
+ Sources/swift-plugin-server/swift-plugin-server.swift
)
- target_include_directories(_swiftCSwiftPluginServer PUBLIC
+ target_include_directories(SwiftPluginServer PUBLIC
Sources/CSwiftPluginServer/include
)
-
- add_pure_swift_host_tool(swift-plugin-server
- Sources/swift-plugin-server/swift-plugin-server.swift
- DEPENDENCIES
+ target_link_libraries(SwiftPluginServer PRIVATE SwiftCompilerPluginMessageHandling)
+ target_link_libraries(swift-plugin-server PRIVATE
swiftDemangling
- $<TARGET_OBJECTS:_swiftCSwiftPluginServer>
- SWIFT_COMPONENT
- compiler
- 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

@ -1,32 +0,0 @@
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

@ -0,0 +1,105 @@
From 19546b1f4439659fe256fa62c74ecbfc3fb527ee
Date: Wed, 3 Jan 2024 22:32:35 +0530
Subject: [PATCH] Android: add better nullability checks for nullability
annotations added in NDK 26 (#444)
Also fix one test.
diff --git a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
index b33b1c61..1d260331 100644
--- a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift
@@ -491,8 +491,7 @@ private struct LocalFileSystem: FileSystem {
func readFileContents(_ path: AbsolutePath) throws -> ByteString {
// Open the file.
- let fp = fopen(path.pathString, "rb")
- if fp == nil {
+ guard let fp = fopen(path.pathString, "rb") else {
throw FileSystemError(errno: errno, path)
}
defer { fclose(fp) }
@@ -521,8 +520,7 @@ private struct LocalFileSystem: FileSystem {
func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws {
// Open the file.
- let fp = fopen(path.pathString, "wb")
- if fp == nil {
+ guard let fp = fopen(path.pathString, "wb") else {
throw FileSystemError(errno: errno, path)
}
defer { fclose(fp) }
diff --git a/swift-tools-support-core/Sources/TSCBasic/Process.swift b/swift-tools-support-core/Sources/TSCBasic/Process.swift
index 6c8aa117..89d3a5be 100644
--- a/swift-tools-support-core/Sources/TSCBasic/Process.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/Process.swift
@@ -144,6 +144,9 @@ public final class Process {
/// The current OS does not support the workingDirectory API.
case workingDirectoryNotSupported
+
+ /// The stdin could not be opened.
+ case stdinUnavailable
}
public enum OutputRedirection {
@@ -677,7 +680,10 @@ public final class Process {
var stdinPipe: [Int32] = [-1, -1]
try open(pipe: &stdinPipe)
- let stdinStream = try LocalFileOutputByteStream(filePointer: fdopen(stdinPipe[1], "wb"), closeOnDeinit: true)
+ guard let fp = fdopen(stdinPipe[1], "wb") else {
+ throw Process.Error.stdinUnavailable
+ }
+ let stdinStream = try LocalFileOutputByteStream(filePointer: fp, closeOnDeinit: true)
// Dupe the read portion of the remote to 0.
posix_spawn_file_actions_adddup2(&fileActions, stdinPipe[0], 0)
@@ -1258,6 +1264,8 @@ extension Process.Error: CustomStringConvertible {
return "could not find executable for '\(program)'"
case .workingDirectoryNotSupported:
return "workingDirectory is not supported in this platform"
+ case .stdinUnavailable:
+ return "could not open stdin on this platform"
}
}
}
diff --git a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
index aee907e3..5b6e4c2c 100644
--- a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
+++ b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift
@@ -790,7 +790,7 @@ public final class LocalFileOutputByteStream: FileOutputByteStream {
override final func writeImpl(_ bytes: ArraySlice<UInt8>) {
bytes.withUnsafeBytes { bytesPtr in
while true {
- let n = fwrite(bytesPtr.baseAddress, 1, bytesPtr.count, filePointer)
+ let n = fwrite(bytesPtr.baseAddress!, 1, bytesPtr.count, filePointer)
if n < 0 {
if errno == EINTR { continue }
errorDetected(code: errno)
diff --git a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
index 59610b61..2797c719 100644
--- a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
+++ b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift
@@ -24,7 +24,7 @@ public final class PseudoTerminal {
if openpty(&primary, &secondary, nil, nil, nil) != 0 {
return nil
}
- guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w"), closeOnDeinit: false) else {
+ guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w")!, closeOnDeinit: false) else {
return nil
}
self.outStream = outStream
diff --git a/swift-tools-support-core/Tests/TSCBasicTests/PathShimTests.swift b/swift-tools-support-core/Tests/TSCBasicTests/PathShimTests.swift
index 1af04a37..76fd6324 100644
--- a/swift-tools-support-core/Tests/TSCBasicTests/PathShimTests.swift
+++ b/swift-tools-support-core/Tests/TSCBasicTests/PathShimTests.swift
@@ -39,7 +39,7 @@ class WalkTests : XCTestCase {
var expected: [AbsolutePath] = [
"\(root)/usr",
"\(root)/bin",
- "\(root)/xbin"
+ "\(root)/etc"
]
#else
let root = ""

View File

@ -10,11 +10,13 @@ index b1d060328bc..218c9215260 100755
if [[ ! "${SKIP_BUILD_ANDROID}" ]] ||
[[ $(is_cross_tools_host ${host}) && "${host}" == "android-"* ]]; then
cmake_options=(
@@ -1733,6 +1734,7 @@
@@ -1733,7 +1734,9 @@
-DSWIFT_ANDROID_NDK_PATH:STRING="${ANDROID_NDK}"
-DSWIFT_ANDROID_DEPLOY_DEVICE_PATH:STRING="${ANDROID_DEPLOY_DEVICE_PATH}"
-DSWIFT_SDK_ANDROID_ARCHITECTURES:STRING="${ANDROID_ARCH}"
+ -DBRIDGING_MODE:STRING="PURE"
)
+ cross_c_flags="--target=$CCTERMUX_HOST_PLATFORM"
+ cross_c_flags="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM"
fi
if [[ ! "${SKIP_BUILD_WASM}" ]]; then
@ -54,9 +56,9 @@ index b1d060328bc..218c9215260 100755
-DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O2 -DNDEBUG"
-DCMAKE_BUILD_TYPE:STRING="${SWIFT_BUILD_TYPE}"
@@ -1878,6 +1891,7 @@
-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_STDLIB_OVERRIDABLE_RETAIN_RELEASE:BOOL=$(true_false "${SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE}")
+ -DSWIFT_CLANG_RESOURCE_DIR_SYMLINK_INSTALL_TARGET:STRING="../clang/${TERMUX_CLANG_VERSION}"
"${swift_cmake_options[@]}"
)
@ -70,7 +72,17 @@ index b1d060328bc..218c9215260 100755
)
fi
@@ -2199,6 +2201,9 @@ for host in "${ALL_HOSTS[@]}"; do
@@ -2388,7 +2404,8 @@
-DENABLE_TESTING=YES
)
if [[ $(is_cross_tools_host ${host}) ]] ; then
- cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")
+ cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}"
+ -DCMAKE_C_FLAGS="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM $CPPFLAGS")
fi
;;
esac
@@ -2537,6 +2554,9 @@
# https://cmake.org/cmake/help/latest/command/find_package.html
cmake_options+=(
-DCMAKE_FIND_ROOT_PATH:PATH="${CROSS_COMPILE_DEPS_PATH}"
@ -80,7 +92,7 @@ index b1d060328bc..218c9215260 100755
)
fi
if [[ "${host}" == "android-"* ]]; then
@@ -2239,6 +2243,11 @@ for host in "${ALL_HOSTS[@]}"; do
@@ -2583,6 +2603,11 @@
)
if [[ $(is_cross_tools_host ${host}) ]] ; then
cmake_options+=("${SWIFT_TARGET_CMAKE_OPTIONS[@]}")

View File

@ -1,278 +0,0 @@
commit 78b88bb6bc428f651ae615a944d985858e0a60f0
Date: Mon Sep 25 02:19:40 2023 +0530
Add an rpath flag to disable the default of looking in the local directory for shared libraries
This is useful when deploying build products, as most executables are not installed
in the same directory as libraries and system libraries do not need it for
system paths. Use the new flag when installing SwiftPM itself and the {Manifest,Plugin}API
libraries on ELF platforms.
diff --git a/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift b/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
index 7aed35e48..5fdb9b4e5 100644
--- a/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
+++ b/swiftpm/Sources/Build/BuildDescription/ProductBuildDescription.swift
@@ -257,12 +257,14 @@ public final class ProductBuildDescription: SPMBuildCore.ProductBuildDescription
}
// Set rpath such that dynamic libraries are looked up
- // adjacent to the product.
- if self.buildParameters.triple.isLinux() {
- args += ["-Xlinker", "-rpath=$ORIGIN"]
- } else if self.buildParameters.triple.isDarwin() {
- let rpath = self.product.type == .test ? "@loader_path/../../../" : "@loader_path"
- args += ["-Xlinker", "-rpath", "-Xlinker", rpath]
+ // adjacent to the product, unless overridden.
+ if !self.buildParameters.shouldDisableLocalRpath {
+ if self.buildParameters.triple.isLinux() {
+ args += ["-Xlinker", "-rpath=$ORIGIN"]
+ } else if self.buildParameters.triple.isDarwin() {
+ let rpath = self.product.type == .test ? "@loader_path/../../../" : "@loader_path"
+ args += ["-Xlinker", "-rpath", "-Xlinker", rpath]
+ }
}
args += ["@\(self.linkFileListPath.pathString)"]
diff --git a/swiftpm/Sources/CoreCommands/Options.swift b/swiftpm/Sources/CoreCommands/Options.swift
index d09b28d6a..739db470e 100644
--- a/swiftpm/Sources/CoreCommands/Options.swift
+++ b/swiftpm/Sources/CoreCommands/Options.swift
@@ -524,6 +524,10 @@ public struct LinkerOptions: ParsableArguments {
/// If should link the Swift stdlib statically.
@Flag(name: .customLong("static-swift-stdlib"), inversion: .prefixedNo, help: "Link Swift stdlib statically")
public var shouldLinkStaticSwiftStdlib: Bool = false
+
+ /// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
+ @Flag(name: .customLong("disable-local-rpath"), help: "Disable adding $ORIGIN/@loader_path to the rpath by default")
+ public var shouldDisableLocalRpath: Bool = false
}
// MARK: - Extensions
diff --git a/swiftpm/Sources/CoreCommands/SwiftTool.swift b/swiftpm/Sources/CoreCommands/SwiftTool.swift
index 72e8be958..b99b80770 100644
--- a/swiftpm/Sources/CoreCommands/SwiftTool.swift
+++ b/swiftpm/Sources/CoreCommands/SwiftTool.swift
@@ -683,6 +683,7 @@ public final class SwiftTool {
architectures: options.build.architectures,
workers: options.build.jobs ?? UInt32(ProcessInfo.processInfo.activeProcessorCount),
shouldLinkStaticSwiftStdlib: options.linker.shouldLinkStaticSwiftStdlib,
+ shouldDisableLocalRpath: options.linker.shouldDisableLocalRpath,
canRenameEntrypointFunctionName: driverSupport.checkSupportedFrontendFlags(
flags: ["entry-point-function-name"],
toolchain: toolchain,
diff --git a/swiftpm/Sources/SPMBuildCore/BuildParameters.swift b/swiftpm/Sources/SPMBuildCore/BuildParameters.swift
index 57825c6e4..bbb3c2cc3 100644
--- a/swiftpm/Sources/SPMBuildCore/BuildParameters.swift
+++ b/swiftpm/Sources/SPMBuildCore/BuildParameters.swift
@@ -190,6 +190,9 @@ public struct BuildParameters: Encodable {
/// If should link the Swift stdlib statically.
public var shouldLinkStaticSwiftStdlib: Bool
+ /// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
+ public var shouldDisableLocalRpath: Bool
+
/// Which compiler sanitizers should be enabled
public var sanitizers: EnabledSanitizers
@@ -362,6 +365,7 @@ public struct BuildParameters: Encodable {
architectures: [String]? = nil,
workers: UInt32 = UInt32(ProcessInfo.processInfo.activeProcessorCount),
shouldLinkStaticSwiftStdlib: Bool = false,
+ shouldDisableLocalRpath: Bool = false,
shouldEnableManifestCaching: Bool = false,
canRenameEntrypointFunctionName: Bool = false,
shouldCreateDylibForDynamicProducts: Bool = true,
@@ -424,6 +428,7 @@ public struct BuildParameters: Encodable {
self.architectures = architectures
self.workers = workers
self.shouldLinkStaticSwiftStdlib = shouldLinkStaticSwiftStdlib
+ self.shouldDisableLocalRpath = shouldDisableLocalRpath
self.shouldEnableManifestCaching = shouldEnableManifestCaching
self.shouldCreateDylibForDynamicProducts = shouldCreateDylibForDynamicProducts
self.canRenameEntrypointFunctionName = canRenameEntrypointFunctionName
@@ -487,6 +492,7 @@ public struct BuildParameters: Encodable {
architectures: nil,
workers: self.workers,
shouldLinkStaticSwiftStdlib: self.shouldLinkStaticSwiftStdlib,
+ shouldDisableLocalRpath: self.shouldDisableLocalRpath,
shouldEnableManifestCaching: self.shouldEnableManifestCaching,
canRenameEntrypointFunctionName: self.canRenameEntrypointFunctionName,
shouldCreateDylibForDynamicProducts: self.shouldCreateDylibForDynamicProducts,
diff --git a/swiftpm/Sources/swift-bootstrap/main.swift b/swiftpm/Sources/swift-bootstrap/main.swift
index 9f45edf51..5c80a5249 100644
--- a/swiftpm/Sources/swift-bootstrap/main.swift
+++ b/swiftpm/Sources/swift-bootstrap/main.swift
@@ -118,6 +118,10 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
@Flag()
public var useIntegratedSwiftDriver: Bool = false
+ /// Disables adding $ORIGIN/@loader_path to the rpath, useful when deploying
+ @Flag(name: .customLong("disable-local-rpath"), help: "Disable adding $ORIGIN/@loader_path to the rpath by default")
+ public var shouldDisableLocalRpath: Bool = false
+
private var buildSystem: BuildSystemProvider.Kind {
#if os(macOS)
// Force the Xcode build system if we want to build more than one arch.
@@ -188,7 +192,8 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
architectures: self.architectures,
buildFlags: self.buildFlags,
manifestBuildFlags: self.manifestFlags,
- useIntegratedSwiftDriver: self.useIntegratedSwiftDriver
+ useIntegratedSwiftDriver: self.useIntegratedSwiftDriver,
+ shouldDisableLocalRpath: self.shouldDisableLocalRpath
)
} catch _ as Diagnostics {
throw ExitCode.failure
@@ -232,7 +237,8 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
architectures: [String],
buildFlags: BuildFlags,
manifestBuildFlags: [String],
- useIntegratedSwiftDriver: Bool
+ useIntegratedSwiftDriver: Bool,
+ shouldDisableLocalRpath: Bool
) throws {
let buildSystem = try createBuildSystem(
packagePath: packagePath,
@@ -244,6 +250,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
buildFlags: buildFlags,
manifestBuildFlags: manifestBuildFlags,
useIntegratedSwiftDriver: useIntegratedSwiftDriver,
+ shouldDisableLocalRpath: shouldDisableLocalRpath,
logLevel: logLevel
)
try buildSystem.build(subset: .allExcludingTests)
@@ -259,6 +266,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
buildFlags: BuildFlags,
manifestBuildFlags: [String],
useIntegratedSwiftDriver: Bool,
+ shouldDisableLocalRpath: Bool,
logLevel: Basics.Diagnostic.Severity
) throws -> BuildSystem {
@@ -277,6 +285,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
destinationTriple: self.destinationToolchain.triple,
flags: buildFlags,
architectures: architectures,
+ shouldDisableLocalRpath: shouldDisableLocalRpath,
useIntegratedSwiftDriver: useIntegratedSwiftDriver,
isXcodeBuildSystemEnabled: buildSystem == .xcode,
verboseOutput: logLevel <= .info
diff --git a/swiftpm/Tests/BuildTests/BuildPlanTests.swift b/swiftpm/Tests/BuildTests/BuildPlanTests.swift
index 768952986..c847afd52 100644
--- a/swiftpm/Tests/BuildTests/BuildPlanTests.swift
+++ b/swiftpm/Tests/BuildTests/BuildPlanTests.swift
@@ -5021,4 +5021,80 @@ final class BuildPlanTests: XCTestCase {
XCTAssertMatch(try result.buildProduct(for: "exe").linkArguments(), ["-sanitize=\(expectedName)"])
}
+
+ func testBasicSwiftPackageWithoutLocalRpath() throws {
+ let fs = InMemoryFileSystem(emptyFiles:
+ "/Pkg/Sources/exe/main.swift",
+ "/Pkg/Sources/lib/lib.swift"
+ )
+
+ let observability = ObservabilitySystem.makeForTesting()
+ let graph = try loadPackageGraph(
+ fileSystem: fs,
+ manifests: [
+ Manifest.createRootManifest(
+ displayName: "Pkg",
+ path: "/Pkg",
+ targets: [
+ TargetDescription(name: "exe", dependencies: ["lib"]),
+ TargetDescription(name: "lib", dependencies: []),
+ ]),
+ ],
+ observabilityScope: observability.topScope
+ )
+ XCTAssertNoDiagnostics(observability.diagnostics)
+
+ let result = try BuildPlanResult(plan: BuildPlan(
+ buildParameters: mockBuildParameters(shouldDisableLocalRpath: true),
+ graph: graph,
+ fileSystem: fs,
+ observabilityScope: observability.topScope
+ ))
+
+ result.checkProductsCount(1)
+ result.checkTargetsCount(2)
+
+ let buildPath = result.plan.buildParameters.dataPath.appending(components: "debug")
+
+ #if os(macOS)
+ let linkArguments = [
+ result.plan.buildParameters.toolchain.swiftCompilerPath.pathString,
+ "-L", buildPath.pathString,
+ "-o", buildPath.appending(components: "exe").pathString,
+ "-module-name", "exe",
+ "-emit-executable",
+ "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
+ "-Xlinker", "-rpath", "-Xlinker", "/fake/path/lib/swift-5.5/macosx",
+ "-target", defaultTargetTriple,
+ "-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "exe.build", "exe.swiftmodule").pathString,
+ "-Xlinker", "-add_ast_path", "-Xlinker", buildPath.appending(components: "lib.swiftmodule").pathString,
+ "-g",
+ ]
+ #elseif os(Windows)
+ let linkArguments = [
+ result.plan.buildParameters.toolchain.swiftCompilerPath.pathString,
+ "-L", buildPath.pathString,
+ "-o", buildPath.appending(components: "exe.exe").pathString,
+ "-module-name", "exe",
+ "-emit-executable",
+ "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
+ "-target", defaultTargetTriple,
+ "-g", "-use-ld=lld", "-Xlinker", "-debug:dwarf",
+ ]
+ #else
+ let linkArguments = [
+ result.plan.buildParameters.toolchain.swiftCompilerPath.pathString,
+ "-L", buildPath.pathString,
+ "-o", buildPath.appending(components: "exe").pathString,
+ "-module-name", "exe",
+ "-emit-executable",
+ "@\(buildPath.appending(components: "exe.product", "Objects.LinkFileList"))",
+ "-target", defaultTargetTriple,
+ "-g"
+ ]
+ #endif
+
+ XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), linkArguments)
+ XCTAssertNoDiagnostics(observability.diagnostics)
+ }
}
diff --git a/swiftpm/Tests/BuildTests/MockBuildTestHelper.swift b/swiftpm/Tests/BuildTests/MockBuildTestHelper.swift
index 243f68a58..b4dd25595 100644
--- a/swiftpm/Tests/BuildTests/MockBuildTestHelper.swift
+++ b/swiftpm/Tests/BuildTests/MockBuildTestHelper.swift
@@ -71,6 +71,7 @@ func mockBuildParameters(
toolchain: PackageModel.Toolchain = MockToolchain(),
flags: PackageModel.BuildFlags = PackageModel.BuildFlags(),
shouldLinkStaticSwiftStdlib: Bool = false,
+ shouldDisableLocalRpath: Bool = false,
canRenameEntrypointFunctionName: Bool = false,
destinationTriple: Basics.Triple = hostTriple,
indexStoreMode: BuildParameters.IndexStoreMode = .off,
@@ -88,6 +89,7 @@ func mockBuildParameters(
pkgConfigDirectories: [],
workers: 3,
shouldLinkStaticSwiftStdlib: shouldLinkStaticSwiftStdlib,
+ shouldDisableLocalRpath: shouldDisableLocalRpath,
canRenameEntrypointFunctionName: canRenameEntrypointFunctionName,
indexStoreMode: indexStoreMode,
useExplicitModuleBuild: useExplicitModuleBuild,
diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap
index 33aacd0b7..5d8ab14b8 100755
--- a/swiftpm/Utilities/bootstrap
+++ b/swiftpm/Utilities/bootstrap
@@ -769,6 +769,9 @@ def get_swiftpm_flags(args):
"--configuration", "release",
])
+ if os.environ.get('ANDROID_DATA') and not '-macosx' in args.build_target and args.command == 'install':
+ build_flags.append("--disable-local-rpath")
+
if args.verbose:
build_flags.append("--verbose")

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 \
6407e39eed7eaefcf7837d192d71765fb0f7cf8bf282c35b021171e8b15617c1
ded6983736ab5e15862e5a924ebd5c4f9459802317eff719936442c832698d06
(cd $TERMUX_PKG_TMPDIR ; tar xf $SWIFT_TAR ; mv $SWIFT_BIN $SWIFT_FOLDER; rm $SWIFT_TAR)
fi