Skip to content

Commit 00c7768

Browse files
finagolfinaciidgh
authored andcommitted
Android: fix ABI triple detection, disable C++ modules flags, and
bring over tweaks from old bootstrap script to new one.
1 parent 7e8dbb1 commit 00c7768

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,13 @@ public final class ClangTargetBuildDescription {
226226
args += buildParameters.indexStoreArguments(for: target)
227227
}
228228

229-
if !buildParameters.triple.isWindows() {
230-
// Using modules currently conflicts with the Windows SDKs.
229+
if !buildParameters.triple.isWindows() && !buildParameters.triple.isAndroid() {
230+
// Using modules currently conflicts with the Windows and Android SDKs.
231231
args += ["-fmodules", "-fmodule-name=" + target.c99name]
232232
}
233233
args += ["-I", clangTarget.includeDir.pathString]
234234
args += additionalFlags
235-
if !buildParameters.triple.isWindows() {
235+
if !buildParameters.triple.isWindows() && !buildParameters.triple.isAndroid() {
236236
args += moduleCacheArgs
237237
}
238238
args += buildParameters.sanitizers.compileCFlags()

Sources/Build/Triple.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public struct Triple: Encodable {
6161

6262
public enum ABI: String, Encodable {
6363
case unknown
64-
case android = "androideabi"
64+
case android
6565
}
6666

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

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

8786
self.tripleString = string
8887
self.arch = arch
@@ -101,6 +100,13 @@ public struct Triple: Encodable {
101100
return nil
102101
}
103102

103+
fileprivate static func parseABI(_ string: String) -> ABI? {
104+
if string.hasPrefix(ABI.android.rawValue) {
105+
return ABI.android
106+
}
107+
return nil
108+
}
109+
104110
public func isAndroid() -> Bool {
105111
return os == .linux && abi == .android
106112
}

Sources/TSCBasic/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,8 @@ install(TARGETS TSCBasic
6262
LIBRARY DESTINATION lib
6363
RUNTIME DESTINATION bin)
6464
endif()
65+
66+
# Don't use GNU strerror_r on Android.
67+
if(CMAKE_SYSTEM_NAME STREQUAL Android)
68+
target_compile_options(TSCBasic PUBLIC "SHELL:-Xcc -U_GNU_SOURCE")
69+
endif()

Utilities/bootstrap

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ def get_build_target(args):
232232
if platform.system() == 'Darwin':
233233
return "x86_64-apple-macosx"
234234
elif platform.system() == 'Linux':
235-
if platform.machine() == 'x86_64':
235+
if 'ANDROID_DATA' in os.environ:
236+
if platform.machine().startswith('armv7'):
237+
return 'armv7a-unknown-linux-androideabi'
238+
elif platform.machine() == 'aarch64':
239+
return 'aarch64-unknown-linux-android'
240+
else:
241+
raise SystemExit("ERROR: unsupported Android platform:", platform.machine())
242+
elif platform.machine() == 'x86_64':
236243
return "x86_64-unknown-linux-gnu"
237244
elif platform.machine() == "i686":
238245
return "i686-unknown-linux"
@@ -548,10 +555,15 @@ def get_swiftpm_flags(args):
548555
"-Xlinker", "@executable_path/../../../../../SharedFrameworks",
549556
])
550557

551-
# Add a rpath to find core swift libraries on linux. We don't need a rpath
552-
# for Darwin because the Swift libraries are present in the OS.
558+
# Add a rpath to find core swift libraries on linux and Android. We don't
559+
# need a rpath for Darwin because the Swift libraries are present in the OS.
553560
if platform.system() == 'Linux':
554-
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/linux"])
561+
if 'ANDROID_DATA' in os.environ:
562+
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/android"])
563+
# Don't use GNU strerror_r on Android.
564+
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
565+
else:
566+
build_flags.extend(["-Xlinker", "-rpath=$ORIGIN/../lib/swift/linux"])
555567

556568
return build_flags
557569

0 commit comments

Comments
 (0)