diff --git a/Package.swift b/Package.swift index b9b97e450..c5a39dab7 100644 --- a/Package.swift +++ b/Package.swift @@ -190,7 +190,7 @@ let package = Package( // by the external environment. This allows sourcekit-lsp to take advantage of the automation used // for building the swift toolchain, such as `update-checkout`, or cross-repo PR tests. -#if os(Linux) +#if canImport(Glibc) import Glibc #else import Darwin.C diff --git a/Sources/SKSupport/Platform.swift b/Sources/SKSupport/Platform.swift index f922ae7a2..a7e25654c 100644 --- a/Sources/SKSupport/Platform.swift +++ b/Sources/SKSupport/Platform.swift @@ -17,9 +17,8 @@ extension Platform { /// The file extension used for a dynamic library on this platform. public var dynamicLibraryExtension: String { switch self { - case .android: return "so" case .darwin: return "dylib" - case .linux: return "so" + case .linux, .android: return "so" } } } diff --git a/Sources/SKSupport/dlopen.swift b/Sources/SKSupport/dlopen.swift index 13f53f5ce..cea0fc9ae 100644 --- a/Sources/SKSupport/dlopen.swift +++ b/Sources/SKSupport/dlopen.swift @@ -62,9 +62,11 @@ public struct DLOpenFlags: RawRepresentable, OptionSet { public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: 0) #else public static let first: DLOpenFlags = DLOpenFlags(rawValue: 0) + #if !os(Android) public static let deepBind: DLOpenFlags = DLOpenFlags(rawValue: RTLD_DEEPBIND) #endif #endif + #endif public var rawValue: Int32 diff --git a/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift b/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift index 977e97ab7..2c1288cd2 100644 --- a/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift +++ b/Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift @@ -46,6 +46,8 @@ final class SwiftSourceKitFramework { self.path = path #if os(Windows) self.dylib = try dlopen(path.pathString, mode: []) + #elseif os(Android) + self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first]) #else self.dylib = try dlopen(path.pathString, mode: [.lazy, .local, .first, .deepBind]) #endif diff --git a/Utilities/build-script-helper.py b/Utilities/build-script-helper.py index 88bee89ca..4ab61a414 100755 --- a/Utilities/build-script-helper.py +++ b/Utilities/build-script-helper.py @@ -44,10 +44,21 @@ def get_swiftpm_options(args): # For '-Xcxx', '-I', '-Xcxx', os.path.join(args.toolchain, 'usr', 'lib', 'swift', 'Block'), - # Library rpath for swift, dispatch, Foundation, etc. when installing - '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux', ] + if 'ANDROID_DATA' in os.environ: + swiftpm_args += [ + '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/android', + # SwiftPM will otherwise try to compile against GNU strerror_r on + # Android and fail. + '-Xswiftc', '-Xcc', '-Xswiftc', '-U_GNU_SOURCE', + ] + else: + # Library rpath for swift, dispatch, Foundation, etc. when installing + swiftpm_args += [ + '-Xlinker', '-rpath', '-Xlinker', '$ORIGIN/../lib/swift/linux', + ] + return swiftpm_args def install(swiftpm_bin_path, toolchain):