Skip to content

Android: add native support #210

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
Jan 17, 2020
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Sources/SKSupport/Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know you could do this in my earlier pull, so modified it now.

}
}
}
2 changes: 2 additions & 0 deletions Sources/SKSupport/dlopen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member Author

Choose a reason for hiding this comment

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

#endif
#endif
#endif

public var rawValue: Int32

Expand Down
2 changes: 2 additions & 0 deletions Sources/SourceKit/sourcekitd/SwiftSourceKitFramework.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 13 additions & 2 deletions Utilities/build-script-helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,21 @@ def get_swiftpm_options(args):
# For <Block.h>
'-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',
Copy link
Member Author

Choose a reason for hiding this comment

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

]
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):
Expand Down