diff --git a/Sources/PackageLoading/Target+PkgConfig.swift b/Sources/PackageLoading/Target+PkgConfig.swift index 944946d5cd6..92887410c14 100644 --- a/Sources/PackageLoading/Target+PkgConfig.swift +++ b/Sources/PackageLoading/Target+PkgConfig.swift @@ -118,6 +118,9 @@ extension SystemPackageProviderDescription { if case .linux(.debian) = platform { return true } + if case .android = platform { + return true + } } return false } diff --git a/Tests/PackageLoadingTests/PackageBuilderTests.swift b/Tests/PackageLoadingTests/PackageBuilderTests.swift index 318f834c798..59181ac17bc 100644 --- a/Tests/PackageLoadingTests/PackageBuilderTests.swift +++ b/Tests/PackageLoadingTests/PackageBuilderTests.swift @@ -111,7 +111,7 @@ class PackageBuilderTests: XCTestCase { #if os(Linux) result.checkDiagnostic("ignoring target 'MyPackageTests' in package 'MyPackage'; C language in tests is not yet supported") - #elseif os(macOS) + #elseif os(macOS) || os(Android) result.checkProduct("MyPackagePackageTests") { _ in } #endif } diff --git a/Tests/TSCBasicTests/FileSystemTests.swift b/Tests/TSCBasicTests/FileSystemTests.swift index e058e31e322..be5d96b8853 100644 --- a/Tests/TSCBasicTests/FileSystemTests.swift +++ b/Tests/TSCBasicTests/FileSystemTests.swift @@ -181,7 +181,11 @@ class FileSystemTests: XCTestCase { // Check read/write against root. XCTAssertThrows(FileSystemError.ioError) { + #if os(Android) + _ = try fs.readFileContents(AbsolutePath("/system/")) + #else _ = try fs.readFileContents(AbsolutePath("/")) + #endif } XCTAssertThrows(FileSystemError.isDirectory) { try fs.writeFileContents(AbsolutePath("/"), bytes: []) diff --git a/Tests/TSCBasicTests/PathShimTests.swift b/Tests/TSCBasicTests/PathShimTests.swift index 725a5b6320f..e6a5f5d5c2b 100644 --- a/Tests/TSCBasicTests/PathShimTests.swift +++ b/Tests/TSCBasicTests/PathShimTests.swift @@ -64,16 +64,30 @@ class PathShimTests : XCTestCase { class WalkTests : XCTestCase { func testNonRecursive() { + #if os(Android) + let root = "/system" + var expected = [ + AbsolutePath("\(root)/usr"), + AbsolutePath("\(root)/bin"), + AbsolutePath("\(root)/xbin") + ] + #else + let root = "" var expected = [ AbsolutePath("/usr"), AbsolutePath("/bin"), AbsolutePath("/sbin") ] - for x in try! walk(AbsolutePath("/"), recursively: false) { + #endif + for x in try! walk(AbsolutePath("\(root)/"), recursively: false) { if let i = expected.firstIndex(of: x) { expected.remove(at: i) } + #if os(Android) + XCTAssertEqual(3, x.components.count) + #else XCTAssertEqual(2, x.components.count) + #endif } XCTAssertEqual(expected.count, 0) } diff --git a/Utilities/bootstrap b/Utilities/bootstrap index 7ddee121db4..266eb6b6b63 100755 --- a/Utilities/bootstrap +++ b/Utilities/bootstrap @@ -270,6 +270,10 @@ class Target(object): if args.llbuild_link_framework: other_args.extend(["-F", args.llbuild_build_dir]) + # Don't use GNU strerror_r on Android. + if 'ANDROID_DATA' in os.environ: + other_args.extend(["-Xcc", "-U_GNU_SOURCE"]) + print(" import-paths: %s" % json.dumps(import_paths), file=output) print(" other-args: %s" % json.dumps(other_args), file=output) @@ -681,7 +685,7 @@ def process_runtime_libraries(build, args, lib_path): cmd = [args.swiftc_path, "-emit-library", "-o", runtime_lib_path, "-Xlinker", "--whole-archive", "-Xlinker", input_lib_path, - "-Xlinker", "--no-whole-archive", "-lswiftGlibc", + "-Xlinker", "--no-whole-archive", "-lswiftGlibc", "-lFoundation", "-Xlinker", "-rpath=$ORIGIN/../../linux"] # We need to pass one swift file here to bypass the "no input files" @@ -1024,7 +1028,14 @@ def main(): if platform.system() == 'Darwin': build_target = "x86_64-apple-macosx" elif platform.system() == 'Linux': - if platform.machine() == 'x86_64': + if 'ANDROID_DATA' in os.environ: + if platform.machine().startswith("armv7"): + build_target = 'armv7-unknown-linux-androideabi' + elif platform.machine() == 'aarch64': + build_target = 'aarch64-unknown-linux-android' + else: + raise SystemExit("ERROR: unsupported Android platform:",platform.machine()) + elif platform.machine() == 'x86_64': build_target = "x86_64-unknown-linux-gnu" elif platform.machine() == "i686": build_target = "i686-unknown-linux" @@ -1175,6 +1186,10 @@ def main(): # Append the versioning build flags. build_flags.extend(create_versoning_args(args)) + # Don't use GNU strerror_r on Android. + if 'ANDROID_DATA' in os.environ: + build_flags.extend(["-Xswiftc", "-Xcc", "-Xswiftc", "-U_GNU_SOURCE"]) + # Add llbuild import flags. for import_path in llbuild_import_paths(args): build_flags.extend(["-Xswiftc", "-I%s" % import_path])