Skip to content

[Android] Use the new overlay and Bionic module from Swift 6 #2777

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ private import Darwin
private import Glibc
#elseif canImport(Musl)
private import Musl
#elseif canImport(Android)
private import Android
#endif
#else
import SwiftSyntaxMacros
Expand Down Expand Up @@ -137,7 +139,7 @@ private func _loadLibrary(_ path: String) throws -> UnsafeMutableRawPointer {
#else
private func _loadLibrary(_ path: String) throws -> UnsafeMutableRawPointer {
guard let dlHandle = dlopen(path, RTLD_LAZY | RTLD_LOCAL) else {
throw LibraryPluginError(message: "loader error: \(String(cString: dlerror()))")
throw LibraryPluginError(message: "loader error: \(String(cString: dlerror()!))")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with glibc? I thought that it was annotated with non null in some cases (at least I ran into one with foundation)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, worked fine in Fedora 40 x86_64, where I tested it before submitting, which uses a recent glibc 2.39-17 from earlier this year. Bionic simply added the _Nullable annotation to the output in the last year, so it has to be unwrapped for Android here, but unless glibc somehow can guarantee this is _Nonnull, this force unwrap should work for both.

}
return dlHandle
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/SwiftSyntax/SyntaxText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
private import Darwin
#elseif canImport(Glibc)
private import Glibc
#elseif canImport(Bionic)
private import Bionic
#elseif canImport(Musl)
private import Musl
#endif
Expand Down Expand Up @@ -281,6 +283,8 @@ private func compareMemory(
return Darwin.memcmp(s1, s2, count) == 0
#elseif canImport(Glibc)
return Glibc.memcmp(s1, s2, count) == 0
#elseif canImport(Bionic)
return Bionic.memcmp(s1, s2, count) == 0
#else
return UnsafeBufferPointer(start: s1, count: count)
.elementsEqual(UnsafeBufferPointer(start: s2, count: count))
Expand Down
2 changes: 2 additions & 0 deletions SwiftParserCLI/Sources/swift-parser-cli/TerminalUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(Android)
import Android
#elseif os(Windows)
import CRT
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class SigIntListener {
/// Registers a `SIGINT` signal handler that forwards `SIGINT` to all
/// subprocesses that are registered in `runningSubprocesses`
static func registerSigIntSubprocessTerminationHandler() {
#if canImport(Darwin) || canImport(Glibc)
#if canImport(Darwin) || canImport(Glibc) || canImport(Bionic)
signal(SIGINT) { _ in
SigIntListener.hasReceivedSigInt = true
for process in SigIntListener.runningSubprocesses {
Expand Down