Skip to content

Commit 4adfbcc

Browse files
finagolfinaciidgh
authored andcommitted
Android: add bootstrap build support and fix tests
1 parent 5c942f6 commit 4adfbcc

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

Sources/PackageLoading/Target+PkgConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ extension SystemPackageProviderDescription {
118118
if case .linux(.debian) = platform {
119119
return true
120120
}
121+
if case .android = platform {
122+
return true
123+
}
121124
}
122125
return false
123126
}

Tests/PackageLoadingTests/PackageBuilderTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class PackageBuilderTests: XCTestCase {
111111

112112
#if os(Linux)
113113
result.checkDiagnostic("ignoring target 'MyPackageTests' in package 'MyPackage'; C language in tests is not yet supported")
114-
#elseif os(macOS)
114+
#elseif os(macOS) || os(Android)
115115
result.checkProduct("MyPackagePackageTests") { _ in }
116116
#endif
117117
}

Tests/TSCBasicTests/FileSystemTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ class FileSystemTests: XCTestCase {
181181

182182
// Check read/write against root.
183183
XCTAssertThrows(FileSystemError.ioError) {
184+
#if os(Android)
185+
_ = try fs.readFileContents(AbsolutePath("/system/"))
186+
#else
184187
_ = try fs.readFileContents(AbsolutePath("/"))
188+
#endif
185189
}
186190
XCTAssertThrows(FileSystemError.isDirectory) {
187191
try fs.writeFileContents(AbsolutePath("/"), bytes: [])

Tests/TSCBasicTests/PathShimTests.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,30 @@ class PathShimTests : XCTestCase {
6464
class WalkTests : XCTestCase {
6565

6666
func testNonRecursive() {
67+
#if os(Android)
68+
let root = "/system"
69+
var expected = [
70+
AbsolutePath("\(root)/usr"),
71+
AbsolutePath("\(root)/bin"),
72+
AbsolutePath("\(root)/xbin")
73+
]
74+
#else
75+
let root = ""
6776
var expected = [
6877
AbsolutePath("/usr"),
6978
AbsolutePath("/bin"),
7079
AbsolutePath("/sbin")
7180
]
72-
for x in try! walk(AbsolutePath("/"), recursively: false) {
81+
#endif
82+
for x in try! walk(AbsolutePath("\(root)/"), recursively: false) {
7383
if let i = expected.firstIndex(of: x) {
7484
expected.remove(at: i)
7585
}
86+
#if os(Android)
87+
XCTAssertEqual(3, x.components.count)
88+
#else
7689
XCTAssertEqual(2, x.components.count)
90+
#endif
7791
}
7892
XCTAssertEqual(expected.count, 0)
7993
}

Utilities/bootstrap

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ class Target(object):
270270
if args.llbuild_link_framework:
271271
other_args.extend(["-F", args.llbuild_build_dir])
272272

273+
# Don't use GNU strerror_r on Android.
274+
if 'ANDROID_DATA' in os.environ:
275+
other_args.extend(["-Xcc", "-U_GNU_SOURCE"])
276+
273277
print(" import-paths: %s" % json.dumps(import_paths), file=output)
274278
print(" other-args: %s" % json.dumps(other_args),
275279
file=output)
@@ -681,7 +685,7 @@ def process_runtime_libraries(build, args, lib_path):
681685
cmd = [args.swiftc_path, "-emit-library", "-o", runtime_lib_path,
682686
"-Xlinker", "--whole-archive",
683687
"-Xlinker", input_lib_path,
684-
"-Xlinker", "--no-whole-archive", "-lswiftGlibc",
688+
"-Xlinker", "--no-whole-archive", "-lswiftGlibc", "-lFoundation",
685689
"-Xlinker", "-rpath=$ORIGIN/../../linux"]
686690

687691
# We need to pass one swift file here to bypass the "no input files"
@@ -1035,7 +1039,14 @@ def main():
10351039
if platform.system() == 'Darwin':
10361040
build_target = "x86_64-apple-macosx"
10371041
elif platform.system() == 'Linux':
1038-
if platform.machine() == 'x86_64':
1042+
if 'ANDROID_DATA' in os.environ:
1043+
if platform.machine().startswith("armv7"):
1044+
build_target = 'armv7-unknown-linux-androideabi'
1045+
elif platform.machine() == 'aarch64':
1046+
build_target = 'aarch64-unknown-linux-android'
1047+
else:
1048+
raise SystemExit("ERROR: unsupported Android platform:",platform.machine())
1049+
elif platform.machine() == 'x86_64':
10391050
build_target = "x86_64-unknown-linux-gnu"
10401051
elif platform.machine() == "i686":
10411052
build_target = "i686-unknown-linux"
@@ -1186,6 +1197,10 @@ def main():
11861197
# Append the versioning build flags.
11871198
build_flags.extend(create_versoning_args(args))
11881199

1200+
# Don't use GNU strerror_r on Android.
1201+
if 'ANDROID_DATA' in os.environ:
1202+
build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"])
1203+
11891204
# Add llbuild import flags.
11901205
for import_path in llbuild_import_paths(args):
11911206
build_flags.extend(["-Xswiftc", "-I%s" % import_path])

0 commit comments

Comments
 (0)