Skip to content

Commit 4001857

Browse files
committed
WIP: Add linkage of SwiftSyntax, to set the stage for future PRs that need it. The way in which this is done is based on #3034 but it's possible we'll need to tweak it. It's not great to only get the dependency in 5.5 or later but there might not be much to do about that if the compiler ABI changed.
1 parent fb32460 commit 4001857

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

Package.swift

+38-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This allows some clients (such as IDEs) that use SwiftPM's data model but not it
1919
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
2020
though that could break some clients.
2121
*/
22-
let swiftPMDataModelProduct = (
22+
var swiftPMDataModelProduct = (
2323
name: "SwiftPMDataModel",
2424
targets: [
2525
"SourceControl",
@@ -33,6 +33,10 @@ let swiftPMDataModelProduct = (
3333
]
3434
)
3535

36+
#if compiler(>=5.5)
37+
swiftPMDataModelProduct.targets.append("PackageSyntax")
38+
#endif
39+
3640
/** The `libSwiftPM` set of interfaces to programmatically work with Swift
3741
packages. `libSwiftPM` includes all of the SwiftPM code except the
3842
command line tools, while `libSwiftPMDataModel` includes only the data model.
@@ -53,6 +57,14 @@ automatic linking type with `-auto` suffix appended to product's name.
5357
*/
5458
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]
5559

60+
var commandsDependencies: [Target.Dependency] = ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]
61+
var commandsSwiftSettings: [SwiftSetting]? = nil
62+
63+
#if compiler(>=5.5)
64+
commandsDependencies.append("PackageSyntax")
65+
commandsSwiftSettings = [.define("BUILD_PACKAGE_SYNTAX")]
66+
#endif
67+
5668
let package = Package(
5769
name: "SwiftPM",
5870
platforms: [
@@ -216,7 +228,8 @@ let package = Package(
216228
.target(
217229
/** High-level commands */
218230
name: "Commands",
219-
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]),
231+
dependencies: commandsDependencies,
232+
swiftSettings: commandsSwiftSettings),
220233
.target(
221234
/** The main executable provided by SwiftPM */
222235
name: "swift-package",
@@ -262,7 +275,8 @@ let package = Package(
262275
dependencies: ["Build", "SPMTestSupport"]),
263276
.testTarget(
264277
name: "CommandsTests",
265-
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build", "SourceControl"]),
278+
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build", "SourceControl"],
279+
swiftSettings: commandsSwiftSettings),
266280
.testTarget(
267281
name: "WorkspaceTests",
268282
dependencies: ["Workspace", "SPMTestSupport"]),
@@ -370,3 +384,24 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
370384
.package(path: "../swift-collections"),
371385
]
372386
}
387+
388+
389+
#if compiler(>=5.5)
390+
// SwiftSyntax depends on lib_InternalSwiftSyntaxParser from the toolchain,
391+
// which had an ABI break in Swift 5.5. As a result, we shouldn't attempt to
392+
// compile PackageSyntax with an earlier compiler version. Although PackageSyntax
393+
// should compile with any 5.5 compiler, it will only be functional when built
394+
// with a toolchain that has a compatible parser library.
395+
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
396+
package.dependencies += [.package(url: "https://github.com/apple/swift-syntax.git", .branch("release/5.5"))]
397+
} else {
398+
package.dependencies += [.package(path: "../swift-syntax")]
399+
}
400+
401+
package.targets += [
402+
.target(name: "PackageSyntax",
403+
dependencies: ["Workspace", "PackageModel", "PackageLoading",
404+
"SourceControl", "SwiftSyntax", "SwiftToolsSupport-auto"]),
405+
.testTarget(name: "PackageSyntaxTests", dependencies: ["PackageSyntax", "SPMTestSupport", "SwiftSyntax"]),
406+
]
407+
#endif

Sources/PackageSyntax/Lib.swift

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import SwiftSyntax
2+
3+
public func DoSomethingWithSwiftSyntax() throws -> String {
4+
let parsed = try SyntaxParser.parse(source: "let abc = 42")
5+
return parsed.description
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
13+
import PackageSyntax
14+
import SPMTestSupport
15+
16+
final class PackageSyntaxTests: XCTestCase {
17+
18+
func testDoingSomethingWithSwiftSyntax() throws {
19+
XCTAssertEqual(try DoSomethingWithSwiftSyntax(), "let abc = 42")
20+
}
21+
}
22+

0 commit comments

Comments
 (0)