Skip to content

Don't pass / as default sysroot on Linux #2797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/Workspace/Destination.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct Destination: Encodable, Equatable {
public var archs: [String] = []

/// The SDK used to compile for the destination.
public var sdk: AbsolutePath
public var sdk: AbsolutePath?

/// The binDir in the containing the compilers/linker to be used for the compilation.
public var binDir: AbsolutePath
Expand All @@ -58,7 +58,7 @@ public struct Destination: Encodable, Equatable {
/// Creates a compilation destination with the specified properties.
public init(
target: Triple? = nil,
sdk: AbsolutePath,
sdk: AbsolutePath?,
binDir: AbsolutePath,
extraCCFlags: [String] = [],
extraSwiftCFlags: [String] = [],
Expand Down Expand Up @@ -142,7 +142,7 @@ public struct Destination: Encodable, Equatable {
#else
return Destination(
target: nil,
sdk: .root,
sdk: nil,
binDir: binDir,
extraCCFlags: ["-fPIC"],
extraSwiftCFlags: [],
Expand Down
22 changes: 15 additions & 7 deletions Sources/Workspace/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,14 @@ public final class UserToolchain: Toolchain {
}

public static func deriveSwiftCFlags(triple: Triple, destination: Destination) -> [String] {
return (triple.isDarwin() || triple.isAndroid() || triple.isWASI()
? ["-sdk", destination.sdk.pathString]
: [])
+ destination.extraSwiftCFlags
guard let sdk = destination.sdk else {
return destination.extraSwiftCFlags
}

return (triple.isDarwin() || triple.isAndroid() || triple.isWASI()
? ["-sdk", sdk.pathString]
: [])
+ destination.extraSwiftCFlags
}

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

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

self.extraCCFlags = [
triple.isDarwin() ? "-isysroot" : "--sysroot", destination.sdk.pathString
] + destination.extraCCFlags
if let sdk = destination.sdk {
self.extraCCFlags = [
triple.isDarwin() ? "-isysroot" : "--sysroot", sdk.pathString
] + destination.extraCCFlags
} else {
self.extraCCFlags = destination.extraCCFlags
}

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