diff --git a/packages/libdispatch/build.sh b/packages/libdispatch/build.sh index 5f47e23c423130b..8b8dc7696b20aa2 100644 --- a/packages/libdispatch/build.sh +++ b/packages/libdispatch/build.sh @@ -2,8 +2,8 @@ TERMUX_PKG_HOMEPAGE=https://github.com/swiftlang/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:6.0.2" -TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift-corelibs-libdispatch/archive/swift-RELEASE.tar.gz -TERMUX_PKG_SHA256=3df429b22d9294c0ca5291c86e83a35f6326600a1c271933107bba199b919008 +TERMUX_PKG_VERSION="1:6.2" +TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift-corelibs-libdispatch/archive/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.tar.gz +TERMUX_PKG_SHA256=0257e985723e17bf7cb943ae963a0e8bc6d15ab4929b84672131806582be6535 TERMUX_PKG_AUTO_UPDATE=false TERMUX_PKG_DEPENDS="libc++, libblocksruntime" diff --git a/packages/llbuild/build.sh b/packages/llbuild/build.sh index 788da1e16737511..7bfdfb43c1479b4 100644 --- a/packages/llbuild/build.sh +++ b/packages/llbuild/build.sh @@ -2,8 +2,8 @@ TERMUX_PKG_HOMEPAGE=https://github.com/swiftlang/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=6.0.2 -TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift-llbuild/archive/swift-RELEASE.tar.gz -TERMUX_PKG_SHA256=40ada0511f0218fb3ca0478c8fff1b4d0958478056a0cc5408677753e8c8f7a7 +TERMUX_PKG_VERSION=6.2 +TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift-llbuild/archive/swift-DEVELOPMENT-SNAPSHOT-2025-01-10-a.tar.gz +TERMUX_PKG_SHA256=59b01224fad52a4f32dd181b0a8b990ddce96ca8c5cc14d63d70db4e78ae1ed9 TERMUX_PKG_DEPENDS="libc++, libandroid-spawn, libsqlite" TERMUX_PKG_NO_STATICSPLIT=true diff --git a/packages/swift/build.sh b/packages/swift/build.sh index 8fa55967fd1cdf6..d9fcec002acd42c 100644 --- a/packages/swift/build.sh +++ b/packages/swift/build.sh @@ -2,17 +2,17 @@ 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=6.0.3 -SWIFT_RELEASE="RELEASE" +TERMUX_PKG_VERSION=6.2 +SWIFT_RELEASE="DEVELOPMENT-SNAPSHOT-2025-01-10-a" TERMUX_PKG_SRCURL=https://github.com/swiftlang/swift/archive/swift-$SWIFT_RELEASE.tar.gz -TERMUX_PKG_SHA256=1489681860e92cee5ddd869a06531d7a1746b2f4ea105a2ff3b631ebcbcffd34 +TERMUX_PKG_SHA256=1219fd794176f3e9d60c2d9beb31f58509cf378d1b9f1f2481a2edf1226a0a1f TERMUX_PKG_AUTO_UPDATE=false TERMUX_PKG_HOSTBUILD=true -TERMUX_PKG_DEPENDS="clang, libandroid-execinfo, libandroid-glob, libandroid-posix-semaphore, libandroid-shmem, libandroid-spawn, libandroid-spawn-static, libandroid-sysv-semaphore, libcurl, libsqlite, libuuid, libxml2, libdispatch, llbuild, pkg-config, swift-sdk-${TERMUX_ARCH/_/-}" +TERMUX_PKG_DEPENDS="clang, libandroid-execinfo, libandroid-glob, libandroid-posix-semaphore, libandroid-shmem, libandroid-spawn, libandroid-spawn-static, libandroid-sysv-semaphore, libcurl, libuuid, libxml2, libdispatch, llbuild, pkg-config, swift-sdk-${TERMUX_ARCH/_/-}" TERMUX_PKG_BUILD_DEPENDS="rsync" TERMUX_PKG_BLACKLISTED_ARCHES="i686" TERMUX_PKG_NO_STATICSPLIT=true -# Temporary hack only needed for x86_64 +# Temporary hack only needed for arm and x86_64 TERMUX_PKG_UNDEF_SYMBOLS_FILES=" ./opt/ndk-multilib/arm-linux-androideabi/lib/libFoundation.so ./opt/ndk-multilib/arm-linux-androideabi/lib/libFoundationNetworking.so @@ -42,33 +42,35 @@ termux_step_post_get_source() { mv .temp swift declare -A library_checksums - library_checksums[swift-cmark]=ab1064350ecedd5b3c0f2a6fbe3acefbc45d7accf1e4ca1591ce04d0c6787e40 - library_checksums[llvm-project]=d93ca164615938e5026a2d1af76b2ef7514eae98b38a716f3278bc1a6dfc8f92 - library_checksums[swift-experimental-string-processing]=6c34cfdf934eb781169866a66505e11541861ba638b05fd4ed87f8c34a6fa55e - library_checksums[swift-syntax]=30788e115f37b7d3f8fc1f5d436b80996f4945fc13287ed7e4391b358479fafd - library_checksums[swift-corelibs-libdispatch]=444c0de5fe18e148548a3f3b60b3bac3d4d586285c21064346c7ca17ed1d4fac - library_checksums[swift-corelibs-foundation]=62c276a18fa3b3b92e95f5349dc125d03f09cea3c477b3af1428ccdbab29e139 - library_checksums[swift-foundation]=31ee3ea95a015049d3f6a5cfe8bd3a460071fa0086c1d112efaf0580611d162c - library_checksums[swift-foundation-icu]=c4332b4e6cc008a5a7045ad7f368df7deb518f286ecd5a78839066dcc07a853a - library_checksums[swift-corelibs-xctest]=eb131d1cfde18548c5fc782ba56bc871b13057b5e7b6992ddae4d4349360571d - library_checksums[swift-llbuild]=68d71bf7e0882153c6ad91fbe0626ab761d8bc46d2d93ce32cbfa392d256a30e - library_checksums[swift-argument-parser]=4a10bbef290a2167c5cc340b39f1f7ff6a8cf4e1b5433b68548bf5f1e542e908 - library_checksums[Yams]=a81c6b93f5d26bae1b619b7f8babbfe7c8abacf95b85916961d488888df886fb - library_checksums[swift-collections]=cd30d2f93c72424df48d182006417abdeebe74d250cb99d1cda78daf40aca569 - library_checksums[swift-crypto]=5c860c0306d0393ff06268f361aaf958656e1288353a0e23c3ad20de04319154 + library_checksums[sourcekit-lsp]=3065554af62dbf2d1a62f82d076998372f5f43becd3f2d9795e8320f4cede0d2 + library_checksums[swift-corelibs-xctest]=8f45a09fb518589d826aacca16c588468a717469bcd7e3169d2239839b2d3ac2 + library_checksums[swift-corelibs-foundation]=a915255aba662363d82491db76df0d1a9e32ebdbd98d2d8ed7efdda8770a5109 + library_checksums[swift-lmdb]=fdd7d49ef815a4bb6193a9910108c7692b712db9e9341433b061f09c454565c7 + library_checksums[swift-collections]=7e5e48d0dc2350bed5919be5cf60c485e72a30bd1f2baf718a619317677b91db + library_checksums[swift-driver]=4ae3db8fee22a2bbfa9441f7ec063b293567c0a7d89eb2bf1261f6b4b8ae18bd + library_checksums[swift-foundation]=981752216eff72c162399078155617ac538e53adda954422f6f89ca7979ebb1e + library_checksums[swift-toolchain-sqlite]=c8704e70c4847a8dbd47aafb25d293fbe1e1bafade16cfa64e04f751e33db0ca + library_checksums[swift-argument-parser]=d5bad3a1da66d9f4ceb0a347a197b8fdd243a91ff6b2d72b78efb052b9d6dd33 + library_checksums[swift-syntax]=8b963b26fc51878be95cad8fa668cd57859867ab3048778175f7c15d0e3cd114 + library_checksums[swift-llbuild]=59b01224fad52a4f32dd181b0a8b990ddce96ca8c5cc14d63d70db4e78ae1ed9 + library_checksums[swift-corelibs-libdispatch]=0257e985723e17bf7cb943ae963a0e8bc6d15ab4929b84672131806582be6535 + library_checksums[swift-foundation-icu]=f0b4ec3c9014307700633cf955d4721cd1aec7a0a9db4550dfc8197c0bdd0796 library_checksums[swift-system]=02e13a7f77887c387f5aa1de05f4d4b8b158c35145450e1d9557d6c42b06cd1f library_checksums[swift-asn1]=e0da995ae53e6fcf8251887f44d4030f6600e2f8f8451d9c92fcaf52b41b6c35 + library_checksums[swift-tools-support-core]=bf18632a5323458264eaf0317e4c27c07c2b71d87a924a68235be2c4772d36e1 + library_checksums[swift-package-manager]=8e0413d78c548462545d60dda419f5c49f582c142f8b3d4fb1f3b50b5fdda5b3 + library_checksums[swift-cmark]=fc34d3fba1a9e3ef0a930661c09ee91c56440b6320769b0ef22969a7feb4c304 + library_checksums[indexstore-db]=e8c90819f528e533eaeb2eac893631f461f940d2b705eded45d78a51c87b7bc2 library_checksums[swift-certificates]=fcaca458aab45ee69b0f678b72c2194b15664cc5f6f5e48d0e3f62bc5d1202ca - library_checksums[swift-driver]=9ee38eda1a0adc24dd995b345dff4a5a25d42ae8d063fcc04b170469f2f53d43 - library_checksums[swift-tools-support-core]=fc83e9922d4c7df0f0d94b8840f292989eb148d5e451b182a9e390a9ea4dd94e - library_checksums[swift-package-manager]=03c5b8dfd8628de42ca1c171faeeddea977ecdad8675d3826a2c165ad8f972ba - library_checksums[indexstore-db]=fdaceb80a819e5b86d1599e7357c79e518a3ff0bb96dcd82245fc50e3d6bbc0d - library_checksums[sourcekit-lsp]=928db64bc179a250afd305b5729217180e2de1cdcd3d353d0fa20b38c5def8ec + library_checksums[swift-crypto]=5c860c0306d0393ff06268f361aaf958656e1288353a0e23c3ad20de04319154 + library_checksums[llvm-project]=0afd7cf017633fbce49f96a61e6ae10fdcd29acf7dc35b0f2df80c21ec119fad + library_checksums[swift-experimental-string-processing]=e3d875438b1457acacd29f0679e44bb1d3bfa2188c1c2fc5798ba6d2278785d3 + library_checksums[Yams]=d0f8eced7ef3462945bde1fe0e37288b7df6a50ca854df53b3aff43ce4d38e39 for library in "${!library_checksums[@]}"; do \ GH_ORG="apple" if [ "$library" = "swift-argument-parser" ]; then - SRC_VERSION="1.2.3" + SRC_VERSION="1.4.0" TAR_NAME=$SRC_VERSION elif [ "$library" = "swift-asn1" ]; then SRC_VERSION="1.0.0" @@ -77,7 +79,7 @@ termux_step_post_get_source() { SRC_VERSION="1.0.1" TAR_NAME=$SRC_VERSION elif [ "$library" = "swift-collections" ]; then - SRC_VERSION="1.1.2" + SRC_VERSION="1.1.3" TAR_NAME=$SRC_VERSION elif [ "$library" = "swift-crypto" ]; then SRC_VERSION="3.0.0" @@ -85,9 +87,13 @@ termux_step_post_get_source() { elif [ "$library" = "swift-system" ]; then SRC_VERSION="1.3.0" TAR_NAME=$SRC_VERSION + elif [ "$library" = "swift-toolchain-sqlite" ]; then + GH_ORG="swiftlang" + SRC_VERSION="1.0.1" + TAR_NAME=$SRC_VERSION elif [ "$library" = "Yams" ]; then GH_ORG="jpsim" - SRC_VERSION="5.0.6" + SRC_VERSION="5.1.3" TAR_NAME=$SRC_VERSION else GH_ORG="swiftlang" @@ -136,9 +142,11 @@ termux_step_make() { if [ "$TERMUX_ON_DEVICE_BUILD" = "false" ]; then termux_setup_swift ln -sf $TERMUX_PKG_HOSTBUILD_DIR/llvm-linux-x86_64 $TERMUX_PKG_BUILDDIR/llvm-linux-x86_64 + ln -sf $NDK/source.properties $TERMUX_STANDALONE_TOOLCHAIN for header in execinfo.h glob.h iconv.h spawn.h sys/sem.h sys/shm.h; do ln -sf $TERMUX_PREFIX/include/$header $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include/$header done + unset ANDROID_NDK_ROOT SWIFT_BUILD_FLAGS="$SWIFT_BUILD_FLAGS --android --android-ndk $TERMUX_STANDALONE_TOOLCHAIN --android-arch $SWIFT_ARCH @@ -158,6 +166,7 @@ termux_step_make() { --install-xctest --install-llbuild --install-swiftpm --install-swift-driver --install-sourcekit-lsp rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/include/{execinfo.h,glob.h,iconv.h,spawn.h,sys/sem.h,sys/shm.h} + rm $TERMUX_STANDALONE_TOOLCHAIN/sysroot/usr/lib/swift } termux_step_make_install() { diff --git a/packages/swift/swift-arm-casts.patch b/packages/swift/swift-arm-casts.patch index d4b21fec01c7473..749d9cede991c0c 100644 --- a/packages/swift/swift-arm-casts.patch +++ b/packages/swift/swift-arm-casts.patch @@ -11,16 +11,3 @@ index 0255b38af1b..3949e62e750 100644 } static bool classof(const DeclAttribute *DA) { -diff --git a/swift/lib/ExternalGenericMetadataBuilder/ExternalGenericMetadataBuilder.cpp b/swift/lib/ExternalGenericMetadataBuilder/ExternalGenericMetadataBuilder.cpp -index 7617abe7ee7..a0016e575c7 100644 ---- a/swift/lib/ExternalGenericMetadataBuilder/ExternalGenericMetadataBuilder.cpp -+++ b/swift/lib/ExternalGenericMetadataBuilder/ExternalGenericMetadataBuilder.cpp -@@ -1488,7 +1488,7 @@ template - llvm::Error ExternalGenericMetadataBuilderContext::addImageInMemory( - const void *start, uint64_t length, const std::string &path) { - LOG(LogLevel::Info, "Adding %s in memory", path.c_str()); -- llvm::StringRef stringRef{reinterpret_cast(start), length}; -+ llvm::StringRef stringRef{reinterpret_cast(start), static_cast(length)}; - llvm::MemoryBufferRef bufferRef{stringRef, {}}; - auto binary = llvm::object::createBinary(bufferRef); - if (!binary) diff --git a/packages/swift/swift-arm.patch b/packages/swift/swift-arm.patch deleted file mode 100644 index 2824510464cb48c..000000000000000 --- a/packages/swift/swift-arm.patch +++ /dev/null @@ -1,746 +0,0 @@ -From 7afa419dd47cc537c02b788dd3e0428749d38cd0 -From: Erik Eckstein -Date: Thu, 21 Mar 2024 15:19:33 +0100 -Subject: SIL: improve inline bitfields in SILNode, SILBasicBlock - and Operand - -* Let the customBits and lastInitializedBitfieldID share a single uint64_t. This increases the number of available bits in SILNode and Operand from 8 to 20. Also, it simplifies the Operand class because no PointerIntPairs are used anymore to store the operand pointer fields. -* Instead make the "deleted" flag a separate bool field in SILNode (instead of encoding it with the sign of lastInitializedBitfieldID). Another simplification -* Enable important invariant checks also in release builds by using `require` instead of `assert`. Not catching such errors in release builds would be a disaster. -* Let the Swift optimization passes use all the available bits and not only a fixed amount of 8 (SILNode) and 16 (SILBasicBlock). - -diff --git a/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift b/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift -index 4cb20cbe2cc76..d2ab37357656e 100644 ---- a/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift -+++ b/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Set.swift -@@ -176,3 +176,55 @@ struct InstructionSet : IntrusiveSet { - context.freeNodeSet(bridged) - } - } -+ -+/// A set of operands. -+/// -+/// This is an extremely efficient implementation which does not need memory -+/// allocations or hash lookups. -+/// -+/// This type should be a move-only type, but unfortunately we don't have move-only -+/// types yet. Therefore it's needed to call `deinitialize()` explicitly to -+/// destruct this data structure, e.g. in a `defer {}` block. -+struct OperandSet : IntrusiveSet { -+ -+ private let context: BridgedPassContext -+ private let bridged: BridgedOperandSet -+ -+ init(_ context: some Context) { -+ self.context = context._bridged -+ self.bridged = self.context.allocOperandSet() -+ } -+ -+ func contains(_ operand: Operand) -> Bool { -+ bridged.contains(operand.bridged) -+ } -+ -+ /// Returns true if `inst` was not contained in the set before inserting. -+ @discardableResult -+ mutating func insert(_ operand: Operand) -> Bool { -+ bridged.insert(operand.bridged) -+ } -+ -+ mutating func erase(_ operand: Operand) { -+ bridged.erase(operand.bridged) -+ } -+ -+ var description: String { -+ let function = bridged.getFunction().function -+ var d = "{\n" -+ for inst in function.instructions { -+ for op in inst.operands { -+ if contains(op) { -+ d += op.description -+ } -+ } -+ } -+ d += "}\n" -+ return d -+ } -+ -+ /// TODO: once we have move-only types, make this a real deinit. -+ mutating func deinitialize() { -+ context.freeOperandSet(bridged) -+ } -+} -diff --git a/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Worklist.swift b/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Worklist.swift -index c36002ab59e8b..a5d1a00ff9ec3 100644 ---- a/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Worklist.swift -+++ b/swift/SwiftCompilerSources/Sources/Optimizer/DataStructures/Worklist.swift -@@ -75,3 +75,4 @@ struct Worklist : CustomStringConvertible, NoReflectionChildr - typealias BasicBlockWorklist = Worklist - typealias InstructionWorklist = Worklist - typealias ValueWorklist = Worklist -+typealias OperandWorklist = Worklist -diff --git a/swift/SwiftCompilerSources/Sources/SIL/Operand.swift b/swift/SwiftCompilerSources/Sources/SIL/Operand.swift -index f3369ae01a843..d353cf45aef6a 100644 ---- a/swift/SwiftCompilerSources/Sources/SIL/Operand.swift -+++ b/swift/SwiftCompilerSources/Sources/SIL/Operand.swift -@@ -14,7 +14,7 @@ import SILBridging - - /// An operand of an instruction. - public struct Operand : CustomStringConvertible, NoReflectionChildren { -- fileprivate let bridged: BridgedOperand -+ public let bridged: BridgedOperand - - public init(bridged: BridgedOperand) { - self.bridged = bridged -diff --git a/swift/include/swift/Basic/Require.h b/swift/include/swift/Basic/Require.h -new file mode 100644 -index 0000000000000..54d1aed574c59 ---- /dev/null -+++ b/swift/include/swift/Basic/Require.h -@@ -0,0 +1,34 @@ -+//===--- Require.h ----------------------------------------------*- C++ -*-===// -+// -+// This source file is part of the Swift.org open source project -+// -+// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors -+// Licensed under Apache License v2.0 with Runtime Library Exception -+// -+// See https://swift.org/LICENSE.txt for license information -+// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors -+// -+//===----------------------------------------------------------------------===// -+// -+// This file defines swift_unreachable, which provides the -+// functionality of llvm_unreachable without necessarily depending on -+// the LLVM support libraries. -+// -+//===----------------------------------------------------------------------===// -+ -+#ifndef SWIFT_BASIC_REQUIRE_H -+#define SWIFT_BASIC_REQUIRE_H -+ -+#include "llvm/Support/raw_ostream.h" -+namespace swift { -+/// Checks the `condition` and if it's false abort with `message`. -+/// In contrast to `assert` and similar functions, `require` works in -+/// no-assert builds the same way as in debug builds. -+inline void require(bool condition, const char *message) { -+ if (!condition) { -+ llvm::errs() << message << '\n'; -+ abort(); -+ } -+} -+} -+#endif -diff --git a/swift/include/swift/SIL/SILBasicBlock.h b/swift/include/swift/SIL/SILBasicBlock.h -index d1a72d5a6f683..ddd81e02b89e6 100644 ---- a/swift/include/swift/SIL/SILBasicBlock.h -+++ b/swift/include/swift/SIL/SILBasicBlock.h -@@ -130,16 +130,13 @@ public SwiftObjectHeader { - /// DD and EEE are uninitialized - /// - /// See also: SILBitfield::bitfieldID, SILFunction::currentBitfieldID. -- int64_t lastInitializedBitfieldID = 0; -+ uint64_t lastInitializedBitfieldID = 0; - - // Used by `BasicBlockBitfield`. - unsigned getCustomBits() const { return customBits; } - // Used by `BasicBlockBitfield`. - void setCustomBits(unsigned value) { customBits = value; } - -- // Used by `BasicBlockBitfield`. -- enum { numCustomBits = std::numeric_limits::digits }; -- - friend struct llvm::ilist_traits; - - SILBasicBlock(); -@@ -155,7 +152,8 @@ public SwiftObjectHeader { - - ~SILBasicBlock(); - -- bool isMarkedAsDeleted() const { return lastInitializedBitfieldID < 0; } -+ enum { numCustomBits = std::numeric_limits::digits }; -+ enum { maxBitfieldID = std::numeric_limits::max() }; - - /// Gets the ID (= index in the function's block list) of the block. - /// -diff --git a/swift/include/swift/SIL/SILBitfield.h b/swift/include/swift/SIL/SILBitfield.h -index 7e445a72b5262..148c0109a9924 100644 ---- a/swift/include/swift/SIL/SILBitfield.h -+++ b/swift/include/swift/SIL/SILBitfield.h -@@ -17,6 +17,7 @@ - #ifndef SWIFT_SIL_SILBITFIELD_H - #define SWIFT_SIL_SILBITFIELD_H - -+#include "swift/Basic/Require.h" - #include "swift/SIL/SILFunction.h" - - namespace swift { -@@ -30,7 +31,7 @@ template class SILBitfield { - /// that the bits of that block are not initialized yet. - /// See also: SILBasicBlock::lastInitializedBitfieldID, - /// SILFunction::currentBitfieldID -- int64_t bitfieldID; -+ uint64_t bitfieldID; - - short startBit; - short endBit; -@@ -55,11 +56,13 @@ template class SILBitfield { - parent(parent), - function(function) { - assert(size > 0 && "bit field size must be > 0"); -- assert(endBit <= T::numCustomBits && "too many/large bit fields allocated in function"); -+ require(endBit <= T::numCustomBits, -+ "too many/large bit fields allocated in function"); - assert((!parent || bitfieldID > parent->bitfieldID) && - "BasicBlockBitfield indices are not in order"); -+ require(function->currentBitfieldID < T::maxBitfieldID, -+ "currentBitfieldID overflow"); - ++function->currentBitfieldID; -- assert(function->currentBitfieldID != 0 && "currentBitfieldID overflow"); - } - - SILBitfield(const SILBitfield &) = delete; -@@ -85,9 +88,6 @@ template class SILBitfield { - unsigned clearMask = mask; - if (bitfieldID > entity->lastInitializedBitfieldID) { - -- if (entity->isMarkedAsDeleted()) -- return; -- - // The bitfield is not initialized yet in this block. - // Initialize the bitfield, and also initialize all parent bitfields, - // which are not initialized, yet. Example: -diff --git a/swift/include/swift/SIL/SILFunction.h b/swift/include/swift/SIL/SILFunction.h -index 27fd1b5d91505..a624914c7574f 100644 ---- a/swift/include/swift/SIL/SILFunction.h -+++ b/swift/include/swift/SIL/SILFunction.h -@@ -294,7 +294,7 @@ class SILFunction - /// A monotonically increasing ID which is incremented whenever a - /// BasicBlockBitfield, NodeBitfield, or OperandBitfield is constructed. For - /// details see SILBitfield::bitfieldID; -- int64_t currentBitfieldID = 1; -+ uint64_t currentBitfieldID = 1; - - /// Unique identifier for vector indexing and deterministic sorting. - /// May be reused when zombie functions are recovered. -diff --git a/swift/include/swift/SIL/SILNode.h b/swift/include/swift/SIL/SILNode.h -index 74f8ac228970b..b72705f5e8324 100644 ---- a/swift/include/swift/SIL/SILNode.h -+++ b/swift/include/swift/SIL/SILNode.h -@@ -126,6 +126,9 @@ class alignas(8) SILNode : - enum { NumAllocRefTailTypesBits = 4 }; - enum { NumMarkDependenceKindBits = 2 }; - -+ enum { numCustomBits = 20 }; -+ enum { maxBitfieldID = std::numeric_limits::max() >> numCustomBits }; -+ - protected: - friend class SILInstruction; - template friend class SILBitfield; -@@ -135,11 +138,7 @@ class alignas(8) SILNode : - - uint8_t kind; - -- // Used by `NodeBitfield`. -- enum { numCustomBits = 8 }; -- -- // Used by `NodeBitfield`. -- uint8_t customBits; -+ bool deleted = false; - - // Part of SILInstruction's debug location. Together with - // `SILInstruction::locationStorage` this forms the SILLocation. -@@ -364,6 +363,9 @@ class alignas(8) SILNode : - - //===---------------------- end of shared fields ------------------------===// - -+ // Used by `NodeBitfield`. -+ uint64_t customBits : numCustomBits; -+ - /// The NodeBitfield ID of the last initialized bitfield in `customBits`. - /// Example: - /// -@@ -377,20 +379,19 @@ class alignas(8) SILNode : - /// -> AAA, BB and C are initialized, - /// DD and EEE are uninitialized - /// -- /// If the ID is negative, it means that the node (in case it's an instruction) -- /// is deleted, i.e. it does not belong to the function anymore. Conceptually -- /// this results in setting all bitfields to zero, which e.g. "removes" the -- /// node from all NodeSets. -+ /// The size of lastInitializedBitfieldID should be more than 32 bits to -+ /// absolutely avoid an overflow. - /// - /// See also: SILBitfield::bitfieldID, SILFunction::currentBitfieldID. -- int64_t lastInitializedBitfieldID = 0; -+ uint64_t lastInitializedBitfieldID : (64 - numCustomBits); - - private: - SwiftMetatype getSILNodeMetatype(SILNodeKind kind); - - protected: - SILNode(SILNodeKind kind) : SwiftObjectHeader(getSILNodeMetatype(kind)), -- kind((uint8_t)kind) { -+ kind((uint8_t)kind), -+ customBits(0), lastInitializedBitfieldID(0) { - _sharedUInt8_private.opaque = 0; - _sharedUInt32_private.opaque = 0; - } -@@ -442,11 +443,8 @@ class alignas(8) SILNode : - lastInitializedBitfieldID = 0; - } - -- void markAsDeleted() { -- lastInitializedBitfieldID = -1; -- } -- -- bool isMarkedAsDeleted() const { return lastInitializedBitfieldID < 0; } -+ void markAsDeleted() { deleted = true; } -+ bool isMarkedAsDeleted() const { return deleted; } - - static SILNode *instAsNode(SILInstruction *inst); - static const SILNode *instAsNode(const SILInstruction *inst); -diff --git a/swift/include/swift/SIL/SILValue.h b/swift/include/swift/SIL/SILValue.h -index 5916b686b76dd..756e96e95ae58 100644 ---- a/swift/include/swift/SIL/SILValue.h -+++ b/swift/include/swift/SIL/SILValue.h -@@ -1019,38 +1019,40 @@ ValueOwnershipKind::getForwardingOperandOwnership(bool allowUnowned) const { - /// A formal SIL reference to a value, suitable for use as a stored - /// operand. - class Operand { -+public: -+ enum { numCustomBits = 8 }; -+ enum { maxBitfieldID = std::numeric_limits::max() >> numCustomBits }; -+ -+private: - template friend class SILBitfield; - -- /// The value used as this operand combined with three bits we use for -- /// `customBits`. -- llvm::PointerIntPair TheValueAndThreeBits = {SILValue(), 0}; -+ /// The value used as this operand. -+ SILValue TheValue; - -- /// The next operand in the use-chain. Note that the chain holds every use of -- /// the current ValueBase, not just those of the designated result. -- /// -- /// We use 3 bits of the pointer for customBits. -- llvm::PointerIntPair NextUseAndThreeBits = {nullptr, 0}; -+ /// The next operand in the use-chain. Note that the chain holds -+ /// every use of the current ValueBase, not just those of the -+ /// designated result. -+ Operand *NextUse = nullptr; - - /// A back-pointer in the use-chain, required for fast patching - /// of use-chains. -- /// -- /// We use 2 bits of the pointer for customBits. -- llvm::PointerIntPair BackAndThreeBits = {nullptr, 0}; -+ Operand **Back = nullptr; - - /// The owner of this operand. - /// FIXME: this could be space-compressed. - SILInstruction *Owner; - -- /// Used by `OperandBitfield` -- enum { numCustomBits = 8 }; -+ uint64_t customBits : numCustomBits; - -- /// Used by `OperandBitfield` -- int64_t lastInitializedBitfieldID = 0; -+ // For details see SILNode::lastInitializedBitfieldID -+ uint64_t lastInitializedBitfieldID : (64 - numCustomBits); - - public: -- Operand(SILInstruction *owner) : Owner(owner) {} -+ Operand(SILInstruction *owner) -+ : Owner(owner), customBits(0), lastInitializedBitfieldID(0) {} - Operand(SILInstruction *owner, SILValue theValue) -- : TheValueAndThreeBits(theValue), Owner(owner) { -+ : TheValue(theValue), Owner(owner), -+ customBits(0), lastInitializedBitfieldID(0) { - insertIntoCurrent(); - } - -@@ -1062,14 +1064,14 @@ class Operand { - Operand &operator=(Operand &&) = default; - - /// Return the current value being used by this operand. -- SILValue get() const { return TheValueAndThreeBits.getPointer(); } -+ SILValue get() const { return TheValue; } - - /// Set the current value being used by this operand. - void set(SILValue newValue) { - // It's probably not worth optimizing for the case of switching - // operands on a single value. - removeFromCurrent(); -- TheValueAndThreeBits.setPointer(newValue); -+ TheValue = newValue; - insertIntoCurrent(); - } - -@@ -1083,9 +1085,9 @@ class Operand { - /// Remove this use of the operand. - void drop() { - removeFromCurrent(); -- TheValueAndThreeBits = {SILValue(), 0}; -- NextUseAndThreeBits = {nullptr, 0}; -- BackAndThreeBits = {nullptr, 0}; -+ TheValue = SILValue(); -+ NextUse = nullptr; -+ Back = nullptr; - Owner = nullptr; - } - -@@ -1097,7 +1099,7 @@ class Operand { - SILInstruction *getUser() { return Owner; } - const SILInstruction *getUser() const { return Owner; } - -- Operand *getNextUse() const { return NextUseAndThreeBits.getPointer(); } -+ Operand *getNextUse() const { return NextUse; } - - /// Return true if this operand is a type dependent operand. - /// -@@ -1147,32 +1149,14 @@ class Operand { - SILBasicBlock *getParentBlock() const; - SILFunction *getParentFunction() const; - -- unsigned getCustomBits() const { -- unsigned bits = 0; -- bits |= TheValueAndThreeBits.getInt(); -- bits |= NextUseAndThreeBits.getInt() << 3; -- bits |= BackAndThreeBits.getInt() << 2; -- return bits; -- } -- -- void setCustomBits(unsigned bits) { -- assert(bits < 256 && "Can only store a byte?!"); -- TheValueAndThreeBits.setInt(bits & 0x7); -- NextUseAndThreeBits.setInt((bits >> 3) & 0x7); -- BackAndThreeBits.setInt((bits >> 6) & 0x3); -- } -+ unsigned getCustomBits() const { return customBits; } -+ void setCustomBits(unsigned bits) {customBits = bits; } - - // Called when transferring basic blocks from one function to another. - void resetBitfields() { - lastInitializedBitfieldID = 0; - } - -- void markAsDeleted() { -- lastInitializedBitfieldID = -1; -- } -- -- bool isMarkedAsDeleted() const { return lastInitializedBitfieldID < 0; } -- - SILFunction *getFunction() const; - - void print(llvm::raw_ostream &os) const; -@@ -1180,30 +1164,21 @@ class Operand { - - private: - void removeFromCurrent() { -- auto *back = getBack(); -- if (!back) -- return; -- auto *nextUse = getNextUse(); -- *back = nextUse; -- if (nextUse) -- nextUse->setBack(back); -+ if (!Back) -+ return; -+ *Back = NextUse; -+ if (NextUse) -+ NextUse->Back = Back; - } - - void insertIntoCurrent() { -- auto **firstUse = &get()->FirstUse; -- setBack(firstUse); -- setNextUse(*firstUse); -- if (auto *nextUse = getNextUse()) -- nextUse->setBack(NextUseAndThreeBits.getAddrOfPointer()); -- get()->FirstUse = this; -+ Back = &TheValue->FirstUse; -+ NextUse = TheValue->FirstUse; -+ if (NextUse) -+ NextUse->Back = &NextUse; -+ TheValue->FirstUse = this; - } - -- void setNextUse(Operand *op) { NextUseAndThreeBits.setPointer(op); } -- -- Operand **getBack() const { return BackAndThreeBits.getPointer(); } -- -- void setBack(Operand **newValue) { BackAndThreeBits.setPointer(newValue); } -- - friend class ValueBase; - friend class ValueBaseUseIterator; - friend class ConsumingUseIterator; -diff --git a/swift/include/swift/SILOptimizer/OptimizerBridging.h b/swift/include/swift/SILOptimizer/OptimizerBridging.h -index e0194a2b7b48a..ea8ef4210fec8 100644 ---- a/swift/include/swift/SILOptimizer/OptimizerBridging.h -+++ b/swift/include/swift/SILOptimizer/OptimizerBridging.h -@@ -50,6 +50,7 @@ class DominanceInfo; - class PostDominanceInfo; - class BasicBlockSet; - class NodeSet; -+class OperandSet; - class ClonerWithFixedLocation; - class SwiftPassInvocation; - class FixedSizeSlabPayload; -@@ -155,6 +156,15 @@ struct BridgedNodeSet { - SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getFunction() const; - }; - -+struct BridgedOperandSet { -+ swift::OperandSet * _Nonnull set; -+ -+ BRIDGED_INLINE bool contains(BridgedOperand operand) const; -+ BRIDGED_INLINE bool insert(BridgedOperand operand) const; -+ BRIDGED_INLINE void erase(BridgedOperand operand) const; -+ SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedFunction getFunction() const; -+}; -+ - struct BridgedCloner { - swift::ClonerWithFixedLocation * _Nonnull cloner; - -@@ -244,6 +254,8 @@ struct BridgedPassContext { - BRIDGED_INLINE void freeBasicBlockSet(BridgedBasicBlockSet set) const; - SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedNodeSet allocNodeSet() const; - BRIDGED_INLINE void freeNodeSet(BridgedNodeSet set) const; -+ SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedOperandSet allocOperandSet() const; -+ BRIDGED_INLINE void freeOperandSet(BridgedOperandSet set) const; - - // Stack nesting - -diff --git a/swift/include/swift/SILOptimizer/OptimizerBridgingImpl.h b/swift/include/swift/SILOptimizer/OptimizerBridgingImpl.h -index 81ec890a88e1b..c79133a6c5447 100644 ---- a/swift/include/swift/SILOptimizer/OptimizerBridgingImpl.h -+++ b/swift/include/swift/SILOptimizer/OptimizerBridgingImpl.h -@@ -129,6 +129,26 @@ BridgedFunction BridgedNodeSet::getFunction() const { - return {set->getFunction()}; - } - -+//===----------------------------------------------------------------------===// -+// BridgedOperandSet -+//===----------------------------------------------------------------------===// -+ -+bool BridgedOperandSet::contains(BridgedOperand operand) const { -+ return set->contains(operand.op); -+} -+ -+bool BridgedOperandSet::insert(BridgedOperand operand) const { -+ return set->insert(operand.op); -+} -+ -+void BridgedOperandSet::erase(BridgedOperand operand) const { -+ set->erase(operand.op); -+} -+ -+BridgedFunction BridgedOperandSet::getFunction() const { -+ return {set->getFunction()}; -+} -+ - //===----------------------------------------------------------------------===// - // BridgedPassContext - //===----------------------------------------------------------------------===// -@@ -256,6 +276,14 @@ void BridgedPassContext::freeNodeSet(BridgedNodeSet set) const { - invocation->freeNodeSet(set.set); - } - -+BridgedOperandSet BridgedPassContext::allocOperandSet() const { -+ return {invocation->allocOperandSet()}; -+} -+ -+void BridgedPassContext::freeOperandSet(BridgedOperandSet set) const { -+ invocation->freeOperandSet(set.set); -+} -+ - void BridgedPassContext::notifyInvalidatedStackNesting() const { - invocation->setNeedFixStackNesting(true); - } -diff --git a/swift/include/swift/SILOptimizer/PassManager/PassManager.h b/swift/include/swift/SILOptimizer/PassManager/PassManager.h -index daf060c43829b..b1f12580f02ec 100644 ---- a/swift/include/swift/SILOptimizer/PassManager/PassManager.h -+++ b/swift/include/swift/SILOptimizer/PassManager/PassManager.h -@@ -14,6 +14,7 @@ - #include "swift/SIL/InstructionUtils.h" - #include "swift/SIL/BasicBlockBits.h" - #include "swift/SIL/NodeBits.h" -+#include "swift/SIL/OperandBits.h" - #include "swift/SILOptimizer/Analysis/Analysis.h" - #include "swift/SILOptimizer/PassManager/PassPipeline.h" - #include "swift/SILOptimizer/PassManager/Passes.h" -@@ -73,16 +74,21 @@ class SwiftPassInvocation { - - SILSSAUpdater *ssaUpdater = nullptr; - -- static constexpr int BlockSetCapacity = 16; -+ static constexpr int BlockSetCapacity = SILBasicBlock::numCustomBits; - char blockSetStorage[sizeof(BasicBlockSet) * BlockSetCapacity]; - bool aliveBlockSets[BlockSetCapacity]; - int numBlockSetsAllocated = 0; - -- static constexpr int NodeSetCapacity = 8; -+ static constexpr int NodeSetCapacity = SILNode::numCustomBits; - char nodeSetStorage[sizeof(NodeSet) * NodeSetCapacity]; - bool aliveNodeSets[NodeSetCapacity]; - int numNodeSetsAllocated = 0; - -+ static constexpr int OperandSetCapacity = Operand::numCustomBits; -+ char operandSetStorage[sizeof(OperandSet) * OperandSetCapacity]; -+ bool aliveOperandSets[OperandSetCapacity]; -+ int numOperandSetsAllocated = 0; -+ - int numClonersAllocated = 0; - - bool needFixStackNesting = false; -@@ -123,6 +129,10 @@ class SwiftPassInvocation { - - void freeNodeSet(NodeSet *set); - -+ OperandSet *allocOperandSet(); -+ -+ void freeOperandSet(OperandSet *set); -+ - /// The top-level API to erase an instruction, called from the Swift pass. - void eraseInstruction(SILInstruction *inst); - -diff --git a/swift/lib/SIL/IR/SILBasicBlock.cpp b/swift/lib/SIL/IR/SILBasicBlock.cpp -index 7198afb189837..8419eaf41a4f3 100644 ---- a/swift/lib/SIL/IR/SILBasicBlock.cpp -+++ b/swift/lib/SIL/IR/SILBasicBlock.cpp -@@ -335,6 +335,9 @@ transferNodesFromList(llvm::ilist_traits &SrcTraits, - for (SILValue result : II.getResults()) { - result->resetBitfields(); - } -+ for (Operand &op : II.getAllOperands()) { -+ op.resetBitfields(); -+ } - II.asSILNode()->resetBitfields(); - - II.setDebugScope(ScopeCloner.getOrCreateClonedScope(II.getDebugScope())); -diff --git a/swift/lib/SIL/IR/SILInstruction.cpp b/swift/lib/SIL/IR/SILInstruction.cpp -index 2f27bfe09b9b8..2d154494d60f3 100644 ---- a/swift/lib/SIL/IR/SILInstruction.cpp -+++ b/swift/lib/SIL/IR/SILInstruction.cpp -@@ -85,6 +85,9 @@ transferNodesFromList(llvm::ilist_traits &L2, - for (SILValue result : first->getResults()) { - result->resetBitfields(); - } -+ for (Operand &op : first->getAllOperands()) { -+ op.resetBitfields(); -+ } - first->asSILNode()->resetBitfields(); - } - } -diff --git a/swift/lib/SILOptimizer/PassManager/PassManager.cpp b/swift/lib/SILOptimizer/PassManager/PassManager.cpp -index c5d9025b00d22..651afa5cfb322 100644 ---- a/swift/lib/SILOptimizer/PassManager/PassManager.cpp -+++ b/swift/lib/SILOptimizer/PassManager/PassManager.cpp -@@ -1402,8 +1402,8 @@ FixedSizeSlab *SwiftPassInvocation::freeSlab(FixedSizeSlab *slab) { - } - - BasicBlockSet *SwiftPassInvocation::allocBlockSet() { -- assert(numBlockSetsAllocated < BlockSetCapacity - 1 && -- "too many BasicBlockSets allocated"); -+ require(numBlockSetsAllocated < BlockSetCapacity, -+ "too many BasicBlockSets allocated"); - - auto *storage = (BasicBlockSet *)blockSetStorage + numBlockSetsAllocated; - BasicBlockSet *set = new (storage) BasicBlockSet(function); -@@ -1426,8 +1426,8 @@ void SwiftPassInvocation::freeBlockSet(BasicBlockSet *set) { - } - - NodeSet *SwiftPassInvocation::allocNodeSet() { -- assert(numNodeSetsAllocated < NodeSetCapacity - 1 && -- "too many BasicNodeSets allocated"); -+ require(numNodeSetsAllocated < NodeSetCapacity, -+ "too many NodeSets allocated"); - - auto *storage = (NodeSet *)nodeSetStorage + numNodeSetsAllocated; - NodeSet *set = new (storage) NodeSet(function); -@@ -1449,6 +1449,30 @@ void SwiftPassInvocation::freeNodeSet(NodeSet *set) { - } - } - -+OperandSet *SwiftPassInvocation::allocOperandSet() { -+ require(numOperandSetsAllocated < OperandSetCapacity, -+ "too many OperandSets allocated"); -+ -+ auto *storage = (OperandSet *)operandSetStorage + numOperandSetsAllocated; -+ OperandSet *set = new (storage) OperandSet(function); -+ aliveOperandSets[numOperandSetsAllocated] = true; -+ ++numOperandSetsAllocated; -+ return set; -+} -+ -+void SwiftPassInvocation::freeOperandSet(OperandSet *set) { -+ int idx = set - (OperandSet *)operandSetStorage; -+ assert(idx >= 0 && idx < numOperandSetsAllocated); -+ assert(aliveOperandSets[idx] && "double free of OperandSet"); -+ aliveOperandSets[idx] = false; -+ -+ while (numOperandSetsAllocated > 0 && !aliveOperandSets[numOperandSetsAllocated - 1]) { -+ auto *set = (OperandSet *)operandSetStorage + numOperandSetsAllocated - 1; -+ set->~OperandSet(); -+ --numOperandSetsAllocated; -+ } -+} -+ - void SwiftPassInvocation::startModulePassRun(SILModuleTransform *transform) { - assert(!this->function && !this->transform && "a pass is already running"); - this->function = nullptr; -@@ -1493,6 +1517,7 @@ void SwiftPassInvocation::endPass() { - assert(allocatedSlabs.empty() && "StackList is leaking slabs"); - assert(numBlockSetsAllocated == 0 && "Not all BasicBlockSets deallocated"); - assert(numNodeSetsAllocated == 0 && "Not all NodeSets deallocated"); -+ assert(numOperandSetsAllocated == 0 && "Not all OperandSets deallocated"); - assert(numClonersAllocated == 0 && "Not all cloners deallocated"); - assert(!needFixStackNesting && "Stack nesting not fixed"); - if (ssaUpdater) { -@@ -1517,6 +1542,7 @@ void SwiftPassInvocation::endTransformFunction() { - function = nullptr; - assert(numBlockSetsAllocated == 0 && "Not all BasicBlockSets deallocated"); - assert(numNodeSetsAllocated == 0 && "Not all NodeSets deallocated"); -+ assert(numOperandSetsAllocated == 0 && "Not all OperandSets deallocated"); - } - - void SwiftPassInvocation::beginVerifyFunction(SILFunction *function) { -@@ -1535,6 +1561,7 @@ void SwiftPassInvocation::endVerifyFunction() { - "verifyication must not change the SIL of a function"); - assert(numBlockSetsAllocated == 0 && "Not all BasicBlockSets deallocated"); - assert(numNodeSetsAllocated == 0 && "Not all NodeSets deallocated"); -+ assert(numOperandSetsAllocated == 0 && "Not all OperandSets deallocated"); - function = nullptr; - } - } -diff --git a/swift/unittests/SIL/SILBitfieldTest.cpp b/swift/unittests/SIL/SILBitfieldTest.cpp -index c9d23bf06b8e1..a11ace8c5483e 100644 ---- a/swift/unittests/SIL/SILBitfieldTest.cpp -+++ b/swift/unittests/SIL/SILBitfieldTest.cpp -@@ -21,20 +21,20 @@ class BasicBlockBitfield; - - struct SILFunction { - BasicBlockBitfield *newestAliveBlockBitfield = nullptr; -- int64_t currentBitfieldID = 1; -+ uint64_t currentBitfieldID = 1; - }; - - struct SILBasicBlock { - SILFunction *function; - uint32_t customBits = 0; -- int64_t lastInitializedBitfieldID = 0; -+ uint64_t lastInitializedBitfieldID = 0; - - enum { numCustomBits = 32 }; -+ enum { maxBitfieldID = std::numeric_limits::max() }; - - SILBasicBlock(SILFunction *function): function(function) {} - - SILFunction *getFunction() const { return function; } -- bool isMarkedAsDeleted() const { return false; } - - unsigned getCustomBits() const { return customBits; } - void setCustomBits(unsigned value) { customBits = value; } diff --git a/packages/swift/swift-cmake.patch b/packages/swift/swift-cmake.patch index 6851e640c697c37..99ba9f7ffa61788 100644 --- a/packages/swift/swift-cmake.patch +++ b/packages/swift/swift-cmake.patch @@ -48,18 +48,6 @@ diff --git a/swift/CMakeLists.txt b/swift/CMakeLists.txt index b7503ecdd6..c643c2c9a5 100644 --- a/swift/CMakeLists.txt +++ b/swift/CMakeLists.txt -@@ -414,9 +414,9 @@ set(SWIFT_STDLIB_MSVC_RUNTIME_LIBRARY - - - if(BRIDGING_MODE STREQUAL "DEFAULT" OR NOT BRIDGING_MODE) -- if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" MATCHES "WINDOWS|ANDROID" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8)) -+ if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WINDOWS" OR (CMAKE_Swift_COMPILER AND CMAKE_Swift_COMPILER_VERSION VERSION_LESS 5.8)) - # In debug builds, to workaround a problem with LLDB's `po` command (rdar://115770255). -- # On Windows and Android, to workaround a build problem. -+ # On Windows, to workaround a build problem. - # If the host Swift version is less than 5.8, use pure mode to workaround a C++ interop compiler crash. - set(BRIDGING_MODE "PURE") - else() @@ -463,7 +463,7 @@ set(SWIFT_BUILD_HOST_DISPATCH FALSE) if(SWIFT_ENABLE_DISPATCH AND NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") # Only build libdispatch for the host if the host tools are being built and @@ -69,6 +57,24 @@ index b7503ecdd6..c643c2c9a5 100644 set(SWIFT_BUILD_HOST_DISPATCH TRUE) endif() +@@ -966,7 +966,7 @@ if("${SWIFT_NATIVE_SWIFT_TOOLS_PATH}" STREQUAL "") + message(WARNING "BOOTSTRAPPING set to OFF because no Swift compiler is defined") + set(BOOTSTRAPPING_MODE "OFF") + endif() +-elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*") ++elseif(BOOTSTRAPPING_MODE MATCHES "HOSTTOOLS") + # If cross-compiling, we don't have to bootstrap. We can just use the previously + # built native swiftc to build the swift compiler modules. + message(STATUS "Building swift modules with previously built tools instead of bootstrapping") +@@ -976,7 +976,7 @@ elseif(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*") + elseif(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING") + set(BOOTSTRAPPING_MODE "CROSSCOMPILE") + else() +- set(BOOTSTRAPPING_MODE "HOSTTOOLS") ++ set(BOOTSTRAPPING_MODE "CROSSCOMPILE") + endif() + elseif(BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS" OR SWIFT_BUILD_SWIFT_SYNTAX) + # We are building using a pre-installed host toolchain but not bootstrapping @@ -1279,7 +1280,8 @@ if (LLVM_ENABLE_DOXYGEN) message(STATUS "Doxygen: enabled") endif() @@ -79,22 +85,32 @@ index b7503ecdd6..c643c2c9a5 100644 include(Libdispatch) endif() +diff --git a/swift/lib/CompilerSwiftSyntax/CMakeLists.txt b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt +index 849cf90fee0..f2a08df0e57 100644 +--- a/swift/lib/CompilerSwiftSyntax/CMakeLists.txt ++++ b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt +@@ -49,6 +49,9 @@ set(compiler_swiftsyntax_libs + + foreach(lib ${compiler_swiftsyntax_libs}) + target_compile_options(${lib} PRIVATE "SHELL:-module-link-name ${lib}") ++ if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE") ++ add_dependencies(${lib} swift-stdlib-${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}-${SWIFT_HOST_VARIANT_ARCH}) ++ endif() + endforeach() + + swift_install_in_component(TARGETS ${compiler_swiftsyntax_libs} diff --git a/swift/SwiftCompilerSources/CMakeLists.txt b/swift/SwiftCompilerSources/CMakeLists.txt -index 79413a711d4..9eca061e1ca 100644 --- a/swift/SwiftCompilerSources/CMakeLists.txt +++ b/swift/SwiftCompilerSources/CMakeLists.txt -@@ -172,7 +172,11 @@ function(add_swift_compiler_modules_library name) - # under `include/swift`. These are either located next to the compiler (in case of open source toolchains) or - # in the SDK (in case a Swift compiler from Xcode) - get_filename_component(swift_exec_bin_dir ${ALS_SWIFT_EXEC} DIRECTORY) -+ if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE") -+ list(APPEND sdk_option "-I" "${SWIFTLIB_DIR}/../") -+ else() - list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib") -+ endif() +@@ -196,6 +196,8 @@ - set(all_obj_files) - set(all_module_targets) + # Workaround for https://github.com/swiftlang/llvm-project/issues/7172 + list(APPEND swift_compile_options "-Xcc" "-Xclang" "-Xcc" "-fmodule-format=raw") ++ elseif(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE") ++ list(APPEND sdk_option "-I" "${SWIFTLIB_DIR}/../") + else() + list(APPEND sdk_option "-I" "${swift_exec_bin_dir}/../lib" "-I" "${sdk_path}/usr/lib") + endif() diff --git a/swift/lib/SwiftSyntax/CMakeLists.txt b/swift/lib/SwiftSyntax/CMakeLists.txt index 5c7bd65fead..36f3bbc1b91 100644 --- a/swift/lib/SwiftSyntax/CMakeLists.txt @@ -159,6 +175,19 @@ index f958d4ce899..ac6d7248606 100644 TARGET_SDKS "ANDROID" INSTALL_IN_COMPONENT sdk-overlay DEPENDS android_modulemap) +diff --git a/swift/stdlib/public/core/CMakeLists.txt b/swift/stdlib/public/core/CMakeLists.txt +index 27a4b2bbc6e..5469b3457a6 100644 +--- a/swift/stdlib/public/core/CMakeLists.txt ++++ b/swift/stdlib/public/core/CMakeLists.txt +@@ -404,7 +404,7 @@ if(BOOTSTRAPPING_MODE STREQUAL "BOOTSTRAPPING") + endif() + + set(tooling_stdlib_deps) +-if(TARGET libSwiftScan) ++if(NOT BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE" AND TARGET libSwiftScan) + list(APPEND tooling_stdlib_deps libSwiftScan) + endif() + diff --git a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake b/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake index 7a77e125f95..7eddfea2054 100644 --- a/swift/tools/SourceKit/cmake/modules/AddSwiftSourceKit.cmake diff --git a/packages/swift/swift-crosscompile-swift-syntax.patch b/packages/swift/swift-crosscompile-swift-syntax.patch index fc807b249be7061..b896dd4861fffc4 100644 --- a/packages/swift/swift-crosscompile-swift-syntax.patch +++ b/packages/swift/swift-crosscompile-swift-syntax.patch @@ -1,29 +1,3 @@ -diff --git a/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift b/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -index 44be07e2..4450c8e3 100644 ---- a/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -+++ b/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -@@ -10,7 +10,7 @@ - // - //===----------------------------------------------------------------------===// - --#if swift(>=6.0) -+#if compiler(>=6.0) - public import SwiftSyntaxMacros - @_spi(PluginMessage) public import SwiftCompilerPluginMessageHandling - private import _SwiftLibraryPluginProviderCShims -diff --git a/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift b/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -index 4d877962..9e12e3a9 100644 ---- a/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -+++ b/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -@@ -10,7 +10,7 @@ - // - //===----------------------------------------------------------------------===// - --#if swift(>=6.0) -+#if compiler(>=6.0) - #if canImport(Darwin) - private import Darwin - #elseif canImport(Glibc) diff --git a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake b/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake index 2a16fa5e..b7fedd87 100644 --- a/swift-syntax/cmake/modules/AddSwiftHostLibrary.cmake @@ -33,15 +7,15 @@ index 2a16fa5e..b7fedd87 100644 ) + if(BOOTSTRAPPING_MODE STREQUAL "CROSSCOMPILE") -+ target_compile_options(${name} PRIVATE ++ target_compile_options(${target} PRIVATE + $<$:-sdk;${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_ARCH_${SWIFT_HOST_VARIANT_ARCH}_PATH};> + $<$:-resource-dir;${SWIFTLIB_DIR};>) + if(SWIFT_HOST_VARIANT_SDK STREQUAL "ANDROID" AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") + swift_android_tools_path(${SWIFT_HOST_VARIANT_ARCH} tools_path) -+ target_compile_options(${name} PRIVATE $<$:-tools-directory;${tools_path};>) ++ target_compile_options(${target} PRIVATE $<$:-tools-directory;${tools_path};>) + endif() + endif() + if(LLVM_USE_LINKER) - target_link_options(${name} PRIVATE + target_link_options(${target} PRIVATE "-use-ld=${LLVM_USE_LINKER}" diff --git a/packages/swift/swift-foundation-armv7.patch b/packages/swift/swift-foundation-armv7.patch deleted file mode 100644 index 6dd3fa7a5c76a5d..000000000000000 --- a/packages/swift/swift-foundation-armv7.patch +++ /dev/null @@ -1,168 +0,0 @@ -commit ad6ca71b4eef90e3ae69b130e3cc989a21192020 -Author: Alex Lorenz -Date: Wed Aug 14 10:56:25 2024 -0700 - - [android] fix the LP32 armv7/i686 android build (#846) - - * [android] fix the LP32 armv7/i686 android build - - * Update Sources/FoundationEssentials/Android+Extensions.swift - - Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com> - - * drop the android Lp32 specific operator & - - --------- - - Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com> - -diff --git a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift -index 2540b14..a779837 100644 ---- a/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift -+++ b/swift-foundation/Sources/FoundationEssentials/Data/Data+Reading.swift -@@ -325,7 +325,7 @@ internal func readBytesFromFile(path inPath: PathOrURL, reportProgress: Bool, ma - } - - let fileSize = min(Int(clamping: filestat.st_size), maxLength ?? Int.max) -- let fileType = filestat.st_mode & S_IFMT -+ let fileType = mode_t(filestat.st_mode) & S_IFMT - #if !NO_FILESYSTEM - let shouldMap = shouldMapFileDescriptor(fd, path: inPath, options: options) - #else -diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift -index 991c5e8..d3e6de3 100644 ---- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift -+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Basics.swift -@@ -221,7 +221,7 @@ internal struct _FileManagerImpl { - var statBuf = stat() - let fd = open(path, 0, 0) - guard fd >= 0 else { return nil } -- if fstat(fd, &statBuf) < 0 || statBuf.st_mode & S_IFMT == S_IFDIR { -+ if fstat(fd, &statBuf) < 0 || mode_t(statBuf.st_mode) & S_IFMT == S_IFDIR { - close(fd) - return nil - } -@@ -240,7 +240,7 @@ internal struct _FileManagerImpl { - } - - /* check for being same type */ -- if myInfo.st_mode & S_IFMT != otherInfo.st_mode & S_IFMT { -+ if mode_t(myInfo.st_mode) & S_IFMT != mode_t(otherInfo.st_mode) & S_IFMT { - return false - } - -diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift -index b8cd50a..bee9fb3 100644 ---- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift -+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Files.swift -@@ -175,7 +175,8 @@ extension stat { - } - - fileprivate var fileAttributes: [FileAttributeKey : Any] { -- let fileType = st_mode.fileType -+ // On 32 bit Android, st_mode is UInt32. -+ let fileType = mode_t(st_mode).fileType - var result: [FileAttributeKey : Any] = [ - .size : _writeFileAttributePrimitive(st_size, as: UInt.self), - .modificationDate : modificationDate, -@@ -400,7 +401,7 @@ extension _FileManagerImpl { - guard stat(rep, &fileInfo) == 0 else { - return (false, false) - } -- let isDir = (fileInfo.st_mode & S_IFMT) == S_IFDIR -+ let isDir = (mode_t(fileInfo.st_mode) & S_IFMT) == S_IFDIR - return (true, isDir) - } - #endif -@@ -479,7 +480,7 @@ extension _FileManagerImpl { - return false - } - -- if ((dirInfo.st_mode & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) { -+ if ((mode_t(dirInfo.st_mode) & S_ISVTX) != 0) && fileManager.fileExists(atPath: path) { - // its sticky so verify that we own the file - // otherwise we answer YES on the principle that if - // we create files we can delete them -diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift -index 9bac967..e531cb5 100644 ---- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift -+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileManager+Utilities.swift -@@ -49,19 +49,19 @@ extension FILETIME { - #if !os(Windows) - extension stat { - var isDirectory: Bool { -- (self.st_mode & S_IFMT) == S_IFDIR -+ (mode_t(self.st_mode) & S_IFMT) == S_IFDIR - } - - var isRegular: Bool { -- (self.st_mode & S_IFMT) == S_IFREG -+ (mode_t(self.st_mode) & S_IFMT) == S_IFREG - } - - var isSymbolicLink: Bool { -- (self.st_mode & S_IFMT) == S_IFLNK -+ (mode_t(self.st_mode) & S_IFMT) == S_IFLNK - } - - var isSpecial: Bool { -- let type = self.st_mode & S_IFMT -+ let type = mode_t(self.st_mode) & S_IFMT - return type == S_IFBLK || type == S_IFCHR - } - } -diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift -index 2c9a02f..500da1d 100644 ---- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift -+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations+Enumeration.swift -@@ -367,7 +367,7 @@ struct _POSIXDirectoryContentsSequence: Sequence { - let statDir = directoryPath + "/" + fileName - if stat(statDir, &statBuf) == 0 { - // #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -- if (statBuf.st_mode & S_IFMT) == S_IFDIR { -+ if (mode_t(statBuf.st_mode) & S_IFMT) == S_IFDIR { - isDirectory = true - } - } -diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift -index 03adcc6..92e609f 100644 ---- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift -+++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift -@@ -867,7 +867,7 @@ enum _FileOperations { - defer { close(dstfd) } - - // Set the file permissions using fchmod() instead of when open()ing to avoid umask() issues -- let permissions = fileInfo.st_mode & ~S_IFMT -+ let permissions = mode_t(fileInfo.st_mode) & ~S_IFMT - guard fchmod(dstfd, permissions) == 0 else { - try delegate.throwIfNecessary(errno, String(cString: srcPtr), String(cString: dstPtr)) - return -diff --git a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift -index 2e809fa..d01ca3f 100644 ---- a/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift -+++ b/swift-foundation/Sources/FoundationEssentials/ProcessInfo/ProcessInfo.swift -@@ -198,7 +198,10 @@ final class _ProcessInfo: Sendable { - } - - var fullUserName: String { --#if canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl) -+#if os(Android) && (arch(i386) || arch(arm)) -+ // On LP32 Android, pw_gecos doesn't exist and is presumed to be NULL. -+ return "" -+#elseif canImport(Darwin) || os(Android) || canImport(Glibc) || canImport(Musl) - let (euid, _) = Platform.getUGIDs() - if let upwd = getpwuid(euid), - let fullname = upwd.pointee.pw_gecos { -diff --git a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift -index 477d5d3..1ce75d6 100644 ---- a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift -+++ b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift -@@ -737,7 +737,7 @@ extension String { - if lstat(buffer.baseAddress!, &statBuf) < 0 { - return nil - } -- if statBuf.st_mode & S_IFMT == S_IFLNK { -+ if mode_t(statBuf.st_mode) & S_IFMT == S_IFLNK { - /* Examples: - * fspath == /foo/bar0baz/quux/froboz - * linkx == /tic/tac/toe diff --git a/packages/swift/swift-foundation-ndk27.patch b/packages/swift/swift-foundation-ndk27.patch index ce3bbdadfbf5fd7..029715024096712 100644 --- a/packages/swift/swift-foundation-ndk27.patch +++ b/packages/swift/swift-foundation-ndk27.patch @@ -10,404 +10,50 @@ index 7f290d16..95366592 100644 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) -diff --git a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h -index a2ba56cd..91a312dc 100644 ---- a/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h -+++ b/swift-corelibs-foundation/Sources/CoreFoundation/include/ForSwiftFoundationOnly.h -@@ -69,6 +69,13 @@ - #include - #include - #include -+#include -+#ifdef __swift__ -+// The linux/stat header is private in the Android modulemap. -+#pragma clang module import posix_filesystem.linux_stat -+#else -+#include -+#endif - #elif TARGET_OS_WASI - #include - #include -diff --git a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift -index ffe3a6c6..c59977f8 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/CGFloat.swift -@@ -7,6 +7,10 @@ - // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors - // - -+#if canImport(Android) -+import Android -+#endif -+ - @frozen - public struct CGFloat: Sendable { - #if arch(i386) || arch(arm) || arch(wasm32) -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -index b07c49ac..b540e284 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -@@ -34,6 +34,11 @@ import WASILibc - fileprivate let _read = WASILibc.read(_:_:_:) - fileprivate let _write = WASILibc.write(_:_:_:) - fileprivate let _close = WASILibc.close(_:) -+#elseif canImport(Android) -+import Android -+fileprivate let _read = Android.read(_:_:_:) -+fileprivate let _write = Android.write(_:_:_:) -+fileprivate let _close = Android.close(_:) - #endif - - #if canImport(WinSDK) -@@ -321,10 +326,15 @@ open class FileHandle : NSObject, @unchecked Sendable { - if options.contains(.alwaysMapped) { - // Filesizes are often 64bit even on 32bit systems - let mapSize = min(length, Int(clamping: statbuf.st_size)) -+ #if canImport(Android) -+ // Bionic mmap() now returns _Nonnull, so the force unwrap below isn't needed. - let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0) -+ #else -+ let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0)! -+ #endif - // Swift does not currently expose MAP_FAILURE - if data != UnsafeMutableRawPointer(bitPattern: -1) { -- return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in -+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in - munmap(buffer, length) - } - } -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -index e89b3bf6..a82fe1c2 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -@@ -7,6 +7,10 @@ - // - #if !os(Windows) - -+#if canImport(Android) -+import Android -+#endif -+ - #if os(Android) && (arch(i386) || arch(arm)) // struct stat.st_mode is UInt32 - internal func &(left: UInt32, right: mode_t) -> mode_t { - return mode_t(left) & right -@@ -398,13 +402,13 @@ extension FileManager { - - _current = fts_read(stream) - while let current = _current { -- let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path, length: Int(current.pointee.fts_pathlen)) -+ let filename = FileManager.default.string(withFileSystemRepresentation: current.pointee.fts_path!, length: Int(current.pointee.fts_pathlen)) - - switch Int32(current.pointee.fts_info) { - case FTS_D: - let (showFile, skipDescendants) = match(filename: filename, to: _options, isDir: true) - if skipDescendants { -- fts_set(_stream, _current, FTS_SKIP) -+ fts_set(stream, current, FTS_SKIP) - } - if showFile { - return URL(fileURLWithPath: filename, isDirectory: true) -@@ -578,7 +582,7 @@ extension FileManager { - let finalErrno = originalItemURL.withUnsafeFileSystemRepresentation { (originalFS) -> Int32? in - return newItemURL.withUnsafeFileSystemRepresentation { (newItemFS) -> Int32? in - // This is an atomic operation in many OSes, but is not guaranteed to be atomic by the standard. -- if rename(newItemFS, originalFS) == 0 { -+ if rename(newItemFS!, originalFS!) == 0 { - return nil - } else { - return errno -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -index a5d75820..a19464d7 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -@@ -21,6 +21,8 @@ import WinSDK - - #if os(WASI) - import WASILibc -+#elseif canImport(Bionic) -+import Bionic - #endif - - #if os(Windows) -diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift -index 6c4f5291..fb130631 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Host.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift -@@ -12,8 +12,9 @@ - import WinSDK - #endif - --#if os(Android) -- // Android Glibc differs a little with respect to the Linux Glibc. -+#if canImport(Android) -+ import Android -+ // Android Bionic differs a little with respect to the Linux Glibc. - - // IFF_LOOPBACK is part of the enumeration net_device_flags, which needs to - // convert to UInt32. -@@ -24,8 +25,8 @@ import WinSDK - } - - // getnameinfo uses size_t for its 4th and 6th arguments. -- private func getnameinfo(_ addr: UnsafePointer?, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { -- return Glibc.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) -+ private func getnameinfo(_ addr: UnsafePointer, _ addrlen: socklen_t, _ host: UnsafeMutablePointer?, _ hostlen: socklen_t, _ serv: UnsafeMutablePointer?, _ servlen: socklen_t, _ flags: Int32) -> Int32 { -+ return Android.getnameinfo(addr, addrlen, host, Int(hostlen), serv, Int(servlen), flags) - } - - // getifaddrs and freeifaddrs are not available in Android 6.0 or earlier, so call these functions dynamically. -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSData.swift b/swift-corelibs-foundation/Sources/Foundation/NSData.swift -index ae54f971..65eb0d93 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSData.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSData.swift -@@ -11,6 +11,9 @@ - #if !os(WASI) - import Dispatch - #endif -+#if canImport(Android) -+import Android -+#endif - - extension NSData { - public typealias ReadingOptions = Data.ReadingOptions -@@ -469,6 +472,8 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding { - let createMode = Int(Musl.S_IRUSR) | Int(Musl.S_IWUSR) | Int(Musl.S_IRGRP) | Int(Musl.S_IWGRP) | Int(Musl.S_IROTH) | Int(Musl.S_IWOTH) - #elseif canImport(WASILibc) - let createMode = Int(WASILibc.S_IRUSR) | Int(WASILibc.S_IWUSR) | Int(WASILibc.S_IRGRP) | Int(WASILibc.S_IWGRP) | Int(WASILibc.S_IROTH) | Int(WASILibc.S_IWOTH) -+#elseif canImport(Android) -+ let createMode = Int(Android.S_IRUSR) | Int(Android.S_IWUSR) | Int(Android.S_IRGRP) | Int(Android.S_IWGRP) | Int(Android.S_IROTH) | Int(Android.S_IWOTH) - #endif - guard let fh = FileHandle(path: path, flags: flags, createMode: createMode) else { - throw _NSErrorWithErrno(errno, reading: false, path: path) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSError.swift b/swift-corelibs-foundation/Sources/Foundation/NSError.swift -index 6f21d3a0..dcd6f3f1 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSError.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSError.swift -@@ -16,6 +16,8 @@ import Darwin - import Glibc - #elseif canImport(CRT) - import CRT -+#elseif canImport(Android) -+import Android - #endif - - @_implementationOnly import CoreFoundation -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -index fe1d08b7..9d0fadc9 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSLock.swift -@@ -11,6 +11,8 @@ - - #if canImport(Glibc) - import Glibc -+#elseif canImport(Bionic) -+import Bionic - #endif - - #if os(Windows) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift -index a1809026..5424f5bb 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSPlatform.swift -@@ -10,6 +10,9 @@ - #if os(macOS) || os(iOS) - fileprivate let _NSPageSize = Int(vm_page_size) - #elseif os(Linux) || os(Android) || os(OpenBSD) -+#if canImport(Android) -+import Android -+#endif - fileprivate let _NSPageSize = Int(getpagesize()) - #elseif os(Windows) - import WinSDK -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -index 03176c17..1509c31d 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSSwiftRuntime.swift -@@ -19,6 +19,8 @@ internal import Synchronization - @_exported import Glibc - #elseif canImport(Musl) - @_exported import Musl -+#elseif canImport(Bionic) -+@_exported import Bionic - #elseif os(WASI) - @_exported import WASILibc - #elseif os(Windows) -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -index 6af73f16..9e6f20d0 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSURL.swift -@@ -22,6 +22,8 @@ import Darwin - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Bionic) -+import Bionic - #endif - - // NOTE: this represents PLATFORM_PATH_STYLE -diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift -index c4ed8282..e71f591b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Port.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift -@@ -107,7 +107,7 @@ fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM - fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP - #endif - --#if canImport(Glibc) && !os(Android) && !os(OpenBSD) -+#if canImport(Glibc) && !os(OpenBSD) - import Glibc - fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue) - fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) -@@ -119,14 +119,19 @@ fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) - fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) - #endif - --#if canImport(Glibc) && os(Android) || os(OpenBSD) -+#if canImport(Glibc) && os(OpenBSD) - import Glibc - fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM) - fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) - fileprivate let INADDR_ANY: in_addr_t = 0 --#if os(OpenBSD) - fileprivate let INADDR_LOOPBACK = 0x7f000001 - #endif -+ -+#if canImport(Android) -+import Android -+fileprivate let FOUNDATION_SOCK_STREAM = Int32(Android.SOCK_STREAM) -+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(Android.IPPROTO_TCP) -+fileprivate let INADDR_ANY: in_addr_t = 0 - #endif - - -diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift -index ee35c23a..5e8cfbaa 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Process.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift -@@ -18,6 +18,8 @@ import struct WinSDK.HANDLE - - #if canImport(Darwin) - import Darwin -+#elseif canImport(Android) -+import Android - #endif - - internal import Synchronization -diff --git a/swift-corelibs-foundation/Sources/Foundation/Thread.swift b/swift-corelibs-foundation/Sources/Foundation/Thread.swift -index 5e79579c..0985a482 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Thread.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Thread.swift -@@ -17,6 +17,8 @@ import WinSDK - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Bionic) -+import Bionic - #endif - - // WORKAROUND_SR9811 -diff --git a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift -index e0d1cbbd..237c1daf 100644 ---- a/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift -+++ b/swift-corelibs-foundation/Sources/FoundationNetworking/HTTPCookie.swift -@@ -15,6 +15,8 @@ import Foundation - - #if os(Windows) - import WinSDK -+#elseif canImport(Android) -+import Android - #endif - - public struct HTTPCookiePropertyKey : RawRepresentable, Equatable, Hashable, Sendable { -diff --git a/swift-corelibs-foundation/Sources/plutil/main.swift b/swift-corelibs-foundation/Sources/plutil/main.swift -index 29316d16..29584596 100644 ---- a/swift-corelibs-foundation/Sources/plutil/main.swift -+++ b/swift-corelibs-foundation/Sources/plutil/main.swift -@@ -15,6 +15,9 @@ import Glibc - #elseif canImport(Musl) - import Foundation - import Musl -+#elseif canImport(Bionic) -+import Foundation -+import Bionic - #elseif canImport(CRT) - import Foundation - import CRT -diff --git a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift -index d515a63f..fb037e24 100644 ---- a/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift -+++ b/swift-corelibs-foundation/Sources/xdgTestHelper/main.swift -@@ -19,6 +19,8 @@ import FoundationNetworking - #endif - #if os(Windows) - import WinSDK -+#elseif canImport(Android) -+import Android - #endif - - enum HelperCheckStatus : Int32 { -diff --git a/swift-corelibs-foundation/Package.swift b/swift-corelibs-foundation/Package.swift ---- a/swift-corelibs-foundation/Package.swift -+++ b/swift-corelibs-foundation/Package.swift -@@ -176,7 +176,8 @@ - "BlockRuntime", - "CMakeLists.txt" - ], -- cSettings: coreFoundationBuildSettings -+ cSettings: coreFoundationBuildSettings, -+ linkerSettings: [.linkedLibrary("log", .when(platforms: [.android]))] - ), - .target( - name: "_CFXMLInterface", -diff --git a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift ---- a/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/NSPathUtilities.swift -@@ -19,6 +19,8 @@ - get { WASILibc.errno } - set { WASILibc.errno = newValue } - } -+#elseif os(Android) -+import Android - #endif - - #if os(Windows) diff --git a/swift-corelibs-foundation/Sources/Foundation/Process.swift b/swift-corelibs-foundation/Sources/Foundation/Process.swift index 758dd1df..02970992 100644 --- a/swift-corelibs-foundation/Sources/Foundation/Process.swift +++ b/swift-corelibs-foundation/Sources/Foundation/Process.swift -@@ -927,8 +927,8 @@ open class Process: NSObject, @unchecked Sendable { +@@ -929,8 +929,8 @@ open class Process: NSObject, @unchecked Sendable { } let useFallbackChdir: Bool if let dir = currentDirectoryURL?.path { - let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir) - useFallbackChdir = chdirResult == ENOSYS -+ // let chdirResult = _CFPosixSpawnFileActionsChdir(fileActions, dir) -+ useFallbackChdir = true ; let chdirResult = ENOSYS ++ let chdirResult = ENOSYS ++ useFallbackChdir = true if !useFallbackChdir { try _throwIfPosixError(chdirResult) } +@@ -943,13 +943,13 @@ open class Process: NSObject, @unchecked Sendable { + #else + var spawnAttrs: posix_spawnattr_t = posix_spawnattr_t() + #endif +-#if os(Android) ++/*#if os(Android) + guard var spawnAttrs else { + throw NSError(domain: NSPOSIXErrorDomain, code: Int(errno), userInfo: [ + NSURLErrorKey:self.executableURL! + ]) + } +-#endif ++#endif*/ + try _throwIfPosixError(posix_spawnattr_init(&spawnAttrs)) + try _throwIfPosixError(posix_spawnattr_setflags(&spawnAttrs, .init(POSIX_SPAWN_SETPGROUP))) + #if canImport(Darwin) diff --git a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift index f1cb26d..44600dd 100644 --- a/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift +++ b/swift-foundation/Sources/FoundationEssentials/String/String+Path.swift -@@ -511,7 +511,7 @@ extension String { +@@ -467,7 +467,7 @@ extension String { return envVar.standardizingPath } - #if !os(WASI) // WASI does not have user concept + #if !os(WASI) && !canImport(Android) // WASI does not have user concept - // Next, attempt to find the home directory via getpwnam/getpwuid - var pass: UnsafeMutablePointer? - if let user { -@@ -528,7 +528,7 @@ extension String { - #endif // !os(WASI) - - // Fallback to HOME for the current user if possible -- if user == nil, let home = getenv("HOME") { -+ if let home = getenv("HOME") { - return String(cString: home).standardizingPath - } - + // Next, attempt to find the home directory via getpwuid + // We use the real UID instead of the EUID here when the EUID is the root user (i.e. a process has called seteuid(0)) + // In this instance, we historically do this to ensure a stable home directory location for processes that call seteuid(0) diff --git a/swift-foundation-icu/icuSources/CMakeLists.txt b/swift-foundation-icu/icuSources/CMakeLists.txt index fde8755..343f3b4 100644 --- a/swift-foundation-icu/icuSources/CMakeLists.txt @@ -421,91 +67,3 @@ index fde8755..343f3b4 100644 add_subdirectory(common) add_subdirectory(i18n) add_subdirectory(io) -From ab001004196b249af359d6152e5c2d06c11bee56 -From: Alex Lorenz -Date: Tue, 29 Oct 2024 13:00:11 -0700 -Subject: [PATCH] [android] fix the android build (#999) - -Platform.swift regressed after 71eefee7fca08ecbeacc89098b74ab80319baa6b ---- - -diff --git a/swift-foundation/Sources/FoundationEssentials/Platform.swift b/swift-foundation/Sources/FoundationEssentials/Platform.swift -index d8b8fe6f..15a1362f 100644 ---- a/swift-foundation/Sources/FoundationEssentials/Platform.swift -+++ b/swift-foundation/Sources/FoundationEssentials/Platform.swift -@@ -29,8 +29,7 @@ fileprivate let _pageSize: Int = { - // WebAssembly defines a fixed page size - fileprivate let _pageSize: Int = 65_536 - #elseif os(Android) --import Bionic --import unistd -+import Android - fileprivate let _pageSize: Int = Int(getpagesize()) - #elseif canImport(Glibc) - import Glibc -@@ -142,7 +141,7 @@ extension Platform { - typealias Operation = (Input, UnsafeMutablePointer, UnsafeMutablePointer, Int, UnsafeMutablePointer?>) -> Int32 - #endif - -- private static func withUserGroupBuffer(_ input: Input, _ output: Output, sizeProperty: Int32, operation: Operation, block: (Output) throws -> R) rethrows -> R? { -+ private static func withUserGroupBuffer(_ input: Input, _ output: Output, sizeProperty: Int32, operation: Operation, block: (Output) throws -> R?) rethrows -> R? { - var bufferLen = sysconf(sizeProperty) - if bufferLen == -1 { - bufferLen = 4096 // Generous default size estimate -@@ -172,31 +171,51 @@ extension Platform { - - static func name(forUID uid: uid_t) -> String? { - withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) { -- String(cString: $0.pw_name) -+ // Android's pw_name `char *`` is nullable when it should be non-null. -+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed. -+ let pw_name: UnsafeMutablePointer? = $0.pw_name -+ return pw_name.flatMap { String(cString: $0) } - } - } - - static func fullName(forUID uid: uid_t) -> String? { - withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) { -- String(cString: $0.pw_gecos) -+#if os(Android) && _pointerBitWidth(_32) -+ // pw_gecos isn't available on 32-bit Android. -+ let pw_gecos: UnsafeMutablePointer? = nil -+#else -+ // Android's pw_gecos `char *`` is nullable, so always coerce to a nullable pointer -+ // in order to be compatible with Android. -+ let pw_gecos: UnsafeMutablePointer? = $0.pw_gecos -+#endif -+ return pw_gecos.flatMap { String(cString: $0) } - } - } - - static func name(forGID gid: gid_t) -> String? { - withUserGroupBuffer(gid, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrgid_r) { -- String(cString: $0.gr_name) -+ // Android's gr_name `char *`` is nullable when it should be non-null. -+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed. -+ let gr_name: UnsafeMutablePointer? = $0.gr_name -+ return gr_name.flatMap { String(cString: $0) } - } - } - - static func homeDirectory(forUserName userName: String) -> String? { - withUserGroupBuffer(userName, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwnam_r) { -- String(cString: $0.pw_dir) -+ // Android's pw_dir `char *`` is nullable when it should be non-null. -+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed. -+ let pw_dir: UnsafeMutablePointer? = $0.pw_dir -+ return pw_dir.flatMap { String(cString: $0) } - } - } - - static func homeDirectory(forUID uid: uid_t) -> String? { - withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) { -- String(cString: $0.pw_dir) -+ // Android's pw_dir `char *`` is nullable when it should be non-null. -+ // FIXME: avoid the coerce cast workaround once https://github.com/android/ndk/issues/2098 is fixed. -+ let pw_dir: UnsafeMutablePointer? = $0.pw_dir -+ return pw_dir.flatMap { String(cString: $0) } - } - } - } diff --git a/packages/swift/swift-import-android.patch b/packages/swift/swift-import-android.patch index a5e757c3a0ae0be..b696c5821f6616a 100644 --- a/packages/swift/swift-import-android.patch +++ b/packages/swift/swift-import-android.patch @@ -1,52 +1,3 @@ -diff --git a/llbuild/products/llbuildSwift/BuildSystemBindings.swift b/llbuild/products/llbuildSwift/BuildSystemBindings.swift -index 6962fff5..8f1bf502 100644 ---- a/llbuild/products/llbuildSwift/BuildSystemBindings.swift -+++ b/llbuild/products/llbuildSwift/BuildSystemBindings.swift -@@ -17,8 +17,8 @@ import WinSDK - import Glibc - #elseif canImport(Musl) - import Musl --#elseif canImport(Bionic) --import Bionic -+#elseif canImport(Android) -+import Android - #else - #error("Missing libc or equivalent") - #endif -@@ -1293,7 +1293,7 @@ public final class BuildSystem { - #elseif os(Windows) - info.pointee.mod_time.seconds = UInt64(s.st_mtime) - info.pointee.mod_time.nanoseconds = 0 -- #elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic) -+ #elseif canImport(Glibc) || canImport(Musl) || canImport(Android) - info.pointee.mod_time.seconds = UInt64(s.st_mtim.tv_sec) - info.pointee.mod_time.nanoseconds = UInt64(s.st_mtim.tv_nsec) - #else -diff --git a/sourcekit-lsp/Sources/SKSupport/Process+Run.swift b/sourcekit-lsp/Sources/SKSupport/Process+Run.swift ---- a/sourcekit-lsp/Sources/SKSupport/Process+Run.swift -+++ b/sourcekit-lsp/Sources/SKSupport/Process+Run.swift -@@ -22,6 +22,8 @@ - - #if os(Windows) - import WinSDK -+#elseif canImport(Android) -+import Android - #endif - - extension Process { -diff --git a/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift b/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift ---- a/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift -+++ b/sourcekit-lsp/Sources/sourcekit-lsp/SourceKitLSP.swift -@@ -28,6 +28,9 @@ - import struct TSCBasic.AbsolutePath - import struct TSCBasic.RelativePath - import var TSCBasic.localFileSystem -+#if canImport(Android) -+import Android -+#endif - - extension AbsolutePath { - public init?(argument: String) { diff --git a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift b/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift index b7fa046..a94e3b8 100644 --- a/swift-argument-parser/Sources/ArgumentParser/Utilities/Platform.swift @@ -171,96 +122,3 @@ index 555f63b..f0db35f 100644 #else #error("Unsupported Platform") #endif -diff --git a/swiftpm/Sources/Basics/AsyncProcess.swift b/swiftpm/Sources/Basics/AsyncProcess.swift ---- a/swiftpm/Sources/Basics/AsyncProcess.swift -+++ b/swiftpm/Sources/Basics/AsyncProcess.swift -@@ -14,6 +14,8 @@ - - #if os(Windows) - import TSCLibc -+#elseif canImport(Android) -+import Android - #endif - - #if os(Linux) -diff --git a/swiftpm/Sources/Basics/Cancellator.swift b/swiftpm/Sources/Basics/Cancellator.swift ---- a/swiftpm/Sources/Basics/Cancellator.swift -+++ b/swiftpm/Sources/Basics/Cancellator.swift -@@ -15,6 +15,8 @@ - import class TSCBasic.Thread - #if canImport(WinSDK) - import WinSDK -+#elseif canImport(Android) -+import Android - #endif - - public typealias CancellationHandler = @Sendable (DispatchTime) throws -> Void -diff --git a/swiftpm/Sources/Basics/Environment/Environment.swift b/swiftpm/Sources/Basics/Environment/Environment.swift ---- a/swiftpm/Sources/Basics/Environment/Environment.swift -+++ b/swiftpm/Sources/Basics/Environment/Environment.swift -@@ -19,8 +19,8 @@ - #elseif os(Windows) - import CRT - import WinSDK --#elseif canImport(Bionic) --import Bionic -+#elseif canImport(Android) -+import Android - #else - import Darwin.C - #endif -diff --git a/swiftpm/Sources/Commands/SwiftRunCommand.swift b/swiftpm/Sources/Commands/SwiftRunCommand.swift ---- a/swiftpm/Sources/Commands/SwiftRunCommand.swift -+++ b/swiftpm/Sources/Commands/SwiftRunCommand.swift -@@ -9,6 +9,9 @@ - // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors - // - //===----------------------------------------------------------------------===// -+#if canImport(Android) -+import Android -+#endif - - import ArgumentParser - import Basics -diff --git a/swiftpm/Sources/PackagePlugin/Plugin.swift b/swiftpm/Sources/PackagePlugin/Plugin.swift ---- a/swiftpm/Sources/PackagePlugin/Plugin.swift -+++ b/swiftpm/Sources/PackagePlugin/Plugin.swift -@@ -36,6 +36,8 @@ - return String(decodingCString: baseAddress, as: UTF16.self) - } - } -+#elseif canImport(Android) -+import Android - #endif - - // -diff --git a/swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift b/swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift -index 41df217ce..cb56fb5c3 100644 ---- a/swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift -+++ b/swiftpm/Sources/PackageRegistryCommand/PackageRegistryCommand+Auth.swift -@@ -63,6 +63,10 @@ private func readpassword(_ prompt: String) throws -> String { - return password - } - #else -+#if canImport(Android) -+import Android -+#endif -+ - private func readpassword(_ prompt: String) throws -> String { - let password: String - -diff --git a/yams/Sources/Yams/Representer.swift b/yams/Sources/Yams/Representer.swift -index a749c52..b74ef8e 100644 ---- a/yams/Sources/Yams/Representer.swift -+++ b/yams/Sources/Yams/Representer.swift -@@ -14,6 +14,10 @@ private let cpow: (_: Double, _: Double) -> Double = Darwin.pow - #elseif os(Windows) - import ucrt - private let cpow: (_: Double, _: Double) -> Double = ucrt.pow -+#elseif canImport(Bionic) -+import CoreFoundation -+import Bionic -+private let cpow: (_: Double, _: Double) -> Double = Bionic.pow - #else - import CoreFoundation - import Glibc diff --git a/packages/swift/swift-ndk27.patch b/packages/swift/swift-ndk27.patch deleted file mode 100644 index afb0189f1166ddf..000000000000000 --- a/packages/swift/swift-ndk27.patch +++ /dev/null @@ -1,62 +0,0 @@ -From c88b9401da550ed2958a0e92e6936120216784e2 -Date: Sat, 14 Sep 2024 01:27:49 +0530 -Subject: [PATCH] [android] Update to LTS NDK 27c - -Add a new bits/ header to the Android overlay, add runtime libraries that are -auto-extracted and listed many times to the list of libraries to be de-duplicated, -and update the doc with new libraries that need to be available to run a simple -executable. ---- - lib/DriverTool/autolink_extract_main.cpp | 3 +++ - stdlib/cmake/modules/AddSwiftStdlib.cmake | 2 +- - stdlib/public/Platform/android.modulemap | 8 ++++++++ - 4 files changed, 23 insertions(+), 10 deletions(-) - -diff --git a/swift/lib/DriverTool/autolink_extract_main.cpp b/swift/lib/DriverTool/autolink_extract_main.cpp -index 332778d581d95..79d63e6ea5d74 100644 ---- a/swift/lib/DriverTool/autolink_extract_main.cpp -+++ b/swift/lib/DriverTool/autolink_extract_main.cpp -@@ -231,8 +231,11 @@ int autolink_extract_main(ArrayRef Args, const char *Argv0, - "-lswiftRegexBuilder", - "-lswift_RegexParser", - "-lswift_Backtracing", -+ "-lswift_Builtin_float", -+ "-lswift_math", - "-lswiftSynchronization", - "-lswiftGlibc", -+ "-lswiftAndroid", - "-lBlocksRuntime", - // Dispatch-specific Swift runtime libs - "-ldispatch", -diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -index 3784880bc63ed..a3912568f95a7 100644 ---- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -+++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake -@@ -557,7 +557,7 @@ function(_add_target_variant_link_flags) - if(NOT CMAKE_HOST_SYSTEM MATCHES Windows) - # The Android resource dir is specified from build.ps1 on windows. - if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") -- if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26") -+ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "r26|r27") - file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*) - else() - file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*) -diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap -index a1a9010c4a042..76da5f6bd5e59 100644 ---- a/swift/stdlib/public/Platform/android.modulemap -+++ b/swift/stdlib/public/Platform/android.modulemap -@@ -556,6 +556,14 @@ module _bits_sa_family_t [system] { - header "bits/sa_family_t.h" - export * - } -+ -+module _bits_sockaddr_storage [system] { -+ // Note: this module is not part of 'sys_socket' -+ // to prevent a circular modular dependency -+ header "bits/sockaddr_storage.h" -+ export * -+} -+ - module _bits_stdatomic [system] { - // Note: this module is not part of 'stdatomic' - // as it depends on libc++ and forcing it to diff --git a/packages/swift/swift-remove-relative-rpaths.patch b/packages/swift/swift-remove-relative-rpaths.patch index 46398ce7deb5b04..73047aba33468dd 100644 --- a/packages/swift/swift-remove-relative-rpaths.patch +++ b/packages/swift/swift-remove-relative-rpaths.patch @@ -24,6 +24,19 @@ index ee668f96903..61397d3910e 100644 ) # 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/lib/CompilerSwiftSyntax/CMakeLists.txt b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt +index 849cf90fee0..b1f8d66be18 100644 +--- a/swift/lib/CompilerSwiftSyntax/CMakeLists.txt ++++ b/swift/lib/CompilerSwiftSyntax/CMakeLists.txt +@@ -13,7 +13,7 @@ function(includeSwiftSyntax) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}/compiler") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${SWIFT_HOST_LIBRARIES_DEST_DIR}/compiler") + 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) diff --git a/swift/lib/SwiftSyntax/CMakeLists.txt b/swift/lib/SwiftSyntax/CMakeLists.txt index b39061073c9..a295f397d72 100644 --- a/swift/lib/SwiftSyntax/CMakeLists.txt diff --git a/packages/swift/swift-syntax.patch b/packages/swift/swift-syntax.patch deleted file mode 100644 index f131bd5c3634348..000000000000000 --- a/packages/swift/swift-syntax.patch +++ /dev/null @@ -1,77 +0,0 @@ -commit 031e9eddc214ac4b4b34e88013dc8fe2e6c150c2 -Date: Tue Aug 6 13:52:27 2024 +0530 - - [Android] Use the new overlay and Bionic module from Swift 6 - - The new overlay was merged into Swift 6 in swiftlang/swift#74758. - -diff --git a/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift b/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -index eb06cca2..44be07e2 100644 ---- a/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -+++ b/swift-syntax/Sources/SwiftLibraryPluginProvider/LibraryPluginProvider.swift -@@ -22,6 +22,8 @@ private import Darwin - private import Glibc - #elseif canImport(Musl) - private import Musl -+#elseif canImport(Android) -+private import Android - #endif - #else - import SwiftSyntaxMacros -@@ -137,7 +139,7 @@ private func _loadLibrary(_ path: String) throws -> UnsafeMutableRawPointer { - #else - private func _loadLibrary(_ path: String) throws -> UnsafeMutableRawPointer { - guard let dlHandle = dlopen(path, RTLD_LAZY | RTLD_LOCAL) else { -- throw LibraryPluginError(message: "loader error: \(String(cString: dlerror()))") -+ throw LibraryPluginError(message: "loader error: \(String(cString: dlerror()!))") - } - return dlHandle - } -diff --git a/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift b/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -index 574a67fc..4d877962 100644 ---- a/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -+++ b/swift-syntax/Sources/SwiftSyntax/SyntaxText.swift -@@ -15,6 +15,8 @@ - private import Darwin - #elseif canImport(Glibc) - private import Glibc -+#elseif canImport(Bionic) -+private import Bionic - #elseif canImport(Musl) - private import Musl - #endif -@@ -281,6 +283,8 @@ private func compareMemory( - return Darwin.memcmp(s1, s2, count) == 0 - #elseif canImport(Glibc) - return Glibc.memcmp(s1, s2, count) == 0 -+ #elseif canImport(Bionic) -+ return Bionic.memcmp(s1, s2, count) == 0 - #else - return UnsafeBufferPointer(start: s1, count: count) - .elementsEqual(UnsafeBufferPointer(start: s2, count: count)) -diff --git a/swift-syntax/SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift b/swift-syntax/SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift -index cb905a27..841e529b 100644 ---- a/swift-syntax/SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift -+++ b/swift-syntax/SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift -@@ -14,6 +14,8 @@ - import Glibc - #elseif canImport(Musl) - import Musl -+#elseif canImport(Android) -+import Android - #elseif os(Windows) - import CRT - #else -diff --git a/swift-syntax/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/ProcessRunner.swift b/swift-syntax/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/ProcessRunner.swift -index 526f4a2f..e88611cb 100644 ---- a/swift-syntax/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/ProcessRunner.swift -+++ b/swift-syntax/SwiftSyntaxDevUtils/Sources/swift-syntax-dev-utils/common/ProcessRunner.swift -@@ -24,7 +24,7 @@ class SigIntListener { - /// Registers a `SIGINT` signal handler that forwards `SIGINT` to all - /// subprocesses that are registered in `runningSubprocesses` - static func registerSigIntSubprocessTerminationHandler() { -- #if canImport(Darwin) || canImport(Glibc) -+ #if canImport(Darwin) || canImport(Glibc) || canImport(Bionic) - signal(SIGINT) { _ in - SigIntListener.hasReceivedSigInt = true - for process in SigIntListener.runningSubprocesses { diff --git a/packages/swift/swift-utils-build-script-impl-flags.patch b/packages/swift/swift-utils-build-script-impl-flags.patch index 9b8c4cc457cf120..44f24ecd8601a4a 100644 --- a/packages/swift/swift-utils-build-script-impl-flags.patch +++ b/packages/swift/swift-utils-build-script-impl-flags.patch @@ -10,11 +10,12 @@ index b1d060328bc..218c9215260 100755 if [[ ! "${SKIP_BUILD_ANDROID}" ]] || [[ $(is_cross_tools_host ${host}) && "${host}" == "android-"* ]]; then cmake_options=( -@@ -1733,6 +1734,7 @@ +@@ -1733,6 +1734,8 @@ -DSWIFT_ANDROID_DEPLOY_DEVICE_PATH:STRING="${ANDROID_DEPLOY_DEVICE_PATH}" -DSWIFT_SDK_ANDROID_ARCHITECTURES:STRING="${ANDROID_ARCH}" ) + cross_c_flags="$CFLAGS --target=$CCTERMUX_HOST_PLATFORM" ++ call ln -sf "$(build_directory ${host} swift)/lib/swift" "${ANDROID_NDK}/sysroot/usr/lib" fi if [[ ! "${SKIP_BUILD_WASM}" ]]; then @@ -121,7 +122,7 @@ index b1d060328bc..218c9215260 100755 if [[ -z "${INSTALL_LLBUILD}" ]] ; then continue fi -- INSTALL_TARGETS="install-swift-build-tool install-libllbuildSwift" +- INSTALL_TARGETS="install-swift-build-tool" + INSTALL_TARGETS="" + # Use the system libdispatch headers instead. + sed -i -e "s%dispatch\.h%@TERMUX_PREFIX@/include/dispatch/dispatch.h%" \ diff --git a/packages/swift/swiftpm-sqlite-dependency.patch b/packages/swift/swiftpm-sqlite-dependency.patch deleted file mode 100644 index 34df170f0c634a5..000000000000000 --- a/packages/swift/swiftpm-sqlite-dependency.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/sourcekit-lsp/Utilities/build-script-helper.py b/sourcekit-lsp/Utilities/build-script-helper.py -index 17ad9e3..953fffd 100755 ---- a/sourcekit-lsp/Utilities/build-script-helper.py -+++ b/sourcekit-lsp/Utilities/build-script-helper.py -@@ -142,6 +142,7 @@ def get_swiftpm_options(swift_exec: str, args: argparse.Namespace) -> List[str]: - elif re.match('android-', args.cross_compile_host): - print('Cross-compiling for %s' % args.cross_compile_host) - swiftpm_args += ['--destination', args.cross_compile_config] -+ swiftpm_args += ['--pkg-config-path', os.path.join(os.path.split(args.cross_compile_config)[0], 'lib/pkgconfig')] - else: - fatal_error("cannot cross-compile for %s" % args.cross_compile_host) - -diff --git a/swiftpm/Utilities/bootstrap b/swiftpm/Utilities/bootstrap -index 085056de..1ded1a90 100755 ---- a/swiftpm/Utilities/bootstrap -+++ b/swiftpm/Utilities/bootstrap -@@ -834,6 +834,7 @@ def get_swiftpm_flags(args): - build_flags += ["--arch", "x86_64", "--arch", "arm64"] - elif cross_compile_hosts.startswith('android-'): - build_flags.extend(["--destination", args.cross_compile_config]) -+ build_flags.extend(["--pkg-config-path", os.path.join(os.path.split(args.cross_compile_config)[0], "lib/pkgconfig")]) - else: - error("cannot cross-compile for %s" % cross_compile_hosts) - diff --git a/scripts/build/setup/termux_setup_swift.sh b/scripts/build/setup/termux_setup_swift.sh index ad3a80c7a9b118f..dfa7bca5a806cb2 100644 --- a/scripts/build/setup/termux_setup_swift.sh +++ b/scripts/build/setup/termux_setup_swift.sh @@ -18,7 +18,7 @@ termux_setup_swift() { termux_download \ https://download.swift.org/development/ubuntu2404/swift-$SWIFT_RELEASE/$SWIFT_BIN.tar.gz \ $SWIFT_TAR \ - 33e923609f6d89ee455af0a017ae4941ce16878c4940882cbf6a1656de294e8b + 1876c31983f7cae0f0410d0b5b4060712ef71d50f7c627c7b06c7c844cbd767d (cd $TERMUX_PKG_TMPDIR ; tar xf $SWIFT_TAR ; mv $SWIFT_BIN $SWIFT_FOLDER; rm $SWIFT_TAR) fi