From 99f53dc12e7a9711c05358f0ab86ae8e41c69f2d Mon Sep 17 00:00:00 2001 From: Owen Voorhees Date: Tue, 8 Apr 2025 10:25:53 -0700 Subject: [PATCH] Initialize Swift Build with a toolchain-based developer directory --- .../SwiftBuildSupport/SwiftBuildSystem.swift | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift index 9127648ce3f..3f96e7075ca 100644 --- a/Sources/SwiftBuildSupport/SwiftBuildSystem.swift +++ b/Sources/SwiftBuildSupport/SwiftBuildSystem.swift @@ -62,13 +62,22 @@ func withService( func withSession( service: SWBBuildService, name: String, + toolchainPath: String, packageManagerResourcesDirectory: Basics.AbsolutePath?, body: @escaping ( _ session: SWBBuildServiceSession, _ diagnostics: [SwiftBuild.SwiftBuildMessage.DiagnosticInfo] ) async throws -> Void ) async throws { - switch await service.createSession(name: name, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil) { + switch await service.createSession( + name: name, + swiftToolchainPath: toolchainPath, + resourceSearchPaths: packageManagerResourcesDirectory.map { + [$0.pathString] + } ?? [], + cachePath: nil, inferiorProductsPath: nil, + environment: nil + ) { case (.success(let session), let diagnostics): do { try await body(session, diagnostics) @@ -265,7 +274,16 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem { ) do { - try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in + let toolchainPath = self.buildParameters.toolchain.swiftCompilerPath + .parentDirectory // remove swift + .parentDirectory // remove bin + .parentDirectory // remove usr + try await withSession( + service: service, + name: self.buildParameters.pifManifest.pathString, + toolchainPath: toolchainPath.pathString, + packageManagerResourcesDirectory: self.packageManagerResourcesDirectory + ) { session, _ in self.outputStream.send("Building for \(self.buildParameters.configuration == .debug ? "debugging" : "production")...\n") // Load the workspace, and set the system information to the default