Skip to content

Pass the correct toolchain path to SwiftBuild #8696

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions Sources/PackageModel/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@ extension Toolchain {
}
}

public var toolchainDir: AbsolutePath {
get throws {
try resolveSymlinks(swiftCompilerPath)
.parentDirectory // bin
.parentDirectory // usr
.parentDirectory // <toolchain>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably breaks for some platforms like FreeBSD where there's an expectation of using /usr/local but will handle that in a future change.

}
}

public var toolchainLibDir: AbsolutePath {
get throws {
// FIXME: Not sure if it's better to base this off of Swift compiler or our own binary.
Expand Down
12 changes: 10 additions & 2 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ func withService(
func withSession(
service: SWBBuildService,
name: String,
toolchainPath: Basics.AbsolutePath,
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) {
// SWIFT_EXEC and SWIFT_EXEC_MANIFEST may need to be overridden in debug scenarios in order to pick up Open Source toolchains
let sessionResult = if toolchainPath.components.contains(where: { $0.hasSuffix(".xctoolchain") }) {
await service.createSession(name: name, developerPath: nil, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil)
} else {
await service.createSession(name: name, swiftToolchainPath: toolchainPath.pathString, resourceSearchPaths: packageManagerResourcesDirectory.map { [$0.pathString] } ?? [], cachePath: nil, inferiorProductsPath: nil, environment: nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went back and forth on whether this should use the toolchain from build params or the toolchain this SwiftPM is installed in. I think I've decided I'm happy with this approach though

}

switch sessionResult {
case (.success(let session), let diagnostics):
do {
try await body(session, diagnostics)
Expand Down Expand Up @@ -260,7 +268,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
)

do {
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, packageManagerResourcesDirectory: self.packageManagerResourcesDirectory) { session, _ in
try await withSession(service: service, name: self.buildParameters.pifManifest.pathString, toolchainPath: self.buildParameters.toolchain.toolchainDir, 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
Expand Down