Skip to content

Initialize Swift Build with a toolchain-based developer directory #8464

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
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
22 changes: 20 additions & 2 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the toolchain base path should also be part of the Toolchain protocol itself rather than expanded here in SwiftBuildSystem.

Also because on some platforms it's usr/local/bin instead of usr/local, so I'd rather that logic be kept In UserToolchain itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's not an obvious way to add that requirement right now because the SwiftPM-level toolchain type conflates toolchains, SDKs, and cross compilation bundles

.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
Expand Down