Skip to content

Commit 1cbb77a

Browse files
committed
Pass the correct toolchain path to SwiftBuild
SwiftBuild can be initialized with either an Xcode-based developer directory for a Swift toolchain based developer directory, pass the right flags to initialize properly based on what kind of toolchain is in use.
1 parent ed2dfbb commit 1cbb77a

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

Sources/PackageModel/Toolchain.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ extension Toolchain {
8888
}
8989
}
9090

91+
public var toolchainDir: AbsolutePath {
92+
get throws {
93+
try resolveSymlinks(swiftCompilerPath)
94+
.parentDirectory // bin
95+
.parentDirectory // usr
96+
.parentDirectory // <toolchain>
97+
}
98+
}
99+
91100
public var toolchainLibDir: AbsolutePath {
92101
get throws {
93102
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,21 @@ func withService(
5959
func withSession(
6060
service: SWBBuildService,
6161
name: String,
62+
toolchainPath: Basics.AbsolutePath,
6263
packageManagerResourcesDirectory: Basics.AbsolutePath?,
6364
body: @escaping (
6465
_ session: SWBBuildServiceSession,
6566
_ diagnostics: [SwiftBuild.SwiftBuildMessage.DiagnosticInfo]
6667
) async throws -> Void
6768
) async throws {
68-
switch await service.createSession(name: name, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil) {
69+
// SWIFT_EXEC and SWIFT_EXEC_MANIFEST may need to be overridden in debug scenarios in order to pick up Open Source toolchains
70+
let sessionResult = if toolchainPath.components.contains(where: { $0.hasSuffix(".xctoolchain") }) {
71+
await service.createSession(name: name, developerPath: nil, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil)
72+
} else {
73+
await service.createSession(name: name, swiftToolchainPath: toolchainPath.pathString, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil)
74+
}
75+
76+
switch sessionResult {
6977
case (.success(let session), let diagnostics):
7078
do {
7179
try await body(session, diagnostics)
@@ -260,7 +268,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
260268
)
261269

262270
do {
263-
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in
271+
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, toolchainPath: self.buildParameters.toolchain.toolchainDir, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in
264272
self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n")
265273

266274
// Load the workspace, and set the system information to the default

0 commit comments

Comments
 (0)