Skip to content

Commit

Permalink
Download and use the latest NDK 27 on the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
finagolfin committed Jul 30, 2024
1 parent 20b250a commit c293be7
Show file tree
Hide file tree
Showing 7 changed files with 241 additions and 6 deletions.
33 changes: 29 additions & 4 deletions .github/workflows/sdks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -126,15 +142,18 @@ jobs:
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
else
NDK=$ANDROID_NDK_LATEST_HOME
unzip -q ~/android-ndk-r27-linux.zip
NDK=`pwd`/android-ndk-r27
git apply -C0 swift-android-foundation-ndk26.patch
if [ ${{ matrix.version }} = 'release-26d' ]; then
git apply swift-android-stdlib-ndk26.patch
else
git apply android-overlay/foundation-fixes.patch android-overlay/swift-argument-parser.patch android-overlay/swift-system.patch android-overlay/yams.patch
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
fi
fi
sed -i "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc
Expand All @@ -158,6 +177,10 @@ jobs:
run: |
cd sdk-config
if [[ ${{ matrix.version }} != 'release-25c' && ! -d android-ndk-r27 ]]; then
unzip -q ~/android-ndk-r27-linux.zip
fi
if [ ! -d ${{ steps.version.outputs.tag }}-ubuntu22.04 ]; then
tar xf ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz
fi
Expand Down Expand Up @@ -198,6 +221,8 @@ jobs:
git apply ../sdk-config/swift-nio-disable-ecn-tests.patch ../sdk-config/swift-nio-filesystem-both-ndks.patch
if [ ${{ matrix.version }} = 'release-25c' ]; then
git apply -R ../sdk-config/swift-nio-ndk26.patch
else
git apply ../sdk-config/swift-nio-ndk27.patch
fi
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift package update
cd .build/checkouts/
Expand Down
17 changes: 17 additions & 0 deletions android-overlay/swift-stdlib-modulemap.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap
index 78e7bda9976..dc25e5c3668 100644
--- a/swift/stdlib/public/Platform/android.modulemap
+++ b/swift/stdlib/public/Platform/android.modulemap
@@ -556,6 +556,12 @@ module _bits_sa_family_t [system] {
header "bits/sa_family_t.h"
export *
}
+
+module _bits_sockaddr_storage [system] {
+ 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
132 changes: 132 additions & 0 deletions swift-android-foundation-trunk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
commit 7e5350751e17515253c096350dddd3aeeda0eee2
Author: Evan Wilde <etceterawilde@gmail.com>
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 {
2 changes: 1 addition & 1 deletion swift-android-stdlib-except-trunk.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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/*)
Expand Down
19 changes: 19 additions & 0 deletions swift-android.patch
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion swift-nio-filesystem-both-ndks.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 42 additions & 0 deletions swift-nio-ndk27.patch
Original file line number Diff line number Diff line change
@@ -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<iovec>?, CInt) -> CLong = writev
#endif
#if !os(Windows)
-private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>?, CInt) -> ssize_t = recvmsg
-private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>?, CInt) -> ssize_t = sendmsg
+private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>, CInt) -> ssize_t = recvmsg
+private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>, CInt) -> ssize_t = sendmsg
#endif
private let sysDup: @convention(c) (CInt) -> CInt = dup
#if !os(Windows)
private let sysGetpeername:
- @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getpeername
+ @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getpeername
private let sysGetsockname:
- @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getsockname
+ @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getsockname
#endif

#if os(Android)
@@ -142,7 +142,7 @@ private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsigned
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
#endif
#if !os(Windows)
-private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>?) -> CInt = socketpair
+private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>) -> CInt = socketpair
#endif

#if os(Linux) || os(Android) || canImport(Darwin)
@@ -966,7 +966,7 @@ internal enum Posix {
socketVector: UnsafeMutablePointer<CInt>?
) throws {
_ = try syscall(blocking: false) {
- sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector)
+ sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector!)
}
}
#endif

0 comments on commit c293be7

Please sign in to comment.