Skip to content

Commit a7f8f9f

Browse files
authored
[Unix] Use the new -sysroot flag for all non-Darwin Unix platforms, not just Android (#1811) (#1819)
This makes two changes: 1. Use the new flag on all Unix platforms, as in the original frontend pull where it was introduced, swiftlang/swift#72352. 2. When compiling for Android and `ANDROID_NDK_ROOT` is unset, fall back to the `-sdk` as the sysroot when linking.
1 parent baf18cf commit a7f8f9f

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ extension GenericUnixToolchain {
223223
commandLine.appendPath(try VirtualPath(path: opt.argument.asSingle))
224224
}
225225

226-
if targetTriple.environment == .android {
227-
if let sysroot = parsedOptions.getLastArgument(.sysroot)?.asSingle {
228-
commandLine.appendFlag("--sysroot")
229-
try commandLine.appendPath(VirtualPath(path: sysroot))
230-
} else if let sysroot = AndroidNDK.getDefaultSysrootPath(in: self.env) {
231-
commandLine.appendFlag("--sysroot")
232-
try commandLine.appendPath(VirtualPath(path: sysroot.pathString))
233-
}
226+
if let sysroot = parsedOptions.getLastArgument(.sysroot)?.asSingle {
227+
commandLine.appendFlag("--sysroot")
228+
try commandLine.appendPath(VirtualPath(path: sysroot))
229+
} else if targetTriple.environment == .android,
230+
let sysroot = AndroidNDK.getDefaultSysrootPath(in: self.env)
231+
{
232+
commandLine.appendFlag("--sysroot")
233+
try commandLine.appendPath(VirtualPath(path: sysroot.pathString))
234234
} else if let path = targetInfo.sdkPath?.path {
235235
commandLine.appendFlag("--sysroot")
236236
commandLine.appendPath(VirtualPath.lookup(path))

Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ public final class GenericUnixToolchain: Toolchain {
152152
frontendTargetInfo: FrontendTargetInfo,
153153
driver: inout Driver
154154
) throws {
155-
if driver.targetTriple.environment == .android {
156-
if let sysroot = driver.parsedOptions.getLastArgument(.sysroot)?.asSingle {
157-
commandLine.appendFlag("-sysroot")
158-
try commandLine.appendPath(VirtualPath(path: sysroot))
159-
} else if let sysroot = AndroidNDK.getDefaultSysrootPath(in: self.env) {
160-
commandLine.appendFlag("-sysroot")
161-
try commandLine.appendPath(VirtualPath(path: sysroot.pathString))
162-
}
155+
if let sysroot = driver.parsedOptions.getLastArgument(.sysroot)?.asSingle {
156+
commandLine.appendFlag("-sysroot")
157+
try commandLine.appendPath(VirtualPath(path: sysroot))
158+
} else if driver.targetTriple.environment == .android,
159+
let sysroot = AndroidNDK.getDefaultSysrootPath(in: self.env)
160+
{
161+
commandLine.appendFlag("-sysroot")
162+
try commandLine.appendPath(VirtualPath(path: sysroot.pathString))
163163
}
164164
}
165165
}

Tests/SwiftDriverTests/SwiftDriverTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -8149,7 +8149,7 @@ final class SwiftDriverTests: XCTestCase {
81498149
do {
81508150
let sysroot = path.appending(component: "sysroot")
81518151
var driver = try Driver(args: [
8152-
"swiftc", "-target", "aarch64-unknown-linux-android", "-sysroot", sysroot.pathString, #file
8152+
"swiftc", "-target", "aarch64-unknown-linux-gnu", "-sysroot", sysroot.pathString, #file
81538153
], env: env)
81548154
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
81558155
let frontend = try XCTUnwrap(jobs.first)

0 commit comments

Comments
 (0)