Skip to content

WIP: Add linkage of SwiftSyntax, to set the stage for future PRs that need it. #3669

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

Closed
Closed
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
41 changes: 38 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This allows some clients (such as IDEs) that use SwiftPM's data model but not it
to not have to depend on SwiftDriver, SwiftLLBuild, etc. We should probably have better names here,
though that could break some clients.
*/
let swiftPMDataModelProduct = (
var swiftPMDataModelProduct = (
name: "SwiftPMDataModel",
targets: [
"SourceControl",
Expand All @@ -33,6 +33,10 @@ let swiftPMDataModelProduct = (
]
)

#if compiler(>=5.5)
Copy link
Contributor

Choose a reason for hiding this comment

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

should we just require 5.5 for SwiftPM?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we did, it would allow dropping some of the conditional compilation in the manifest, but some would still be necessary elsewhere to account for SwiftSyntax being missing from the first stage cmake build when bootstrapping. It's probably still worth doing so long as it doesn't interfere with SourceKit-LSP (which currently has a minimum of 5.3).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think some of the toolchain CI is still using an older Swift version, so that might be problematic. But it would be great to start being able to rely on synthesized Codable of enums in particular, and that requires 5.5.

swiftPMDataModelProduct.targets.append("PackageSyntax")
#endif

/** The `libSwiftPM` set of interfaces to programmatically work with Swift
packages. `libSwiftPM` includes all of the SwiftPM code except the
command line tools, while `libSwiftPMDataModel` includes only the data model.
Expand All @@ -53,6 +57,14 @@ automatic linking type with `-auto` suffix appended to product's name.
*/
let autoProducts = [swiftPMProduct, swiftPMDataModelProduct]

var commandsDependencies: [Target.Dependency] = ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]
var commandsSwiftSettings: [SwiftSetting]? = nil

#if compiler(>=5.5)
commandsDependencies.append("PackageSyntax")
commandsSwiftSettings = [.define("BUILD_PACKAGE_SYNTAX")]
#endif

let package = Package(
name: "SwiftPM",
platforms: [
Expand Down Expand Up @@ -219,7 +231,8 @@ let package = Package(
.target(
/** High-level commands */
name: "Commands",
dependencies: ["SwiftToolsSupport-auto", "Basics", "Build", "PackageGraph", "SourceControl", "Xcodeproj", "Workspace", "XCBuildSupport", "ArgumentParser", "PackageCollections"]),
dependencies: commandsDependencies,
swiftSettings: commandsSwiftSettings),
.target(
/** The main executable provided by SwiftPM */
name: "swift-package",
Expand Down Expand Up @@ -269,7 +282,8 @@ let package = Package(
dependencies: ["Build", "SPMTestSupport"]),
.testTarget(
name: "CommandsTests",
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build", "SourceControl"]),
dependencies: ["swift-build", "swift-package", "swift-test", "swift-run", "Commands", "Workspace", "SPMTestSupport", "Build", "SourceControl"],
swiftSettings: commandsSwiftSettings),
.testTarget(
name: "WorkspaceTests",
dependencies: ["Workspace", "SPMTestSupport"]),
Expand Down Expand Up @@ -378,3 +392,24 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
.package(path: "../swift-crypto"),
]
}


#if compiler(>=5.5)
// SwiftSyntax depends on lib_InternalSwiftSyntaxParser from the toolchain,
// which had an ABI break in Swift 5.5. As a result, we shouldn't attempt to
// compile PackageSyntax with an earlier compiler version. Although PackageSyntax
// should compile with any 5.5 compiler, it will only be functional when built
// with a toolchain that has a compatible parser library.
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [.package(url: "https://github.com/apple/swift-syntax.git", .branch(relatedDependenciesBranch))]
} else {
package.dependencies += [.package(path: "../swift-syntax")]
}

package.targets += [
.target(name: "PackageSyntax",
dependencies: ["Workspace", "PackageModel", "PackageLoading",
"SourceControl", "SwiftSyntax", "SwiftToolsSupport-auto"]),
.testTarget(name: "PackageSyntaxTests", dependencies: ["PackageSyntax", "SPMTestSupport", "SwiftSyntax"]),
]
#endif
7 changes: 7 additions & 0 deletions Sources/PackageSyntax/Lib.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SwiftSyntax

public func DoSomethingWithSwiftSyntax() throws -> String {
let parsed = try SyntaxParser.parse(source: "let abc = 42")
print(parsed)
return parsed.description
}
22 changes: 22 additions & 0 deletions Tests/PackageSyntaxTests/PackageSyntaxTest.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest

import PackageSyntax
import SPMTestSupport

final class PackageSyntaxTests: XCTestCase {

func testDoingSomethingWithSwiftSyntax() throws {
XCTAssertEqual(try DoSomethingWithSwiftSyntax(), "description")
}
}