Skip to content

Commit ef1727d

Browse files
committed
Fix hot reloading for Swift 6.0+
1 parent 7a3ee20 commit ef1727d

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

Sources/SwiftBundler/Bundler/SwiftPackageManager/SwiftPackageManager.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,6 @@ enum SwiftPackageManager {
133133
buildContext: BuildContext
134134
) async -> Result<URL, SwiftPackageManagerError> {
135135
#if os(macOS)
136-
// TODO: Package up 'build options' into a struct so that it can be passed around
137-
// more easily
138136
let productsDirectory: URL
139137
switch await SwiftPackageManager.getProductsDirectory(buildContext) {
140138
case let .success(value):
@@ -164,9 +162,21 @@ enum SwiftPackageManager {
164162
return .failure(.failedToDecodeBuildPlan(error))
165163
}
166164

167-
let commandName = "C.\(product)-\(buildContext.configuration).exe"
165+
let targetInfo: SwiftTargetInfo
166+
switch await getTargetInfo() {
167+
case .success(let value):
168+
targetInfo = value
169+
case .failure(let error):
170+
return .failure(error)
171+
}
172+
173+
// Swift versions before 6.0 or so named commands differently in the build plan.
174+
// We check for the newer format (with triple) then the older format (no triple).
175+
let triple = targetInfo.target.triple
176+
let commandName = "C.\(product)-\(triple)-\(buildContext.configuration).exe"
177+
let oldCommandName = "C.\(product)-\(buildContext.configuration).exe"
168178
guard
169-
let linkCommand = buildPlan.commands[commandName],
179+
let linkCommand = buildPlan.commands[commandName] ?? buildPlan.commands[oldCommandName],
170180
linkCommand.tool == "shell",
171181
let commandExecutable = linkCommand.arguments?.first,
172182
let arguments = linkCommand.arguments?.dropFirst()

Sources/SwiftBundler/Bundler/SwiftPackageManager/SwiftTargetInfo.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Foundation
77
struct SwiftTargetInfo: Codable {
88
/// Info about a target platform.
99
struct Target: Codable {
10+
/// The platform's versioned triple.
11+
var triple: String
1012
/// The platform's unversioned triple.
1113
var unversionedTriple: String
1214
}

Sources/SwiftBundler/Commands/RunCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ struct RunCommand: ErrorHandledCommand {
114114
let additionalEnvironmentVariables: [String: String]
115115
#if SUPPORT_HOT_RELOADING
116116
if hot {
117-
var port: UInt16 = 7000
117+
var port: UInt16 = 7331
118118

119119
/// Attempt to create the socket and retry with a new port if the address is
120120
/// already in use.

0 commit comments

Comments
 (0)