Skip to content

Commit 4516d0e

Browse files
authored
Merge pull request #210 from buttaface/droid
Android: add native support
2 parents 6c64dfa + a4cec47 commit 4516d0e

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ let package = Package(
190190
// by the external environment. This allows sourcekit-lsp to take advantage of the automation used
191191
// for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests.
192192

193-
#if os(Linux)
193+
#if canImport(Glibc)
194194
import Glibc
195195
#else
196196
import Darwin.C

Sources/SKSupport/Platform.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ extension Platform {
1717
/// The file extension used for a dynamic library on this platform.
1818
public var dynamicLibraryExtension: String {
1919
switch self {
20-
case .android: return "so"
2120
case .darwin: return "dylib"
22-
case .linux: return "so"
21+
case .linux, .android: return "so"
2322
}
2423
}
2524
}

Sources/SKSupport/dlopen.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,11 @@ public struct DLOpenFlags: RawRepresentable, OptionSet {
6262
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0)
6363
#else
6464
public static let first: DLOpenFlags = DLOpenFlags(rawValue: 0)
65+
#if !os(Android)
6566
public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: RTLD_DEEPBIND)
6667
#endif
6768
#endif
69+
#endif
6870

6971
public var rawValue: Int32
7072

Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ final class SwiftSourceKitFramework {
4646
self.path = path
4747
#if os(Windows)
4848
self.dylib = try dlopen(path.pathString, mode: [])
49+
#elseif os(Android)
50+
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first])
4951
#else
5052
self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind])
5153
#endif

Utilities/build-script-helper.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ def get_swiftpm_options(args):
4444
# For <Block.h>
4545
'-Xcxx', '-I', '-Xcxx',
4646
os.path.join(args.toolchain, 'usr', 'lib', 'swift', 'Block'),
47-
# Library rpath for swift, dispatch, Foundation, etc. when installing
48-
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
4947
]
5048

49+
if 'ANDROID_DATA' in os.environ:
50+
swiftpm_args += [
51+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android',
52+
# SwiftPM will otherwise try to compile against GNU strerror_r on
53+
# Android and fail.
54+
'-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE',
55+
]
56+
else:
57+
# Library rpath for swift, dispatch, Foundation, etc. when installing
58+
swiftpm_args += [
59+
'-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux',
60+
]
61+
5162
return swiftpm_args
5263

5364
def install(swiftpm_bin_path, toolchain):

0 commit comments

Comments
 (0)