Skip to content

Commit 606ccef

Browse files
committed
Download and use the latest NDK 27 on the CI
1 parent 20b250a commit 606ccef

7 files changed

+241
-6
lines changed

.github/workflows/sdks.yml

+29-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ jobs:
1414
devel-version: ${{ steps.check.outputs.devel-tag }}
1515
trunk-version: ${{ steps.check.outputs.trunk-tag }}
1616
steps:
17+
- name: Get cached NDK
18+
id: cache-ndk
19+
uses: actions/cache@v4
20+
with:
21+
path: ~/android-ndk-r27-linux.zip
22+
key: ndk-27
23+
- name: Get NDK 27 if not cached
24+
if: ${{ steps.cache-ndk.outputs.cache-hit != 'true' }}
25+
run: wget -q -O ~/android-ndk-r27-linux.zip https://dl.google.com/android/repository/android-ndk-r27-linux.zip
1726
- name: Check for latest Swift ${{ matrix.version }} toolchain
1827
id: check
1928
run: |
@@ -84,12 +93,19 @@ jobs:
8493
with:
8594
path: ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz
8695
key: ${{ steps.version.outputs.tag }}-toolchain
96+
- name: Get cached NDK
97+
if: ${{ matrix.version != 'release-25c'}}
98+
id: cache-ndk
99+
uses: actions/cache@v4
100+
with:
101+
path: ~/android-ndk-r27-linux.zip
102+
key: ndk-27
87103
- name: Get cached SDK
88104
id: cache-sdk
89105
uses: actions/cache@v4
90106
with:
91107
path: ~/swift-${{ matrix.version }}-android-${{ matrix.arch }}-*-sdk.tar.xz
92-
key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-overlay-sdk
108+
key: ${{ matrix.version }}-${{ steps.version.outputs.latest }}-${{ matrix.arch }}-ndk27-sdk
93109
- name: Clone
94110
uses: actions/checkout@v4
95111
with:
@@ -116,7 +132,7 @@ jobs:
116132
git apply swift-android-stdlib-except-trunk.patch
117133
STUPID_FILE_RENAMING=Tool
118134
else
119-
sed -i "s%r26%ndk/26%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
135+
sed -i "s%r26%r27%" swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
120136
STUPID_FILE_RENAMING=Command
121137
fi
122138
if [ ${{ matrix.version }} = 'release-25c' ]; then
@@ -126,15 +142,18 @@ jobs:
126142
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-tools-support-core/Sources/TSCclibc/include/indexstore_functions.h
127143
sed -i "s%#include <time%#include <signal.h>\n#include <time%" swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h
128144
else
129-
NDK=$ANDROID_NDK_LATEST_HOME
145+
unzip -q ~/android-ndk-r27-linux.zip
146+
NDK=`pwd`/android-ndk-r27
130147
git apply -C0 swift-android-foundation-ndk26.patch
131148
if [ ${{ matrix.version }} = 'release-26d' ]; then
132149
git apply swift-android-stdlib-ndk26.patch
133150
else
134-
git apply android-overlay/foundation-fixes.patch android-overlay/swift-argument-parser.patch android-overlay/swift-system.patch android-overlay/yams.patch
135151
if [ ${{ matrix.version }} = 'devel' ]; then
136152
git apply android-overlay/import-android-devel.patch
153+
else
154+
git apply swift-android-foundation-trunk.patch
137155
fi
156+
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
138157
fi
139158
fi
140159
sed -i "s%/data/data/com.termux/files%$SDK%" $SDK/usr/lib/pkgconfig/sqlite3.pc
@@ -158,6 +177,10 @@ jobs:
158177
run: |
159178
cd sdk-config
160179
180+
if [[ ${{ matrix.version }} != 'release-25c' && ! -d android-ndk-r27 ]]; then
181+
unzip -q ~/android-ndk-r27-linux.zip
182+
fi
183+
161184
if [ ! -d ${{ steps.version.outputs.tag }}-ubuntu22.04 ]; then
162185
tar xf ~/${{ steps.version.outputs.tag }}-ubuntu22.04.tar.gz
163186
fi
@@ -198,6 +221,8 @@ jobs:
198221
git apply ../sdk-config/swift-nio-disable-ecn-tests.patch ../sdk-config/swift-nio-filesystem-both-ndks.patch
199222
if [ ${{ matrix.version }} = 'release-25c' ]; then
200223
git apply -R ../sdk-config/swift-nio-ndk26.patch
224+
else
225+
git apply ../sdk-config/swift-nio-ndk27.patch
201226
fi
202227
../sdk-config/${{ steps.version.outputs.tag }}-ubuntu22.04/usr/bin/swift package update
203228
cd .build/checkouts/
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
diff --git a/swift/stdlib/public/Platform/android.modulemap b/swift/stdlib/public/Platform/android.modulemap
2+
index 78e7bda9976..dc25e5c3668 100644
3+
--- a/swift/stdlib/public/Platform/android.modulemap
4+
+++ b/swift/stdlib/public/Platform/android.modulemap
5+
@@ -556,6 +556,12 @@ module _bits_sa_family_t [system] {
6+
header "bits/sa_family_t.h"
7+
export *
8+
}
9+
+
10+
+module _bits_sockaddr_storage [system] {
11+
+ header "bits/sockaddr_storage.h"
12+
+ export *
13+
+}
14+
+
15+
module _bits_stdatomic [system] {
16+
// Note: this module is not part of 'stdatomic'
17+
// as it depends on libc++ and forcing it to

swift-android-foundation-trunk.patch

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
commit 7e5350751e17515253c096350dddd3aeeda0eee2
2+
Author: Evan Wilde <etceterawilde@gmail.com>
3+
Date: Tue Jul 9 22:45:20 2024 -0700
4+
5+
Workaround broken glibc modulemap
6+
7+
We have been running into modularization issues on newer versions of
8+
various Linux distros, resulting in the compiler saying that the Glibc
9+
module doesn't have a SOCK_STREAM or SOCK_DGRAM. From some poking
10+
around, the definition is now coming from the CoreFoundation module as
11+
far as Swift is concerned. This is ultimately because our modulemap for
12+
Glibc is bad, but also means that I can't bring up Swift 6 on all of the
13+
Linux distros that 5.10 has support for.
14+
15+
This workaround removes the explicit module name from `SOCK_STREAM` and
16+
renames it to `FOUNDATION_SOCK_STREAM` to avoid an ambiguous name, and
17+
completely removes `SOCK_DGRAM`.
18+
19+
Both SOCK_STREAM and SOCK_DGRAM are fileprivates, so changing them will
20+
have no visible external effect. It is true that if another header
21+
somewhere defines `SOCK_STREAM`, we may pick it up instead of the
22+
definition from the glibc module, but that will also cause some nasty
23+
surprises to anyone using that header in C, so it is unlikely.
24+
25+
Fixes: rdar://128079849
26+
27+
diff --git a/swift-corelibs-foundation/Sources/Foundation/Port.swift b/swift-corelibs-foundation/Sources/Foundation/Port.swift
28+
index c53263f0..f06f95a9 100644
29+
--- a/swift-corelibs-foundation/Sources/Foundation/Port.swift
30+
+++ b/swift-corelibs-foundation/Sources/Foundation/Port.swift
31+
@@ -90,18 +90,22 @@ open class SocketPort: Port {}
32+
33+
#else
34+
35+
+#if canImport(Darwin)
36+
+import Darwin
37+
+fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM
38+
+fileprivate let FOUNDATION_IPPROTO_TCP = IPPROTO_TCP
39+
+#endif
40+
+
41+
#if canImport(Glibc) && !os(Android) && !os(OpenBSD)
42+
import Glibc
43+
-fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM.rawValue)
44+
-fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM.rawValue)
45+
-fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
46+
+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM.rawValue)
47+
+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
48+
#endif
49+
50+
#if canImport(Glibc) && os(Android) || os(OpenBSD)
51+
import Glibc
52+
-fileprivate let SOCK_STREAM = Int32(Glibc.SOCK_STREAM)
53+
-fileprivate let SOCK_DGRAM = Int32(Glibc.SOCK_DGRAM)
54+
-fileprivate let IPPROTO_TCP = Int32(Glibc.IPPROTO_TCP)
55+
+fileprivate let FOUNDATION_SOCK_STREAM = Int32(SOCK_STREAM)
56+
+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(IPPROTO_TCP)
57+
fileprivate let INADDR_ANY: in_addr_t = 0
58+
#if os(OpenBSD)
59+
fileprivate let INADDR_LOOPBACK = 0x7f000001
60+
@@ -123,7 +127,8 @@ import WinSDK
61+
fileprivate typealias sa_family_t = ADDRESS_FAMILY
62+
fileprivate typealias in_port_t = USHORT
63+
fileprivate typealias in_addr_t = UInt32
64+
-fileprivate let IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue)
65+
+fileprivate let FOUNDATION_SOCK_STREAM = SOCK_STREAM
66+
+fileprivate let FOUNDATION_IPPROTO_TCP = Int32(WinSDK.IPPROTO_TCP.rawValue)
67+
#endif
68+
69+
// MARK: Darwin representation of socket addresses
70+
@@ -484,7 +489,7 @@ open class SocketPort : Port {
71+
72+
let data = withUnsafeBytes(of: address) { Data($0) }
73+
74+
- self.init(protocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
75+
+ self.init(protocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data)
76+
}
77+
78+
private final func createNonuniquedCore(from socket: CFSocket, protocolFamily family: Int32, socketType type: Int32, protocol: Int32) {
79+
@@ -500,7 +505,7 @@ open class SocketPort : Port {
80+
var context = CFSocketContext()
81+
context.info = Unmanaged.passUnretained(self).toOpaque()
82+
var s: CFSocket
83+
- if type == SOCK_STREAM {
84+
+ if type == FOUNDATION_SOCK_STREAM {
85+
s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context)
86+
} else {
87+
s = CFSocketCreate(nil, family, type, `protocol`, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context)
88+
@@ -519,7 +524,7 @@ open class SocketPort : Port {
89+
var context = CFSocketContext()
90+
context.info = Unmanaged.passUnretained(self).toOpaque()
91+
var s: CFSocket
92+
- if type == SOCK_STREAM {
93+
+ if type == FOUNDATION_SOCK_STREAM {
94+
s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketAcceptCallBack), __NSFireSocketAccept, &context)
95+
} else {
96+
s = CFSocketCreateWithNative(nil, CFSocketNativeHandle(sock), CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketDatagram, &context)
97+
@@ -543,7 +548,7 @@ open class SocketPort : Port {
98+
sinAddr.sin_addr = inAddr
99+
100+
let data = withUnsafeBytes(of: sinAddr) { Data($0) }
101+
- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
102+
+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data)
103+
return
104+
}
105+
}
106+
@@ -556,7 +561,7 @@ open class SocketPort : Port {
107+
sinAddr.sin6_addr = in6Addr
108+
109+
let data = withUnsafeBytes(of: sinAddr) { Data($0) }
110+
- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
111+
+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data)
112+
return
113+
}
114+
}
115+
@@ -573,7 +578,7 @@ open class SocketPort : Port {
116+
withUnsafeBytes(of: in_addr_t(INADDR_LOOPBACK).bigEndian) { buffer.copyMemory(from: $0) }
117+
}
118+
let data = withUnsafeBytes(of: sinAddr) { Data($0) }
119+
- self.init(remoteWithProtocolFamily: PF_INET, socketType: SOCK_STREAM, protocol: IPPROTO_TCP, address: data)
120+
+ self.init(remoteWithProtocolFamily: PF_INET, socketType: FOUNDATION_SOCK_STREAM, protocol: FOUNDATION_IPPROTO_TCP, address: data)
121+
}
122+
123+
private static let remoteSocketCoresLock = NSLock()
124+
@@ -1049,7 +1054,7 @@ open class SocketPort : Port {
125+
if let connector = core.connectors[signature], CFSocketIsValid(connector) {
126+
return connector
127+
} else {
128+
- if signature.socketType == SOCK_STREAM {
129+
+ if signature.socketType == FOUNDATION_SOCK_STREAM {
130+
if let connector = CFSocketCreate(nil, socketKind.protocolFamily, socketKind.socketType, socketKind.protocol, CFOptionFlags(kCFSocketDataCallBack), __NSFireSocketData, &context), CFSocketIsValid(connector) {
131+
var timeout = time - Date.timeIntervalSinceReferenceDate
132+
if timeout < 0 || timeout >= SocketPort.maximumTimeout {

swift-android-stdlib-except-trunk.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ index 61447d50f08..b533b9291af 100644
77
list(APPEND result "-lm")
88
if(NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
99
- file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)
10-
+ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "ndk/26")
10+
+ if("${SWIFT_ANDROID_NDK_PATH}" MATCHES "ndk-r27")
1111
+ file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib/clang/*)
1212
+ else()
1313
+ file(GLOB RESOURCE_DIR ${SWIFT_SDK_ANDROID_ARCH_${LFLAGS_ARCH}_PATH}/../lib64/clang/*)

swift-android.patch

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2+
diff --git a/swift/utils/swift_build_support/swift_build_support/targets.py b/swift/utils/swift_build_support/swift_build_support/targets.py
3+
index 9932b854cb6..ad3ac757665 100644
4+
--- a/swift/utils/swift_build_support/swift_build_support/targets.py
5+
+++ b/swift/utils/swift_build_support/swift_build_support/targets.py
6+
@@ -167,9 +167,10 @@ class AndroidPlatform(Platform):
7+
options = cmake.CMakeOptions()
8+
options.define('CMAKE_SYSTEM_NAME', 'Android')
9+
options.define('CMAKE_SYSTEM_VERSION' , args.android_api_level)
10+
- options.define('CMAKE_SYSTEM_PROCESSOR', args.android_arch if not
11+
- args.android_arch == 'armv7'
12+
- else 'armv7-a')
13+
+ arm_arch_to_abi = { 'armv7' : 'armeabi-v7a', 'aarch64' : 'arm64-v8a' }
14+
+ options.define('CMAKE_ANDROID_ARCH_ABI', args.android_arch if not
15+
+ args.android_arch.startswith('a')
16+
+ else arm_arch_to_abi[args.android_arch])
17+
options.define('CMAKE_ANDROID_NDK:PATH', args.android_ndk)
18+
return options
19+
120
diff --git a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt b/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt
221
index 016bf294..5c42986a 100644
322
--- a/swift-corelibs-foundation/Sources/Foundation/CMakeLists.txt

swift-nio-filesystem-both-ndks.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ index f24736a7..310d9691 100644
9494
--- a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
9595
+++ b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
9696
@@ -19,8 +19,8 @@ import NIOCore
97-
import XCTest
97+
import NIOConcurrencyHelpers
9898

9999
extension FilePath {
100100
- static let testData = FilePath(#filePath)

swift-nio-ndk27.patch

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff --git a/Sources/NIOPosix/System.swift b/Sources/NIOPosix/System.swift
2+
index 33b3be73..b97fa645 100644
3+
--- a/Sources/NIOPosix/System.swift
4+
+++ b/Sources/NIOPosix/System.swift
5+
@@ -125,15 +125,15 @@ private let sysWritev = sysWritev_wrapper
6+
private let sysWritev: @convention(c) (Int32, UnsafePointer<iovec>?, CInt) -> CLong = writev
7+
#endif
8+
#if !os(Windows)
9+
-private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>?, CInt) -> ssize_t = recvmsg
10+
-private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>?, CInt) -> ssize_t = sendmsg
11+
+private let sysRecvMsg: @convention(c) (CInt, UnsafeMutablePointer<msghdr>, CInt) -> ssize_t = recvmsg
12+
+private let sysSendMsg: @convention(c) (CInt, UnsafePointer<msghdr>, CInt) -> ssize_t = sendmsg
13+
#endif
14+
private let sysDup: @convention(c) (CInt) -> CInt = dup
15+
#if !os(Windows)
16+
private let sysGetpeername:
17+
- @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getpeername
18+
+ @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getpeername
19+
private let sysGetsockname:
20+
- @convention(c) (CInt, UnsafeMutablePointer<sockaddr>?, UnsafeMutablePointer<socklen_t>?) -> CInt = getsockname
21+
+ @convention(c) (CInt, UnsafeMutablePointer<sockaddr>, UnsafeMutablePointer<socklen_t>) -> CInt = getsockname
22+
#endif
23+
24+
#if os(Android)
25+
@@ -142,7 +142,7 @@ private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>) -> CUnsigned
26+
private let sysIfNameToIndex: @convention(c) (UnsafePointer<CChar>?) -> CUnsignedInt = if_nametoindex
27+
#endif
28+
#if !os(Windows)
29+
-private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>?) -> CInt = socketpair
30+
+private let sysSocketpair: @convention(c) (CInt, CInt, CInt, UnsafeMutablePointer<CInt>) -> CInt = socketpair
31+
#endif
32+
33+
#if os(Linux) || os(Android) || canImport(Darwin)
34+
@@ -966,7 +966,7 @@ internal enum Posix {
35+
socketVector: UnsafeMutablePointer<CInt>?
36+
) throws {
37+
_ = try syscall(blocking: false) {
38+
- sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector)
39+
+ sysSocketpair(domain.rawValue, type.rawValue, protocolSubtype.rawValue, socketVector!)
40+
}
41+
}
42+
#endif

0 commit comments

Comments
 (0)