Skip to content

Commit 3d239c9

Browse files
committed
Pass the correct toolchain path to SwiftBuild on Windows and FreeBSD
Amendment to #8696 which computes the correct path on Windows and FreeBSD, which use different install layouts from the other platforms.
1 parent 612d503 commit 3d239c9

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

Sources/Basics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ add_library(Basics
6060
Netrc.swift
6161
Observability.swift
6262
OSSignpost.swift
63+
Process.swift
6364
ProgressAnimation/NinjaProgressAnimation.swift
6465
ProgressAnimation/PercentProgressAnimation.swift
6566
ProgressAnimation/ProgressAnimationProtocol.swift

Sources/_InternalTestSupport/Process.swift renamed to Sources/Basics/Process.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,24 @@ public enum OperatingSystem: Hashable, Sendable {
1515
case windows
1616
case linux
1717
case android
18+
case freebsd
1819
case unknown
1920
}
2021

2122
extension ProcessInfo {
22-
#if os(macOS)
23-
public static let hostOperatingSystem = OperatingSystem.macOS
24-
#elseif os(Linux)
25-
public static let hostOperatingSystem = OperatingSystem.linux
26-
#elseif os(Windows)
27-
public static let hostOperatingSystem = OperatingSystem.windows
28-
#else
29-
public static let hostOperatingSystem = OperatingSystem.unknown
30-
#endif
23+
public static var hostOperatingSystem: OperatingSystem {
24+
#if os(macOS)
25+
.macOS
26+
#elseif os(Linux)
27+
.linux
28+
#elseif os(Windows)
29+
.windows
30+
#elseif os(FreeBSD)
31+
.freebsd
32+
#else
33+
.unknown
34+
#endif
35+
}
3136

3237
#if os(Windows)
3338
public static let EOL = "\r\n"

Sources/PackageModel/Toolchain.swift

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import Foundation
1415

1516
public protocol Toolchain {
1617
/// Path of the librarian.
@@ -88,12 +89,33 @@ extension Toolchain {
8889
}
8990
}
9091

92+
/// Base toolchain path that's given to Swift Build to initialize its core.
9193
public var toolchainDir: AbsolutePath {
9294
get throws {
93-
try resolveSymlinks(swiftCompilerPath)
94-
.parentDirectory // bin
95-
.parentDirectory // usr
96-
.parentDirectory // <toolchain>
95+
let compilerPath = try resolveSymlinks(swiftCompilerPath)
96+
let os = ProcessInfo.hostOperatingSystem
97+
switch os {
98+
case .windows:
99+
return compilerPath
100+
.parentDirectory // bin
101+
.parentDirectory // usr
102+
.parentDirectory // <version>
103+
.parentDirectory // Toolchains
104+
.parentDirectory // <toolchain>
105+
case .macOS, .linux, .android:
106+
return compilerPath
107+
.parentDirectory // bin
108+
.parentDirectory // usr
109+
.parentDirectory // <toolchain>
110+
case .freebsd:
111+
return compilerPath
112+
.parentDirectory // bin
113+
.parentDirectory // local
114+
.parentDirectory // usr
115+
.parentDirectory // <toolchain>
116+
case .unknown:
117+
throw UnknownToolchainLayout(os: os)
118+
}
97119
}
98120
}
99121

@@ -128,3 +150,10 @@ extension Toolchain {
128150
try AbsolutePath(validating: "../../lib", relativeTo: resolveSymlinks(swiftCompilerPath))
129151
}
130152
}
153+
154+
struct UnknownToolchainLayout: Error, CustomStringConvertible {
155+
let os: OperatingSystem
156+
var description: String {
157+
"Unknown toolchain layout for host operating system: \(os)"
158+
}
159+
}

Sources/_InternalTestSupport/SkippedTestSupport.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import class Foundation.FileManager
1313
import class Foundation.ProcessInfo
14+
import Basics
1415
import Testing
1516

1617
extension Trait where Self == Testing.ConditionTrait {

0 commit comments

Comments
 (0)