diff --git a/.github/workflows/sdks.yml b/.github/workflows/sdks.yml index af2688d..4ed3d6d 100644 --- a/.github/workflows/sdks.yml +++ b/.github/workflows/sdks.yml @@ -110,26 +110,21 @@ jobs: tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz ./$SWIFT_TAG-ubuntu22.04/usr/bin/swift --version git apply swift-android-ci.patch - git apply -C1 swift-android.patch swift-android-both-ndks.patch + git apply -C1 swift-android.patch + git apply -C0 swift-android-foundation-ndk26.patch if [[ ${{ matrix.version }} = 'release' ]]; then sed -i "s%strsignal(signal).map%String(cString: strsignal(signal)) //%" swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift - git apply swift-android-stdlib-except-trunk.patch + git apply swift-android-release-stdlib.patch STUPID_FILE_RENAMING=Tool else sed -i "s%r26%ndk/27%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake - STUPID_FILE_RENAMING=Command - fi - - git apply -C0 swift-android-foundation-ndk26.patch - if [ ${{ matrix.version }} = 'release' ]; then - git apply swift-android-stdlib-ndk26.patch - else if [ ${{ matrix.version }} = 'devel' ]; then git apply android-overlay/import-android-devel.patch else git apply swift-android-foundation-trunk.patch fi git apply android-overlay/foundation-fixes.patch android-overlay/swift-argument-parser.patch android-overlay/swift-stdlib-modulemap.patch android-overlay/swift-system.patch android-overlay/yams.patch + STUPID_FILE_RENAMING=Command fi sed -i "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc diff --git a/swift-android-both-ndks.patch b/swift-android-both-ndks.patch deleted file mode 100644 index b24737f..0000000 --- a/swift-android-both-ndks.patch +++ /dev/null @@ -1,119 +0,0 @@ -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -index a538a297..0a757c4b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift -@@ -310,9 +310,15 @@ open class FileHandle : NSObject { - let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0) - // Swift does not currently expose MAP_FAILURE - if data != UnsafeMutableRawPointer(bitPattern: -1) { -+ #if os(Android) -+ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in -+ munmap(buffer, length) -+ } -+ #else - return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in - munmap(buffer, length) - } -+ #endif - } - } - -diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -index d90ece91..d2bbd22b 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift -@@ -741,13 +741,13 @@ extension FileManager { - ps.deinitialize(count: 2) - ps.deallocate() - -- if stream != nil { -+ if let openStream = stream { - defer { -- fts_close(stream) -+ fts_close(openStream) - } - -- while let current = fts_read(stream)?.pointee { -- let itemPath = string(withFileSystemRepresentation: current.fts_path, length: Int(current.fts_pathlen)) -+ while let current = fts_read(openStream)?.pointee, let current_path = current.fts_path { -+ let itemPath = string(withFileSystemRepresentation: current_path, length: Int(current.fts_pathlen)) - guard alreadyConfirmed || shouldRemoveItemAtPath(itemPath, isURL: isURL) else { - continue - } -@@ -762,11 +768,11 @@ extension FileManager { - do { - switch Int32(current.fts_info) { - case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE: -- if unlink(current.fts_path) == -1 { -+ if unlink(current_path) == -1 { - throw _NSErrorWithErrno(errno, reading: false, path: itemPath) - } - case FTS_DP: -- if rmdir(current.fts_path) == -1 { -+ if rmdir(current_path) == -1 { - throw _NSErrorWithErrno(errno, reading: false, path: itemPath) - } - case FTS_DNR, FTS_ERR, FTS_NS: -@@ -1135,14 +1149,14 @@ 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)) -+ while let current = _current, let current_path = current.pointee.fts_path { -+ let filename = FileManager.default.string(withFileSystemRepresentation: current_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) -@@ -1315,7 +1329,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 let newFS = newItemFS, let origFS = originalFS, rename(newFS, origFS) == 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 1aa3038a..9fdb495c 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift -@@ -568,13 +568,13 @@ open class FileManager : NSObject { - let attributes = try windowsFileAttributes(atPath: path) - let type = FileAttributeType(attributes: attributes, atPath: path) - #else -- if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil { -- let name = String(cString: pwd.pointee.pw_name) -+ if let pwd = getpwuid(s.st_uid), let pwd_name = pwd.pointee.pw_name { -+ let name = String(cString: pwd_name) - result[.ownerAccountName] = name - } - -- if let grd = getgrgid(s.st_gid), grd.pointee.gr_name != nil { -- let name = String(cString: grd.pointee.gr_name) -+ if let grd = getgrgid(s.st_gid), let grd_name = grd.pointee.gr_name { -+ let name = String(cString: grd_name) - result[.groupOwnerAccountName] = name - } - -diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift -index 5fe7b29c..ce571abe 100644 ---- a/swift-corelibs-foundation/Sources/Foundation/Host.swift -+++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift -@@ -25,7 +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) -+ guard let saddr = addr else { return -1 } -+ return Glibc.getnameinfo(saddr, 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-android-foundation-ndk26.patch b/swift-android-foundation-ndk26.patch index de99aa1..7dac565 100644 --- a/swift-android-foundation-ndk26.patch +++ b/swift-android-foundation-ndk26.patch @@ -37,3 +37,122 @@ index d90ece91..d2bbd22b 100644 return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) } if _stream == nil { +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift +index a538a297..0a757c4b 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileHandle.swift +@@ -310,9 +310,15 @@ open class FileHandle : NSObject { + let data = mmap(nil, mapSize, PROT_READ, MAP_PRIVATE, _fd, 0) + // Swift does not currently expose MAP_FAILURE + if data != UnsafeMutableRawPointer(bitPattern: -1) { ++ #if os(Android) ++ return NSData.NSDataReadResult(bytes: data, length: mapSize) { buffer, length in ++ munmap(buffer, length) ++ } ++ #else + return NSData.NSDataReadResult(bytes: data!, length: mapSize) { buffer, length in + munmap(buffer, length) + } ++ #endif + } + } + +diff --git a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +index d90ece91..d2bbd22b 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileManager+POSIX.swift +@@ -741,13 +741,13 @@ extension FileManager { + ps.deinitialize(count: 2) + ps.deallocate() + +- if stream != nil { ++ if let openStream = stream { + defer { +- fts_close(stream) ++ fts_close(openStream) + } + +- while let current = fts_read(stream)?.pointee { +- let itemPath = string(withFileSystemRepresentation: current.fts_path, length: Int(current.fts_pathlen)) ++ while let current = fts_read(openStream)?.pointee, let current_path = current.fts_path { ++ let itemPath = string(withFileSystemRepresentation: current_path, length: Int(current.fts_pathlen)) + guard alreadyConfirmed || shouldRemoveItemAtPath(itemPath, isURL: isURL) else { + continue + } +@@ -762,11 +768,11 @@ extension FileManager { + do { + switch Int32(current.fts_info) { + case FTS_DEFAULT, FTS_F, FTS_NSOK, FTS_SL, FTS_SLNONE: +- if unlink(current.fts_path) == -1 { ++ if unlink(current_path) == -1 { + throw _NSErrorWithErrno(errno, reading: false, path: itemPath) + } + case FTS_DP: +- if rmdir(current.fts_path) == -1 { ++ if rmdir(current_path) == -1 { + throw _NSErrorWithErrno(errno, reading: false, path: itemPath) + } + case FTS_DNR, FTS_ERR, FTS_NS: +@@ -1135,14 +1149,14 @@ 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)) ++ while let current = _current, let current_path = current.pointee.fts_path { ++ let filename = FileManager.default.string(withFileSystemRepresentation: current_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) +@@ -1315,7 +1329,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 let newFS = newItemFS, let origFS = originalFS, rename(newFS, origFS) == 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 1aa3038a..9fdb495c 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/FileManager.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/FileManager.swift +@@ -568,13 +568,13 @@ open class FileManager : NSObject { + let attributes = try windowsFileAttributes(atPath: path) + let type = FileAttributeType(attributes: attributes, atPath: path) + #else +- if let pwd = getpwuid(s.st_uid), pwd.pointee.pw_name != nil { +- let name = String(cString: pwd.pointee.pw_name) ++ if let pwd = getpwuid(s.st_uid), let pwd_name = pwd.pointee.pw_name { ++ let name = String(cString: pwd_name) + result[.ownerAccountName] = name + } + +- if let grd = getgrgid(s.st_gid), grd.pointee.gr_name != nil { +- let name = String(cString: grd.pointee.gr_name) ++ if let grd = getgrgid(s.st_gid), let grd_name = grd.pointee.gr_name { ++ let name = String(cString: grd_name) + result[.groupOwnerAccountName] = name + } + +diff --git a/swift-corelibs-foundation/Sources/Foundation/Host.swift b/swift-corelibs-foundation/Sources/Foundation/Host.swift +index 5fe7b29c..ce571abe 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Host.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Host.swift +@@ -25,7 +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) ++ guard let saddr = addr else { return -1 } ++ return Glibc.getnameinfo(saddr, 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-android-stdlib-except-trunk.patch b/swift-android-release-stdlib.patch similarity index 67% rename from swift-android-stdlib-except-trunk.patch rename to swift-android-release-stdlib.patch index 63fe2f9..cec746c 100644 --- a/swift-android-stdlib-except-trunk.patch +++ b/swift-android-release-stdlib.patch @@ -28,3 +28,16 @@ index f8daa50325c..66be85a77f0 100644 #else return pipe(unsafeFds.baseAddress) #endif +diff --git a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h +index 1e4132f6279..045b8a28746 100644 +--- a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h ++++ b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h +@@ -61,7 +61,7 @@ SWIFT_READONLY + static inline int _swift_stdlib_memcmp(const void *s1, const void *s2, + __swift_size_t n) { + // FIXME: Is there a way to identify Glibc specifically? +-#if defined(__gnu_linux__) ++#if defined(__gnu_linux__) || defined(__ANDROID__) + extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t); + #else + extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t); diff --git a/swift-android-stdlib-ndk26.patch b/swift-android-stdlib-ndk26.patch deleted file mode 100644 index f0d0d2c..0000000 --- a/swift-android-stdlib-ndk26.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -index 1e4132f6279..045b8a28746 100644 ---- a/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -+++ b/swift/stdlib/public/SwiftShims/swift/shims/LibcShims.h -@@ -61,7 +61,7 @@ SWIFT_READONLY - static inline int _swift_stdlib_memcmp(const void *s1, const void *s2, - __swift_size_t n) { - // FIXME: Is there a way to identify Glibc specifically? --#if defined(__gnu_linux__) -+#if defined(__gnu_linux__) || defined(__ANDROID__) - extern int memcmp(const void * _Nonnull, const void * _Nonnull, __swift_size_t); - #else - extern int memcmp(const void * _Null_unspecified, const void * _Null_unspecified, __swift_size_t); diff --git a/swift-android.patch b/swift-android.patch index 8f91de5..830f565 100644 --- a/swift-android.patch +++ b/swift-android.patch @@ -1,4 +1,3 @@ - diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py index 9932b854cb6..ad3ac757665 100644 --- a/swift/utils/swift_build_support/swift_build_support/targets.py