Skip to content

Commit bad178b

Browse files
committed
[CMake] Implement CMake support for the package manifest editing commands
Start building package editing commands with the CMake build system as well, using FetchContent to get the swift-syntax libraries.
1 parent 3ff45aa commit bad178b

File tree

6 files changed

+159
-1
lines changed

6 files changed

+159
-1
lines changed
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
SET(SWIFTPM_PATH_TO_SWIFT_SYNTAX_SOURCE ${CMAKE_SOURCE_DIR}/../swift-syntax)
2+
message(STATUS "swift-syntax path: ${SWIFTPM_PATH_TO_SWIFT_SYNTAX_SOURCE}")
3+
4+
include(FetchContent)
5+
6+
if(NOT EXISTS "${SWIFTPM_PATH_TO_SWIFT_SYNTAX_SOURCE}")
7+
message(SEND_ERROR "swift-syntax is required to build SwiftPM. Please run update-checkout or specify SWIFTPM_PATH_TO_SWIFT_SYNTAX_SOURCE")
8+
return()
9+
endif()
10+
11+
# Build swift-syntax libraries with FetchContent.
12+
# set(CMAKE_Swift_COMPILER_TARGET ${SWIFT_HOST_TRIPLE})
13+
set(BUILD_SHARED_LIBS OFF)
14+
15+
file(TO_CMAKE_PATH "${SWIFTPM_PATH_TO_SWIFT_SYNTAX_SOURCE}" swift_syntax_path)
16+
FetchContent_Declare(SwiftSyntax SOURCE_DIR "${swift_syntax_path}")
17+
FetchContent_MakeAvailable(SwiftSyntax)

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ find_package(SQLite3 REQUIRED)
5454
# Enable `package` modifier for the whole package.
5555
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:-package-name;SwiftPM>")
5656

57+
add_subdirectory(BuildSupport/SwiftSyntax)
5758
add_subdirectory(Sources)
5859
add_subdirectory(cmake/modules)

Package.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ let package = Package(
260260
.product(name: "SwiftParser", package: "swift-syntax"),
261261
.product(name: "SwiftSyntax", package: "swift-syntax"),
262262
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
263-
]
263+
],
264+
exclude: ["CMakeLists.txt"]
264265
),
265266

