Skip to content

Commit 38b9756

Browse files
authored
Merge pull request #2797 from drexin/wip-fix-sysroot
Don't pass / as default sysroot on Linux
2 parents 4fc9f0f + e5e1bea commit 38b9756

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Sources/Workspace/Destination.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public struct Destination: Encodable, Equatable {
4141
public var archs: [String] = []
4242

4343
/// The SDK used to compile for the destination.
44-
public var sdk: AbsolutePath
44+
public var sdk: AbsolutePath?
4545

4646
/// The binDir in the containing the compilers/linker to be used for the compilation.
4747
public var binDir: AbsolutePath
@@ -58,7 +58,7 @@ public struct Destination: Encodable, Equatable {
5858
/// Creates a compilation destination with the specified properties.
5959
public init(
6060
target: Triple? = nil,
61-
sdk: AbsolutePath,
61+
sdk: AbsolutePath?,
6262
binDir: AbsolutePath,
6363
extraCCFlags: [String] = [],
6464
extraSwiftCFlags: [String] = [],
@@ -142,7 +142,7 @@ public struct Destination: Encodable, Equatable {
142142
#else
143143
return Destination(
144144
target: nil,
145-
sdk: .root,
145+
sdk: nil,
146146
binDir: binDir,
147147
extraCCFlags: ["-fPIC"],
148148
extraSwiftCFlags: [],

Sources/Workspace/UserToolchain.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,14 @@ public final class UserToolchain: Toolchain {
206206
}
207207

208208
public static func deriveSwiftCFlags(triple: Triple, destination: Destination) -> [String] {
209-
return (triple.isDarwin() || triple.isAndroid() || triple.isWASI()
210-
? ["-sdk", destination.sdk.pathString]
211-
: [])
212-
+ destination.extraSwiftCFlags
209+
guard let sdk = destination.sdk else {
210+
return destination.extraSwiftCFlags
211+
}
212+
213+
return (triple.isDarwin() || triple.isAndroid() || triple.isWASI()
214+
? ["-sdk", sdk.pathString]
215+
: [])
216+
+ destination.extraSwiftCFlags
213217
}
214218

215219
public init(destination: Destination, environment: [String: String] = ProcessEnv.vars) throws {
@@ -252,9 +256,13 @@ public final class UserToolchain: Toolchain {
252256

253257
self.extraSwiftCFlags = UserToolchain.deriveSwiftCFlags(triple: triple, destination: destination)
254258

255-
self.extraCCFlags = [
256-
triple.isDarwin() ? "-isysroot" : "--sysroot", destination.sdk.pathString
257-
] + destination.extraCCFlags
259+
if let sdk = destination.sdk {
260+
self.extraCCFlags = [
261+
triple.isDarwin() ? "-isysroot" : "--sysroot", sdk.pathString
262+
] + destination.extraCCFlags
263+
} else {
264+
self.extraCCFlags = destination.extraCCFlags
265+
}
258266

259267
// Compute the path of directory containing the PackageDescription libraries.
260268
var pdLibDir = UserManifestResources.libDir(forBinDir: binDir)

0 commit comments

Comments
 (0)