Skip to content

Commit 808957a

Browse files
committed
Fix Android builds with NDK r28 and later
The nullability annotations of many POSIX functions changed in r28. Also switch the CI to test with both the latest LTS version (r27d) and the latest stable version (r29).
1 parent 40b3fdc commit 808957a

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
macos_build_command: 'xcrun swift-format lint -s -r --configuration ./.swift-format . && xcrun swift test && xcrun swift test -c release && xcrun swift test --disable-default-traits'
4040
enable_linux_static_sdk_build: true
4141
enable_android_sdk_build: true
42+
android_ndk_version: '["r27d", "r29"]'
4243
linux_static_sdk_versions: '["6.1", "nightly-6.2"]'
4344
linux_static_sdk_build_command: |
4445
for triple in aarch64-swift-linux-musl x86_64-swift-linux-musl ; do

Sources/Subprocess/Thread.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,24 +312,19 @@ internal func pthread_create(
312312
(Unmanaged<AnyObject>.fromOpaque(context).takeRetainedValue() as! Context).body()
313313
return context
314314
}
315-
#elseif canImport(Glibc) || canImport(Musl)
315+
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
316316
func proc(_ context: UnsafeMutableRawPointer?) -> UnsafeMutableRawPointer? {
317317
(Unmanaged<AnyObject>.fromOpaque(context!).takeRetainedValue() as! Context).body()
318318
return context
319319
}
320-
#elseif canImport(Bionic)
321-
func proc(_ context: UnsafeMutableRawPointer) -> UnsafeMutableRawPointer {
322-
(Unmanaged<AnyObject>.fromOpaque(context).takeRetainedValue() as! Context).body()
323-
return context
324-
}
325320
#endif
326321

327322
#if canImport(Glibc) || canImport(Bionic)
328323
var thread = pthread_t()
329324
#else
330325
var thread: pthread_t?
331326
#endif
332-
let rc = pthread_create(
327+
let rc = _subprocess_pthread_create(
333328
&thread,
334329
nil,
335330
proc,

Sources/_SubprocessCShims/include/process_shims.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "target_conditionals.h"
1616

1717
#if !TARGET_OS_WINDOWS
18+
#include <pthread.h>
1819
#include <unistd.h>
1920

2021
#if _POSIX_SPAWN
@@ -39,6 +40,13 @@
3940
extern "C" {
4041
#endif
4142

43+
int _subprocess_pthread_create(
44+
pthread_t* _Nonnull ptr,
45+
pthread_attr_t const* _Nullable attr,
46+
void* _Nullable (* _Nonnull start)(void* _Nullable),
47+
void* _Nullable context
48+
);
49+
4250
#if __has_include(<mach/vm_page_size.h>)
4351
vm_size_t _subprocess_vm_size(void);
4452
#endif

Sources/_SubprocessCShims/process_shims.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ int _was_process_suspended(int status) {
7979
return WIFSTOPPED(status);
8080
}
8181

82+
int _subprocess_pthread_create(
83+
pthread_t * _Nonnull ptr,
84+
pthread_attr_t const * _Nullable attr,
85+
void * _Nullable (* _Nonnull start)(void * _Nullable),
86+
void * _Nullable context
87+
) {
88+
return pthread_create(ptr, attr, start, context);
89+
}
90+
8291
#endif
8392

8493
#if __has_include(<mach/vm_page_size.h>)

0 commit comments

Comments
 (0)