266267
.target(

Sources/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_subdirectory(PackageFingerprint)
2121
add_subdirectory(PackageGraph)
2222
add_subdirectory(PackageLoading)
2323
add_subdirectory(PackageModel)
24+
add_subdirectory(PackageModelSyntax)
2425
add_subdirectory(PackagePlugin)
2526
add_subdirectory(PackageRegistry)
2627
add_subdirectory(PackageSigning)

Sources/Commands/CMakeLists.txt

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# This source file is part of the Swift open source project
2+
#
3+
# Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(Commands
10+
PackageCommands/AddDependency.swift
11+
PackageCommands/AddTarget.swift
12+
PackageCommands/APIDiff.swift
13+
PackageCommands/ArchiveSource.swift
14+
PackageCommands/CompletionCommand.swift
15+
PackageCommands/ComputeChecksum.swift
16+
PackageCommands/Config.swift
17+
PackageCommands/Describe.swift
18+
PackageCommands/DumpCommands.swift
19+
PackageCommands/EditCommands.swift
20+
PackageCommands/Format.swift
21+
PackageCommands/Init.swift
22+
PackageCommands/InstalledPackages.swift
23+
PackageCommands/Learn.swift
24+
PackageCommands/PluginCommand.swift
25+
PackageCommands/ResetCommands.swift
26+
PackageCommands/Resolve.swift
27+
PackageCommands/ShowDependencies.swift
28+
PackageCommands/SwiftPackageCommand.swift
29+
PackageCommands/ToolsVersionCommand.swift
30+
PackageCommands/Update.swift
31+
Snippets/CardEvent.swift
32+
Snippets/Cards/SnippetCard.swift
33+
Snippets/Cards/SnippetGroupCard.swift
34+
Snippets/Cards/TopCard.swift
35+
Snippets/CardStack.swift
36+
Snippets/Card.swift
37+
Snippets/Colorful.swift
38+
SwiftBuildCommand.swift
39+
SwiftRunCommand.swift
40+
SwiftTestCommand.swift
41+
CommandWorkspaceDelegate.swift
42+
Utilities/APIDigester.swift
43+
Utilities/DependenciesSerializer.swift
44+
Utilities/DescribedPackage.swift
45+
Utilities/DOTManifestSerializer.swift
46+
Utilities/MermaidPackageSerializer.swift
47+
Utilities/MultiRootSupport.swift
48+
Utilities/PlainTextEncoder.swift
49+
Utilities/PluginDelegate.swift
50+
Utilities/SymbolGraphExtract.swift
51+
Utilities/TestingSupport.swift
52+
Utilities/XCTEvents.swift)
53+
target_link_libraries(Commands PUBLIC
54+
SwiftCollections::OrderedCollections
55+
ArgumentParser
56+
Basics
57+
Build
58+
CoreCommands
59+
LLBuildManifest
60+
PackageGraph
61+
PackageModelSyntax
62+
SourceControl
63+
TSCBasic
64+
TSCUtility
65+
Workspace
66+
XCBuildSupport)
67+
target_link_libraries(Commands PRIVATE
68+
DriverSupport
69+
$<$<NOT:$<PLATFORM_ID:Darwin>>:FoundationXML>)
70+
# NOTE(compnerd) workaround for CMake not setting up include flags yet
71+
set_target_properties(Commands PROPERTIES
72+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
73+
74+
install(TARGETS Commands
75+
ARCHIVE DESTINATION lib
76+
LIBRARY DESTINATION lib
77+
RUNTIME DESTINATION bin)
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This source file is part of the Swift open source project
2+
#
3+
# Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
add_library(PackageModelSyntax
10+
AddPackageDependency.swift
11+
AddTarget.swift
12+
ManifestEditError.swift
13+
ManifestSyntaxRepresentable.swift
14+
PackageDependency+Syntax.swift
15+
PackageEditResult.swift
16+
SyntaxEditUtils.swift
17+
TargetDescription+Syntax.swift
18+
)
19+
20+
target_link_libraries(PackageModelSyntax PUBLIC
21+
Basics
22+
PackageLoading
23+
PackageModel
24+
25+
SwiftBasicFormat
26+
SwiftDiagnostics
27+
SwiftIDEUtils
28+
SwiftParser
29+
SwiftSyntax
30+
SwiftSyntaxBuilder
31+
)
32+
33+
# NOTE(compnerd) workaround for CMake not setting up include flags yet
34+
set_target_properties(PackageModelSyntax PROPERTIES
35+
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
36+
37+
install(TARGETS PackageModelSyntax
38+
ARCHIVE DESTINATION lib
39+
LIBRARY DESTINATION lib
40+
RUNTIME DESTINATION bin)
41+
set_property(GLOBAL APPEND PROPERTY SwiftPM_EXPORTS PackageModelSyntax)
42+
43+
set(SWIFT_SYNTAX_MODULES
44+
SwiftBasicFormat
45+
SwiftParser
46+
SwiftParserDiagnostics
47+
SwiftDiagnostics
48+
SwiftSyntax
49+
SwiftOperators
50+
SwiftSyntaxBuilder
51+
SwiftSyntaxMacros
52+
SwiftSyntaxMacroExpansion
53+
SwiftCompilerPluginMessageHandling
54+
# Support for LSP
55+
SwiftIDEUtils
56+
SwiftRefactor
57+
)
58+
export(TARGETS ${SWIFT_SYNTAX_MODULES}
59+
NAMESPACE SwiftSyntax::
60+
FILE ${CMAKE_BINARY_DIR}/cmake/modules/SwiftSyntaxConfig.cmake
61+
EXPORT_LINK_INTERFACE_LIBRARIES)

0 commit comments

Comments
 (0)