From e75ccfe42730050b66b51e9ad1c26ebf8f27b3aa Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Thu, 21 Sep 2023 19:09:48 +0530 Subject: [PATCH] Patch and build against LTS NDK 26b also on CI --- .github/workflows/sdks.yml | 57 ++++--- swift-android-arm.patch | 16 ++ swift-android-both-ndks.patch | 252 +++++++++++++++++++++++++++++++ swift-android-ndk26.patch | 52 +++++++ swift-android.patch | 16 -- swift-nio-force-unwrap.patch | 57 +++++++ swift-nio-ndk26.patch | 123 +++++++++++++++ swift-nio-ssh-ndk26.patch | 13 ++ swift-nio-ssl-force-unwrap.patch | 13 ++ swift-nio-ssl-ndk26.patch | 31 ++++ swift-system-ndk26.patch | 22 +++ 11 files changed, 619 insertions(+), 33 deletions(-) create mode 100644 swift-android-arm.patch create mode 100644 swift-android-both-ndks.patch create mode 100644 swift-android-ndk26.patch create mode 100644 swift-nio-force-unwrap.patch create mode 100644 swift-nio-ndk26.patch create mode 100644 swift-nio-ssh-ndk26.patch create mode 100644 swift-nio-ssl-force-unwrap.patch create mode 100644 swift-nio-ssl-ndk26.patch create mode 100644 swift-system-ndk26.patch diff --git a/.github/workflows/sdks.yml b/.github/workflows/sdks.yml index 5cecba76..676e8646 100644 --- a/.github/workflows/sdks.yml +++ b/.github/workflows/sdks.yml @@ -59,6 +59,7 @@ jobs: matrix: version: [release, devel, trunk] arch: [aarch64, x86_64, armv7] + ndk: [25c, 26b] env: ANDROID_API_LEVEL: 24 steps: @@ -86,8 +87,8 @@ jobs: id: cache-sdk uses: actions/cache@v3 with: - path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}-*-sdk.tar.xz - key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-bump-sdk + path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}-*-ndk${{ matrix.ndk }}-sdk.tar.xz + key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-ndk${{ matrix.ndk }}-sdk - name: Clone uses: actions/checkout@v3 with: @@ -106,21 +107,30 @@ jobs: SDK=`pwd`/$SDK_NAME tar xf ~/$SWIFT_TAG-ubuntu22.04.tar.gz - git apply swift-android.patch swift-android-ci.patch + git apply swift-android.patch swift-android-ci.patch swift-android-both-ndks.patch + if [ ${{ matrix.version }} != 'release' ]; then + git apply swift-android-arm.patch + fi + if [ ${{ matrix.ndk }} = '26b' ]; then + NDK=$ANDROID_NDK_LATEST_HOME + git apply swift-android-ndk26.patch + else + NDK=$ANDROID_NDK + sed -i "s%#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include uc_mcontext.pc); + #elif defined(__arm__) ++#if defined(__ANDROID__) ++ pc = (void *)(ctx->uc_mcontext.arm_pc); ++#else + pc = (void *)(ctx->uc_mcontext.gprs[15]); ++#endif + #endif + + _swift_displayCrashMessage(signum, pc); diff --git a/swift-android-both-ndks.patch b/swift-android-both-ndks.patch new file mode 100644 index 00000000..04b86321 --- /dev/null +++ b/swift-android-both-ndks.patch @@ -0,0 +1,252 @@ +diff --git a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake +index 61447d50f08..b533b9291af 100644 +--- a/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake ++++ b/swift/stdlib/cmake/modules/AddSwiftStdlib.cmake +@@ -522,7 +522,11 @@ function(_add_target_variant_link_flags) + # We need to add the math library, which is linked implicitly by libc++ + list(APPEND result "-lm") + if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "") +- file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*) ++ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "ndk/26") ++ 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/*) ++ endif() + list(APPEND result "-resource-dir=${RESOURCE_DIR}") + endif() + +diff --git a/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift b/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift +index f8daa50325c..66be85a77f0 100644 +--- a/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift ++++ b/swift/stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift +@@ -131,6 +131,8 @@ public func _stdlib_pipe() -> (readEnd: CInt, writeEnd: CInt, error: CInt) { + return _pipe(unsafeFds.baseAddress, 0, 0) + #elseif os(WASI) + preconditionFailure("No pipes available on WebAssembly/WASI") ++#elseif os(Android) ++ return pipe(unsafeFds.baseAddress!) + #else + return pipe(unsafeFds.baseAddress) + #endif +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-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift +index 4d6577d0..aa22dade 100644 +--- a/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift ++++ b/swift-driver/Sources/SwiftDriver/Driver/ToolExecutionDelegate.swift +@@ -136,7 +136,7 @@ import var TSCBasic.stdoutStream + } + #else + case .signalled(let signal): +- let errorMessage = strsignal(signal).map { String(cString: $0) } ?? "" ++ let errorMessage = String(cString: strsignal(signal)) + messages = constructJobSignalledMessages(job: job, error: errorMessage, output: output, + signal: signal, pid: pid).map { + ParsableMessage(name: job.kind.rawValue, kind: .signalled($0)) +diff --git a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift +index b33b1c6..cd2ce5b 100644 +--- a/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift ++++ b/swift-tools-support-core/Sources/TSCBasic/FileSystem.swift +@@ -491,8 +491,8 @@ private struct LocalFileSystem: FileSystem { + + func readFileContents(_ path: AbsolutePath) throws -> ByteString { + // Open the file. +- let fp = fopen(path.pathString, "rb") +- if fp == nil { ++ let fpo = fopen(path.pathString, "rb") ++ guard let fp = fpo else { + throw FileSystemError(errno: errno, path) + } + defer { fclose(fp) } +@@ -521,8 +521,8 @@ private struct LocalFileSystem: FileSystem { + + func writeFileContents(_ path: AbsolutePath, bytes: ByteString) throws { + // Open the file. +- let fp = fopen(path.pathString, "wb") +- if fp == nil { ++ let fpo = fopen(path.pathString, "wb") ++ guard let fp = fpo else { + throw FileSystemError(errno: errno, path) + } + defer { fclose(fp) } +diff --git a/swift-tools-support-core/Sources/TSCBasic/Process.swift b/swift-tools-support-core/Sources/TSCBasic/Process.swift +index 6c8aa11..71d829c 100644 +--- a/swift-tools-support-core/Sources/TSCBasic/Process.swift ++++ b/swift-tools-support-core/Sources/TSCBasic/Process.swift +@@ -144,6 +144,9 @@ public final class Process { + + /// The current OS does not support the workingDirectory API. + case workingDirectoryNotSupported ++ ++ /// The stdin could not be opened. ++ case stdinNotOpening + } + + public enum OutputRedirection { +@@ -677,7 +680,10 @@ public final class Process { + var stdinPipe: [Int32] = [-1, -1] + try open(pipe: &stdinPipe) + +- let stdinStream = try LocalFileOutputByteStream(filePointer: fdopen(stdinPipe[1], "wb"), closeOnDeinit: true) ++ guard let fp = fdopen(stdinPipe[1], "wb") else { ++ throw Process.Error.stdinNotOpening ++ } ++ let stdinStream = try LocalFileOutputByteStream(filePointer: fp, closeOnDeinit: true) + + // Dupe the read portion of the remote to 0. + posix_spawn_file_actions_adddup2(&fileActions, stdinPipe[0], 0) +@@ -1258,6 +1264,8 @@ extension Process.Error: CustomStringConvertible { + return "could not find executable for '\(program)'" + case .workingDirectoryNotSupported: + return "workingDirectory is not supported in this platform" ++ case .stdinNotOpening: ++ return "could not open stdin on this platform" + } + } + } +diff --git a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift +index aee907e..2047d22 100644 +--- a/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift ++++ b/swift-tools-support-core/Sources/TSCBasic/WritableByteStream.swift +@@ -790,7 +790,11 @@ public final class LocalFileOutputByteStream: FileOutputByteStream { + override final func writeImpl(_ bytes: ArraySlice) { + bytes.withUnsafeBytes { bytesPtr in + while true { ++ #if os(Android) ++ let n = fwrite(bytesPtr.baseAddress!, 1, bytesPtr.count, filePointer) ++ #else + let n = fwrite(bytesPtr.baseAddress, 1, bytesPtr.count, filePointer) ++ #endif + if n < 0 { + if errno == EINTR { continue } + errorDetected(code: errno) +diff --git a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift +index 59610b6..2797c71 100644 +--- a/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift ++++ b/swift-tools-support-core/Sources/TSCTestSupport/PseudoTerminal.swift +@@ -24,7 +24,7 @@ public final class PseudoTerminal { + if openpty(&primary, &secondary, nil, nil, nil) != 0 { + return nil + } +- guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w"), closeOnDeinit: false) else { ++ guard let outStream = try? LocalFileOutputByteStream(filePointer: fdopen(secondary, "w")!, closeOnDeinit: false) else { + return nil + } + self.outStream = outStream diff --git a/swift-android-ndk26.patch b/swift-android-ndk26.patch new file mode 100644 index 00000000..1693456d --- /dev/null +++ b/swift-android-ndk26.patch @@ -0,0 +1,52 @@ +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-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,9 +741,15 @@ extension FileManager { + if rmdir(fsRep) == 0 { + return + } else if errno == ENOTEMPTY { ++ #if os(Android) ++ let ps = UnsafeMutablePointer>.allocate(capacity: 2) ++ ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) ++ ps.advanced(by: 1).initialize(to: unsafeBitCast(0, to: UnsafeMutablePointer.self)) ++ #else + let ps = UnsafeMutablePointer?>.allocate(capacity: 2) + ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) + ps.advanced(by: 1).initialize(to: nil) ++ #endif + let stream = fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) + ps.deinitialize(count: 2) + ps.deallocate() +@@ -1085,10 +1091,18 @@ extension FileManager { + do { + guard fm.fileExists(atPath: _url.path) else { throw _NSErrorWithErrno(ENOENT, reading: true, url: url) } + _stream = try FileManager.default._fileSystemRepresentation(withPath: _url.path) { fsRep in ++ #if os(Android) ++ let ps = UnsafeMutablePointer>.allocate(capacity: 2) ++ #else + let ps = UnsafeMutablePointer?>.allocate(capacity: 2) ++ #endif + defer { ps.deallocate() } + ps.initialize(to: UnsafeMutablePointer(mutating: fsRep)) ++ #if os(Android) ++ ps.advanced(by: 1).initialize(to: unsafeBitCast(0, to: UnsafeMutablePointer.self)) ++ #else + ps.advanced(by: 1).initialize(to: nil) ++ #endif + return fts_open(ps, FTS_PHYSICAL | FTS_XDEV | FTS_NOCHDIR | FTS_NOSTAT, nil) + } + if _stream == nil { diff --git a/swift-android.patch b/swift-android.patch index 9955df0d..58260580 100644 --- a/swift-android.patch +++ b/swift-android.patch @@ -1,19 +1,3 @@ -diff --git a/swift/stdlib/public/runtime/CrashHandlerLinux.cpp b/swift/stdlib/public/runtime/CrashHandlerLinux.cpp -index ff44dbe7541..2f386278975 100644 ---- a/swift/stdlib/public/runtime/CrashHandlerLinux.cpp -+++ b/swift/stdlib/public/runtime/CrashHandlerLinux.cpp -@@ -243,7 +243,11 @@ handle_fatal_signal(int signum, - #elif defined(__arm64__) || defined(__aarch64__) - pc = (void *)(ctx->uc_mcontext.pc); - #elif defined(__arm__) -+#if defined(__ANDROID__) -+ pc = (void *)(ctx->uc_mcontext.arm_pc); -+#else - pc = (void *)(ctx->uc_mcontext.gprs[15]); -+#endif - #endif - - _swift_displayCrashMessage(signum, pc); diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt index 016bf294..5c42986a 100644 --- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt diff --git a/swift-nio-force-unwrap.patch b/swift-nio-force-unwrap.patch new file mode 100644 index 00000000..63703e38 --- /dev/null +++ b/swift-nio-force-unwrap.patch @@ -0,0 +1,57 @@ +diff --git a/Sources/NIOCore/Interfaces.swift b/Sources/NIOCore/Interfaces.swift +index 1c656db0..5fcbbf83 100644 +--- a/Sources/NIOCore/Interfaces.swift ++++ b/Sources/NIOCore/Interfaces.swift +@@ -123,7 +123,7 @@ public final class NIONetworkInterface { + } + #else + internal init?(_ caddr: ifaddrs) { +- self.name = String(cString: caddr.ifa_name) ++ self.name = String(cString: caddr.ifa_name!) + + guard caddr.ifa_addr != nil else { + return nil +@@ -414,7 +414,7 @@ extension NIONetworkDevice { + } + #else + internal init?(_ caddr: ifaddrs) { +- self.name = String(cString: caddr.ifa_name) ++ self.name = String(cString: caddr.ifa_name!) + self.address = caddr.ifa_addr.flatMap { $0.convert() } + self.netmask = caddr.ifa_netmask.flatMap { $0.convert() } + +diff --git a/Sources/NIOCore/SystemCallHelpers.swift b/Sources/NIOCore/SystemCallHelpers.swift +index dc9b457a..676d22d9 100644 +--- a/Sources/NIOCore/SystemCallHelpers.swift ++++ b/Sources/NIOCore/SystemCallHelpers.swift +@@ -173,7 +173,7 @@ enum SystemCalls { + @inline(never) + internal static func if_nametoindex(_ name: UnsafePointer?) throws -> CUnsignedInt { + return try syscall(blocking: false) { +- sysIfNameToIndex(name) ++ sysIfNameToIndex(name!) + }.result + } + +diff --git a/Sources/NIOPosix/System.swift b/Sources/NIOPosix/System.swift +index 025e60f0..79096568 100644 +--- a/Sources/NIOPosix/System.swift ++++ b/Sources/NIOPosix/System.swift +@@ -90,7 +90,7 @@ func sysRecvFrom_wrapper(sockfd: CInt, buf: UnsafeMutableRawPointer, len: CLong, + return recvfrom(sockfd, buf, len, flags, src_addr, addrlen) // src_addr is 'UnsafeMutablePointer', but it need to be 'UnsafePointer' + } + func sysWritev_wrapper(fd: CInt, iov: UnsafePointer?, iovcnt: CInt) -> CLong { +- return CLong(writev(fd, iov, iovcnt)) // cast 'Int32' to 'CLong' ++ return CLong(writev(fd, iov!, iovcnt)) // cast 'Int32' to 'CLong' + } + private let sysWritev = sysWritev_wrapper + #elseif !os(Windows) +@@ -732,7 +732,7 @@ internal enum Posix { + @inline(never) + internal static func if_nametoindex(_ name: UnsafePointer?) throws -> CUnsignedInt { + return try syscall(blocking: false) { +- sysIfNameToIndex(name) ++ sysIfNameToIndex(name!) + }.result + } + diff --git a/swift-nio-ndk26.patch b/swift-nio-ndk26.patch new file mode 100644 index 00000000..dbb3c3a4 --- /dev/null +++ b/swift-nio-ndk26.patch @@ -0,0 +1,123 @@ +diff --git a/Sources/NIOCore/BSDSocketAPI.swift b/Sources/NIOCore/BSDSocketAPI.swift +index c370644e..07ba7beb 100644 +--- a/Sources/NIOCore/BSDSocketAPI.swift ++++ b/Sources/NIOCore/BSDSocketAPI.swift +@@ -68,8 +68,13 @@ import Musl + #endif + import CNIOLinux + ++#if os(Android) ++private let sysInet_ntop: @convention(c) (CInt, UnsafeRawPointer, UnsafeMutablePointer, socklen_t) -> UnsafePointer? = inet_ntop ++private let sysInet_pton: @convention(c) (CInt, UnsafePointer, UnsafeMutableRawPointer) -> CInt = inet_pton ++#else + private let sysInet_ntop: @convention(c) (CInt, UnsafeRawPointer?, UnsafeMutablePointer?, socklen_t) -> UnsafePointer? = inet_ntop + private let sysInet_pton: @convention(c) (CInt, UnsafePointer?, UnsafeMutableRawPointer?) -> CInt = inet_pton ++#endif + #elseif canImport(Darwin) + import Darwin + +diff --git a/Sources/NIOCore/SystemCallHelpers.swift b/Sources/NIOCore/SystemCallHelpers.swift +index dc9b457a..b74092a1 100644 +--- a/Sources/NIOCore/SystemCallHelpers.swift ++++ b/Sources/NIOCore/SystemCallHelpers.swift +@@ -43,11 +43,16 @@ private let sysOpenWithMode: @convention(c) (UnsafePointer, CInt, NIOPOSI + private let sysLseek: @convention(c) (CInt, off_t, CInt) -> off_t = lseek + private let sysRead: @convention(c) (CInt, UnsafeMutableRawPointer?, size_t) -> size_t = read + #endif +-private let sysIfNameToIndex: @convention(c) (UnsafePointer?) -> CUnsignedInt = if_nametoindex + ++#if os(Android) ++private let sysIfNameToIndex: @convention(c) (UnsafePointer) -> CUnsignedInt = if_nametoindex ++private let sysGetifaddrs: @convention(c) (UnsafeMutablePointer?>) -> CInt = getifaddrs ++#else ++private let sysIfNameToIndex: @convention(c) (UnsafePointer?) -> CUnsignedInt = if_nametoindex + #if !os(Windows) + private let sysGetifaddrs: @convention(c) (UnsafeMutablePointer?>?) -> CInt = getifaddrs + #endif ++#endif + + private func isUnacceptableErrno(_ code: Int32) -> Bool { + switch code { +diff --git a/Sources/NIOPosix/System.swift b/Sources/NIOPosix/System.swift +index 025e60f0..fc6c0584 100644 +--- a/Sources/NIOPosix/System.swift ++++ b/Sources/NIOPosix/System.swift +@@ -106,12 +106,16 @@ private let sysGetpeername: @convention(c) (CInt, UnsafeMutablePointer + private let sysGetsockname: @convention(c) (CInt, UnsafeMutablePointer?, UnsafeMutablePointer?) -> CInt = getsockname + #endif + ++#if os(Android) ++private let sysIfNameToIndex: @convention(c) (UnsafePointer) -> CUnsignedInt = if_nametoindex ++#else + private let sysIfNameToIndex: @convention(c) (UnsafePointer?) -> CUnsignedInt = if_nametoindex ++#endif + #if !os(Windows) + private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer?) -> CInt = socketpair + #endif + +-#if os(Linux) && !canImport(Musl) ++#if (os(Linux) && !canImport(Musl)) || os(Android) + private let sysFstat: @convention(c) (CInt, UnsafeMutablePointer) -> CInt = fstat + private let sysStat: @convention(c) (UnsafePointer, UnsafeMutablePointer) -> CInt = stat + private let sysLstat: @convention(c) (UnsafePointer, UnsafeMutablePointer) -> CInt = lstat +@@ -122,9 +126,14 @@ private let sysMkdir: @convention(c) (UnsafePointer, mode_t) -> CInt = mk + private let sysOpendir: @convention(c) (UnsafePointer) -> OpaquePointer? = opendir + private let sysReaddir: @convention(c) (OpaquePointer) -> UnsafeMutablePointer? = readdir + private let sysClosedir: @convention(c) (OpaquePointer) -> CInt = closedir ++#if os(Android) ++private let sysRename: @convention(c) (UnsafePointer, UnsafePointer) -> CInt = rename ++private let sysRemove: @convention(c) (UnsafePointer) -> CInt = remove ++#else + private let sysRename: @convention(c) (UnsafePointer?, UnsafePointer?) -> CInt = rename + private let sysRemove: @convention(c) (UnsafePointer?) -> CInt = remove +-#elseif canImport(Darwin) || os(Android) ++#endif ++#elseif canImport(Darwin) + private let sysFstat: @convention(c) (CInt, UnsafeMutablePointer?) -> CInt = fstat + private let sysStat: @convention(c) (UnsafePointer?, UnsafeMutablePointer?) -> CInt = stat + private let sysLstat: @convention(c) (UnsafePointer?, UnsafeMutablePointer?) -> CInt = lstat +@@ -132,16 +141,10 @@ private let sysSymlink: @convention(c) (UnsafePointer?, UnsafePointer?, UnsafeMutablePointer?, Int) -> CLong = readlink + private let sysUnlink: @convention(c) (UnsafePointer?) -> CInt = unlink + private let sysMkdir: @convention(c) (UnsafePointer?, mode_t) -> CInt = mkdir +-#if os(Android) +-private let sysOpendir: @convention(c) (UnsafePointer?) -> OpaquePointer? = opendir +-private let sysReaddir: @convention(c) (OpaquePointer?) -> UnsafeMutablePointer? = readdir +-private let sysClosedir: @convention(c) (OpaquePointer?) -> CInt = closedir +-#else + private let sysMkpath: @convention(c) (UnsafePointer?, mode_t) -> CInt = mkpath_np + private let sysOpendir: @convention(c) (UnsafePointer?) -> UnsafeMutablePointer? = opendir + private let sysReaddir: @convention(c) (UnsafeMutablePointer?) -> UnsafeMutablePointer? = readdir + private let sysClosedir: @convention(c) (UnsafeMutablePointer?) -> CInt = closedir +-#endif + private let sysRename: @convention(c) (UnsafePointer?, UnsafePointer?) -> CInt = rename + private let sysRemove: @convention(c) (UnsafePointer?) -> CInt = remove + #endif +diff --git a/Sources/NIOPosix/ThreadPosix.swift b/Sources/NIOPosix/ThreadPosix.swift +index b6e0ed4a..852f08f6 100644 +--- a/Sources/NIOPosix/ThreadPosix.swift ++++ b/Sources/NIOPosix/ThreadPosix.swift +@@ -19,7 +19,11 @@ import CNIOLinux + + private let sys_pthread_getname_np = CNIOLinux_pthread_getname_np + private let sys_pthread_setname_np = CNIOLinux_pthread_setname_np ++#if os(Android) ++private typealias ThreadDestructor = @convention(c) (UnsafeMutableRawPointer) -> UnsafeMutableRawPointer ++#else + private typealias ThreadDestructor = @convention(c) (UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? ++#endif + #elseif canImport(Darwin) + private let sys_pthread_getname_np = pthread_getname_np + // Emulate the same method signature as pthread_setname_np on Linux. +@@ -111,7 +115,11 @@ enum ThreadOpsPosix: ThreadOps { + + body(NIOThread(handle: hThread, desiredName: name)) + ++ #if os(Android) ++ return UnsafeMutableRawPointer(bitPattern: 0xdeadbee)! ++ #else + return nil ++ #endif + }, args: argv0) + precondition(res == 0, "Unable to create thread: \(res)") + diff --git a/swift-nio-ssh-ndk26.patch b/swift-nio-ssh-ndk26.patch new file mode 100644 index 00000000..cfdfc201 --- /dev/null +++ b/swift-nio-ssh-ndk26.patch @@ -0,0 +1,13 @@ +diff --git a/Sources/NIOSSHClient/ExecHandler.swift b/Sources/NIOSSHClient/ExecHandler.swift +index 8dd244e..9f1e5d5 100644 +--- a/Sources/NIOSSHClient/ExecHandler.swift ++++ b/Sources/NIOSSHClient/ExecHandler.swift +@@ -100,7 +100,7 @@ final class ExampleExecHandler: ChannelDuplexHandler { + case .stdErr: + // We just write to stderr directly, pipe channel can't help us here. + bytes.withUnsafeReadableBytes { str in +- let rc = fwrite(str.baseAddress, 1, str.count, stderr) ++ let rc = fwrite(str.baseAddress!, 1, str.count, stderr) + precondition(rc == str.count) + } + diff --git a/swift-nio-ssl-force-unwrap.patch b/swift-nio-ssl-force-unwrap.patch new file mode 100644 index 00000000..e5f84c30 --- /dev/null +++ b/swift-nio-ssl-force-unwrap.patch @@ -0,0 +1,13 @@ +diff --git a/Sources/NIOSSL/SSLContext.swift b/Sources/NIOSSL/SSLContext.swift +index 8b82976..3abecab 100644 +--- a/Sources/NIOSSL/SSLContext.swift ++++ b/Sources/NIOSSL/SSLContext.swift +@@ -853,7 +853,7 @@ internal class DirectoryContents: Sequence, IteratorProtocol { + + init(path: String) { + self.path = path +- self.dir = opendir(path) ++ self.dir = opendir(path)! + } + + func next() -> String? { diff --git a/swift-nio-ssl-ndk26.patch b/swift-nio-ssl-ndk26.patch new file mode 100644 index 00000000..d22c7ebb --- /dev/null +++ b/swift-nio-ssl-ndk26.patch @@ -0,0 +1,31 @@ +diff --git a/Sources/NIOSSL/PosixPort.swift b/Sources/NIOSSL/PosixPort.swift +index ad2924a..8d9170f 100644 +--- a/Sources/NIOSSL/PosixPort.swift ++++ b/Sources/NIOSSL/PosixPort.swift +@@ -36,18 +36,24 @@ internal typealias FILEPointer = OpaquePointer + internal typealias FILEPointer = UnsafeMutablePointer + #endif + ++#if os(Android) ++private let sysFopen: @convention(c) (UnsafePointer, UnsafePointer) -> FILEPointer? = fopen ++private let sysMlock: @convention(c) (UnsafeRawPointer, size_t) -> CInt = mlock ++private let sysMunlock: @convention(c) (UnsafeRawPointer, size_t) -> CInt = munlock ++#else + private let sysFopen: @convention(c) (UnsafePointer?, UnsafePointer?) -> FILEPointer? = fopen + private let sysMlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = mlock + private let sysMunlock: @convention(c) (UnsafeRawPointer?, size_t) -> CInt = munlock ++#endif + private let sysFclose: @convention(c) (FILEPointer?) -> CInt = { fclose($0!) } + + // Sadly, stat, lstat, and readlink have different signatures with glibc and macOS libc. +-#if canImport(Darwin) || os(Android) ++#if canImport(Darwin) + private let sysStat: @convention(c) (UnsafePointer?, UnsafeMutablePointer?) -> CInt = stat(_:_:) + private let sysReadlink: @convention(c) (UnsafePointer?, UnsafeMutablePointer?, Int) -> Int = readlink + private let sysLstat: @convention(c) (UnsafePointer?, UnsafeMutablePointer?) -> Int32 = lstat + +-#elseif os(Linux) || os(FreeBSD) ++#elseif os(Linux) || os(FreeBSD) || os(Android) + private let sysStat: @convention(c) (UnsafePointer, UnsafeMutablePointer) -> CInt = stat(_:_:) + private let sysReadlink: @convention(c) (UnsafePointer, UnsafeMutablePointer, Int) -> Int = readlink + private let sysLstat: @convention(c) (UnsafePointer, UnsafeMutablePointer) -> Int32 = lstat diff --git a/swift-system-ndk26.patch b/swift-system-ndk26.patch new file mode 100644 index 00000000..91a250a6 --- /dev/null +++ b/swift-system-ndk26.patch @@ -0,0 +1,22 @@ +diff --git a/Sources/System/Internals/Syscalls.swift b/Sources/System/Internals/Syscalls.swift +index 9fcb2f9..3d375a5 100644 +--- a/Sources/System/Internals/Syscalls.swift ++++ b/Sources/System/Internals/Syscalls.swift +@@ -71,7 +71,7 @@ internal func system_pread( + #if ENABLE_MOCKING + if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) } + #endif +- return pread(fd, buf, nbyte, offset) ++ return pread(fd, buf!, nbyte, offset) + } + + // lseek +@@ -101,7 +101,7 @@ internal func system_pwrite( + #if ENABLE_MOCKING + if mockingEnabled { return _mockInt(fd, buf, nbyte, offset) } + #endif +- return pwrite(fd, buf, nbyte, offset) ++ return pwrite(fd, buf!, nbyte, offset) + } + + internal func system_dup(_ fd: Int32) -> Int32 {