From c293be7ca4704d79be7595aa1bfe67c6b11b621c Mon Sep 17 00:00:00 2001 From: Finagolfin Date: Thu, 25 Jul 2024 18:15:48 +0530 Subject: [PATCH] Download and use the latest NDK 27 on the CI --- .github/workflows/sdks.yml | 33 ++++- android-overlay/swift-stdlib-modulemap.patch | 17 +++ swift-android-foundation-trunk.patch | 132 +++++++++++++++++++ swift-android-stdlib-except-trunk.patch | 2 +- swift-android.patch | 19 +++ swift-nio-filesystem-both-ndks.patch | 2 +- swift-nio-ndk27.patch | 42 ++++++ 7 files changed, 241 insertions(+), 6 deletions(-) create mode 100644 android-overlay/swift-stdlib-modulemap.patch create mode 100644 swift-android-foundation-trunk.patch create mode 100644 swift-nio-ndk27.patch diff --git a/.github/workflows/sdks.yml b/.github/workflows/sdks.yml index fd2749f8..593f97df 100644 --- a/.github/workflows/sdks.yml +++ b/.github/workflows/sdks.yml @@ -14,6 +14,15 @@ jobs: devel-version: ${{ steps.check.outputs.devel-tag }} trunk-version: ${{ steps.check.outputs.trunk-tag }} steps: + - name: Get cached NDK + id: cache-ndk + uses: actions/cache@v4 + with: + path: ~/android-ndk-r27-linux.zip + key: ndk-27 + - name: Get NDK 27 if not cached + if: ${{ steps.cache-ndk.outputs.cache-hit != 'true' }} + run: wget -q -O ~/android-ndk-r27-linux.zip https://dl.google.com/android/repository/android-ndk-r27-linux.zip - name: Check for latest Swift ${{ matrix.version }} toolchain id: check run: | @@ -84,12 +93,19 @@ jobs: with: path: ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz key: ${{ steps.version.outputs.tag }}-toolchain + - name: Get cached NDK + if: ${{ matrix.version != 'release-25c'}} + id: cache-ndk + uses: actions/cache@v4 + with: + path: ~/android-ndk-r27-linux.zip + key: ndk-27 - name: Get cached SDK id: cache-sdk uses: actions/cache@v4 with: path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}-*-sdk.tar.xz - key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-overlay-sdk + key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-ndk27-sdk - name: Clone uses: actions/checkout@v4 with: @@ -116,7 +132,7 @@ jobs: git apply swift-android-stdlib-except-trunk.patch STUPID_FILE_RENAMING=Tool else - sed -i "s%r26%ndk/26%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake + sed -i "s%r26%r27%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake STUPID_FILE_RENAMING=Command fi if [ ${{ matrix.version }} = 'release-25c' ]; then @@ -126,15 +142,18 @@ jobs: sed -i "s%#include \n#include \n#include +Date: Tue Jul 9 22:45:20 2024 -0700 + + Workaround broken glibc modulemap + + We have been running into modularization issues on newer versions of + various Linux distros, resulting in the compiler saying that the Glibc + module doesn't have a SOCK_STREAM or SOCK_DGRAM. From some poking + around, the definition is now coming from the CoreFoundation module as + far as Swift is concerned. This is ultimately because our modulemap for + Glibc is bad, but also means that I can't bring up Swift 6 on all of the + Linux distros that 5.10 has support for. + + This workaround removes the explicit module name from `SOCK_STREAM` and + renames it to `FOUNDATION_SOCK_STREAM` to avoid an ambiguous name, and + completely removes `SOCK_DGRAM`. + + Both SOCK_STREAM and SOCK_DGRAM are fileprivates, so changing them will + have no visible external effect. It is true that if another header + somewhere defines `SOCK_STREAM`, we may pick it up instead of the + definition from the glibc module, but that will also cause some nasty + surprises to anyone using that header in C, so it is unlikely. + + Fixes: rdar://128079849 + +diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift +index c53263f0..f06f95a9 100644 +--- a/swift-corelibs-foundation/Sources/Foundation/Port.swift ++++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift +@@ -90,18 +90,22 @@ open class SocketPort: Port {} + + #else + ++#if canImport(Darwin) ++import Darwin ++fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM ++fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP ++#endif ++ + #if canImport(Glibc) && !os(Android) && !os(OpenBSD) + import Glibc +-fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue) +-fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM.rawValue) +-fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP) ++fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue) ++fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP) + #endif + + #if canImport(Glibc) && os(Android) || os(OpenBSD) + import Glibc +-fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM) +-fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM) +-fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP) ++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 +@@ -123,7 +127,8 @@ import WinSDK + fileprivate typealias sa_family_t = ADDRESS_FAMILY + fileprivate typealias in_port_t = USHORT + fileprivate typealias in_addr_t = UInt32 +-fileprivate let IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue) ++fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM ++fileprivate let FOUNDATION_IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue) + #endif + + // MARK: Darwin representation of socket addresses +@@ -484,7 +489,7 @@ open class SocketPort : Port { + + let data = withUnsafeBytes(of: address) { Data($0) } + +- self.init(protocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) ++ self.init(protocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) + } + + private final func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) { +@@ -500,7 +505,7 @@ open class SocketPort : Port { + var context = CFSocketContext() + context.info = Unmanaged.passUnretained(self).toOpaque() + var s: CFSocket +- if type == SOCK_STREAM { ++ if type == FOUNDATION_SOCK_STREAM { + s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context) + } else { + s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context) +@@ -519,7 +524,7 @@ open class SocketPort : Port { + var context = CFSocketContext() + context.info = Unmanaged.passUnretained(self).toOpaque() + var s: CFSocket +- if type == SOCK_STREAM { ++ if type == FOUNDATION_SOCK_STREAM { + s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context) + } else { + s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context) +@@ -543,7 +548,7 @@ open class SocketPort : Port { + sinAddr.sin_addr = inAddr + + let data = withUnsafeBytes(of: sinAddr) { Data($0) } +- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) ++ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) + return + } + } +@@ -556,7 +561,7 @@ open class SocketPort : Port { + sinAddr.sin6_addr = in6Addr + + let data = withUnsafeBytes(of: sinAddr) { Data($0) } +- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) ++ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) + return + } + } +@@ -573,7 +578,7 @@ open class SocketPort : Port { + withUnsafeBytes(of: in_addr_t(INADDR_LOOPBACK).bigEndian) { buffer.copyMemory(from: $0) } + } + let data = withUnsafeBytes(of: sinAddr) { Data($0) } +- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data) ++ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data) + } + + private static let remoteSocketCoresLock = NSLock() +@@ -1049,7 +1054,7 @@ open class SocketPort : Port { + if let connector = core.connectors[signature], CFSocketIsValid(connector) { + return connector + } else { +- if signature.socketType == SOCK_STREAM { ++ if signature.socketType == FOUNDATION_SOCK_STREAM { + if let connector = CFSocketCreate(nil, socketKind.protocolFamily, socketKind.socketType, socketKind.protocol, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketData, &context), CFSocketIsValid(connector) { + var timeout = time - Date.timeIntervalSinceReferenceDate + if timeout < 0 || timeout >= SocketPort.maximumTimeout { diff --git a/swift-android-stdlib-except-trunk.patch b/swift-android-stdlib-except-trunk.patch index 93e70f26..bc114180 100644 --- a/swift-android-stdlib-except-trunk.patch +++ b/swift-android-stdlib-except-trunk.patch @@ -7,7 +7,7 @@ index 61447d50f08..b533b9291af 100644 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") ++ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "ndk-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-android.patch b/swift-android.patch index 58260580..8f91de5d 100644 --- a/swift-android.patch +++ b/swift-android.patch @@ -1,3 +1,22 @@ + +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 ++++ b/swift/utils/swift_build_support/swift_build_support/targets.py +@@ -167,9 +167,10 @@ class AndroidPlatform(Platform): + options = cmake.CMakeOptions() + options.define('CMAKE_SYSTEM_NAME', 'Android') + options.define('CMAKE_SYSTEM_VERSION' , args.android_api_level) +- options.define('CMAKE_SYSTEM_PROCESSOR', args.android_arch if not +- args.android_arch == 'armv7' +- else 'armv7-a') ++ arm_arch_to_abi = { 'armv7' : 'armeabi-v7a', 'aarch64' : 'arm64-v8a' } ++ options.define('CMAKE_ANDROID_ARCH_ABI', args.android_arch if not ++ args.android_arch.startswith('a') ++ else arm_arch_to_abi[args.android_arch]) + options.define('CMAKE_ANDROID_NDK:PATH', args.android_ndk) + return options + 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-filesystem-both-ndks.patch b/swift-nio-filesystem-both-ndks.patch index 09f52dce..31e3ee00 100644 --- a/swift-nio-filesystem-both-ndks.patch +++ b/swift-nio-filesystem-both-ndks.patch @@ -94,7 +94,7 @@ index f24736a7..310d9691 100644 --- a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift +++ b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift @@ -19,8 +19,8 @@ import NIOCore - import XCTest + import NIOConcurrencyHelpers extension FilePath { - static let testData = FilePath(#filePath) diff --git a/swift-nio-ndk27.patch b/swift-nio-ndk27.patch new file mode 100644 index 00000000..652fce60 --- /dev/null +++ b/swift-nio-ndk27.patch @@ -0,0 +1,42 @@ +diff --git a/Sources/NIOPosix/System.swift b/Sources/NIOPosix/System.swift +index 33b3be73..b97fa645 100644 +--- a/Sources/NIOPosix/System.swift ++++ b/Sources/NIOPosix/System.swift +@@ -125,15 +125,15 @@ private let sysWritev = sysWritev_wrapper + private let sysWritev: @convention(c) (Int32, UnsafePointer?, CInt) -> CLong = writev + #endif + #if !os(Windows) +-private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer?, CInt) -> ssize_t = recvmsg +-private let sysSendMsg: @convention(c) (CInt, UnsafePointer?, CInt) -> ssize_t = sendmsg ++private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer, CInt) -> ssize_t = recvmsg ++private let sysSendMsg: @convention(c) (CInt, UnsafePointer, CInt) -> ssize_t = sendmsg + #endif + private let sysDup: @convention(c) (CInt) -> CInt = dup + #if !os(Windows) + private let sysGetpeername: +- @convention(c) (CInt, UnsafeMutablePointer?, UnsafeMutablePointer?) -> CInt = getpeername ++ @convention(c) (CInt, UnsafeMutablePointer, UnsafeMutablePointer) -> CInt = getpeername + private let sysGetsockname: +- @convention(c) (CInt, UnsafeMutablePointer?, UnsafeMutablePointer?) -> CInt = getsockname ++ @convention(c) (CInt, UnsafeMutablePointer, UnsafeMutablePointer) -> CInt = getsockname + #endif + + #if os(Android) +@@ -142,7 +142,7 @@ private let sysIfNameToIndex: @convention(c) (UnsafePointer) -> CUnsigned + private let sysIfNameToIndex: @convention(c) (UnsafePointer?) -> CUnsignedInt = if_nametoindex + #endif + #if !os(Windows) +-private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer?) -> CInt = socketpair ++private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer) -> CInt = socketpair + #endif + + #if os(Linux) || os(Android) || canImport(Darwin) +@@ -966,7 +966,7 @@ internal enum Posix { + socketVector: UnsafeMutablePointer? + ) throws { + _ = try syscall(blocking: false) { +- sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector) ++ sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector!) + } + } + #endif