Skip to content

Android: fix ABI triple detection, disable C++ modules flags, and bring back bootstrap script tweaks #2466

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
Dec 17, 2019
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
6 changes: 3 additions & 3 deletions Sources/Build/BuildPlan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ public final class ClangTargetBuildDescription {
args += buildParameters.indexStoreArguments(for: target)
}

if !buildParameters.triple.isWindows() {
// Using modules currently conflicts with the Windows SDKs.
if !buildParameters.triple.isWindows() && !buildParameters.triple.isAndroid() {
// Using modules currently conflicts with the Windows and Android SDKs.
args += ["-fmodules", "-fmodule-name=" + target.c99name]
}
args += ["-I", clangTarget.includeDir.pathString]
args += additionalFlags
if !buildParameters.triple.isWindows() {
if !buildParameters.triple.isWindows() && !buildParameters.triple.isAndroid() {
args += moduleCacheArgs
}
args += buildParameters.sanitizers.compileCFlags()
Expand Down
12 changes: 9 additions & 3 deletions Sources/Build/Triple.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public struct Triple: Encodable {

public enum ABI: String, Encodable {
case unknown
case android = "androideabi"
Copy link
Member Author

Choose a reason for hiding this comment

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

This raw value was added years back and never used until my recent native Android pulls, so should be fine to change.

case android
}

public init(_ string: String) throws {
Expand All @@ -81,8 +81,7 @@ public struct Triple: Encodable {
throw Error.unknownOS
}

let abiString = components.count > 3 ? components[3] : nil
let abi = abiString.flatMap(ABI.init)
let abi = components.count > 3 ? Triple.parseABI(components[3]) : nil

self.tripleString = string
self.arch = arch
Expand All @@ -101,6 +100,13 @@ public struct Triple: Encodable {
return nil
}

fileprivate static func parseABI(_ string: String) -> ABI? {
if string.hasPrefix(ABI.android.rawValue) {
return ABI.android
}
return nil
}

public func isAndroid() -> Bool {
return os == .linux && abi == .android
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/TSCBasic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,8 @@ install(TARGETS TSCBasic
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin)
endif()

# Don't use GNU strerror_r on Android.
if(CMAKE_SYSTEM_NAME STREQUAL Android)
target_compile_options(TSCBasic PUBLIC "SHELL:-Xcc -U_GNU_SOURCE")
endif()
20 changes: 16 additions & 4 deletions Utilities/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,14 @@ def get_build_target(args):
if platform.system() == 'Darwin':
return "x86_64-apple-macosx"
elif platform.system() == 'Linux':
if platform.machine() == 'x86_64':
if 'ANDROID_DATA' in os.environ:
Copy link
Contributor

Choose a reason for hiding this comment

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

Hey, wanna try using the new swift -print-target-info to get the triple automatically?

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'll try it out.

if platform.machine().startswith('armv7'):
return 'armv7a-unknown-linux-androideabi'
elif platform.machine() == 'aarch64':
return 'aarch64-unknown-linux-android'
else:
raise SystemExit("ERROR: unsupported Android platform:", platform.machine())
elif platform.machine() == 'x86_64':
return "x86_64-unknown-linux-gnu"
elif platform.machine() == "i686":
return "i686-unknown-linux"
Expand Down Expand Up @@ -548,10 +555,15 @@ def get_swiftpm_flags(args):
"-Xlinker", "@executable_path/../../../../../SharedFrameworks",
])

# Add a rpath to find core swift libraries on linux. We don't need a rpath
# for Darwin because the Swift libraries are present in the OS.
# Add a rpath to find core swift libraries on linux and Android. We don't
# need a rpath for Darwin because the Swift libraries are present in the OS.
if platform.system() == 'Linux':
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/linux"])
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably drive this based on swift -print-target-info as well 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, ‘-print-target-info’ indicates whether one should use rpaths

Copy link
Member Author

Choose a reason for hiding this comment

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

@aciidb0mb3r, do you mean extracting the relative path from the provided runtimeLibraryPaths instead of hardcoding it for each platform here? Because librariesRequireRPath is currently useless on non-Darwin platforms, always returning false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exacting the "linux" or "android" bit from the triple should be good enough, I think? @DougGregor or @brentdax might have better ideas though.

Anyway, I don't want to block your PR on this stuff so I am happy to take this patch and perhaps you can try swift -print-target-info in a follow on patch 😃

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, I'll try it in my next pull.

if 'ANDROID_DATA' in os.environ:
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/android"])
# Don't use GNU strerror_r on Android.
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
else:
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/linux"])

return build_flags

Expand Down