1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Basics
public protocol Toolchain {
/// Path of the librarian.
var librarianPath: AbsolutePath { get }
/// Path of the `swiftc` compiler.
var swiftCompilerPath: AbsolutePath { get }
/// Path to `lib/swift`
var swiftResourcesPath: AbsolutePath? { get }
/// Path to `lib/swift_static`
var swiftStaticResourcesPath: AbsolutePath? { get }
/// Path containing the macOS Swift stdlib.
var macosSwiftStdlib: AbsolutePath { get throws }
/// An array of paths to search for headers and modules at compile time.
var includeSearchPaths: [AbsolutePath] { get }
/// An array of paths to search for libraries at link time.
var librarySearchPaths: [AbsolutePath] { get }
/// Configuration from the used toolchain.
var installedSwiftPMConfiguration: InstalledSwiftPMConfiguration { get }
/// The root path to the Swift SDK used by this toolchain.
var sdkRootPath: AbsolutePath? { get }
/// Path of the `clang` compiler.
func getClangCompiler() throws -> AbsolutePath
// FIXME: This is a temporary API until index store is widely available in
// the OSS clang compiler. This API should not used for any other purpose.
/// Returns true if clang compiler's vendor is Apple and nil if unknown.
func _isClangCompilerVendorApple() throws -> Bool?
/// Additional flags to be passed to the build tools.
var extraFlags: BuildFlags { get }
/// Additional flags to be passed to the C compiler.
@available(*, deprecated, message: "use extraFlags.cCompilerFlags instead")
var extraCCFlags: [String] { get }
/// Additional flags to be passed to the Swift compiler.
@available(*, deprecated, message: "use extraFlags.swiftCompilerFlags instead")
var extraSwiftCFlags: [String] { get }
/// Additional flags to be passed to the C++ compiler.
@available(*, deprecated, message: "use extraFlags.cxxCompilerFlags instead")
var extraCPPFlags: [String] { get }
}
extension Toolchain {
public func _isClangCompilerVendorApple() throws -> Bool? {
return nil
}
public var hostLibDir: AbsolutePath {
get throws {
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
components: ["swift", "host"]
)
}
}
public var macosSwiftStdlib: AbsolutePath {
get throws {
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath).appending(
components: ["swift", "macosx"]
)
}
}
public var toolchainLibDir: AbsolutePath {
get throws {
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.
try Self.toolchainLibDir(swiftCompilerPath: self.swiftCompilerPath)
}
}
/// Returns the appropriate Swift resources directory path.
///
/// - Parameter static: Controls whether to use the static or dynamic
/// resources directory.
public func swiftResourcesPath(isStatic: Bool) -> AbsolutePath? {
isStatic ? swiftStaticResourcesPath : swiftResourcesPath
}
public var extraCCFlags: [String] {
extraFlags.cCompilerFlags
}
public var extraCPPFlags: [String] {
extraFlags.cxxCompilerFlags
}
public var extraSwiftCFlags: [String] {
extraFlags.swiftCompilerFlags
}
package static func toolchainLibDir(swiftCompilerPath: AbsolutePath) throws -> AbsolutePath {
try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
}
}
|