Skip to content

Commit c66eb4f

Browse files
committed
Teach swift package add-target to use the host toolchain's configuration
This allows us to pick up the appropriate swift-syntax version from the host toolchain, rather than using the hard-coded one.
1 parent 2b6df0a commit c66eb4f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Sources/Commands/PackageCommands/AddTarget.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ extension SwiftPackageCommand {
113113

114114
let editResult = try PackageModelSyntax.AddTarget.addTarget(
115115
target,
116-
to: manifestSyntax
116+
to: manifestSyntax,
117+
installedSwiftPMConfiguration: swiftCommandState
118+
.getHostToolchain()
119+
.installedSwiftPMConfiguration
117120
)
118121

119122
try editResult.applyEdits(

Sources/PackageModelSyntax/AddTarget.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public struct AddTarget {
3535
/// new target.
3636
public static func addTarget(
3737
_ target: TargetDescription,
38-
to manifest: SourceFileSyntax
38+
to manifest: SourceFileSyntax,
39+
installedSwiftPMConfiguration: InstalledSwiftPMConfiguration = .default
3940
) throws -> PackageEditResult {
4041
// Make sure we have a suitable tools version in the manifest.
4142
try manifest.checkEditManifestToolsVersion()
@@ -99,7 +100,9 @@ public struct AddTarget {
99100
if !manifest.description.contains("swift-syntax") {
100101
newPackageCall = try AddPackageDependency
101102
.addPackageDependencyLocal(
102-
.swiftSyntax,
103+
.swiftSyntax(
104+
configuration: installedSwiftPMConfiguration
105+
),
103106
to: newPackageCall
104107
)
105108

@@ -279,9 +282,10 @@ fileprivate extension PackageDependency {
279282
}
280283

281284
/// Package dependency on the swift-syntax package.
282-
static var swiftSyntax: PackageDependency {
283-
let swiftSyntaxVersionDefault = InstalledSwiftPMConfiguration
284-
.default
285+
static func swiftSyntax(
286+
configuration: InstalledSwiftPMConfiguration
287+
) -> PackageDependency {
288+
let swiftSyntaxVersionDefault = configuration
285289
.swiftSyntaxVersionForMacroTemplate
286290
let swiftSyntaxVersion = Version(swiftSyntaxVersionDefault.description)!
287291

0 commit comments

Comments
 (0)