Skip to content

Commit 2d80762

Browse files
committed
build: initial support for building with CMake
Add support for building with CMake which is required to get the toolchain bootstrapped. This partially addresses #7.
1 parent fbad654 commit 2d80762

File tree

29 files changed

+1296
-1
lines changed

29 files changed

+1296
-1
lines changed

CMakeLists.txt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright (c) 2014 - 2025 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+
cmake_minimum_required(VERSION 3.26...3.29)
12+
project(SwiftBuild
13+
LANGUAGES C CXX Swift)
14+
15+
set(CMAKE_C_VISIBILITY hidden)
16+
set(CMAKE_CXX_VISIBILITY hidden)
17+
set(CMAKE_CXX_STANDARD 17)
18+
set(CMAKE_CXX_STANDARD_REQUIRED YES)
19+
set(CMAKE_CXX_EXTENSIONS NO)
20+
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
21+
22+
option(SwiftBuild_USE_LLBUILD_FRAMEWORK "Use LLBuild Framework" NO)
23+
24+
set(SwiftBuild_LANGUAGE_VERSION_6 $<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>)
25+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name SwiftBuild>"
26+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ConciseMagicFile>"
27+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature DeprecateApplicationMain>"
28+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature DisableOutwardActorInference>"
29+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ForwardTrailingClosures>"
30+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature GlobalConcurrency>"
31+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ImplicitOpenExistentials>"
32+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ImplicitOpenExistentialsImportObjcForwardDeclarations>"
33+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature InferSendableFromCaptures>"
34+
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature IsolatedDefaultValues>"
35+
# rdar://137809703
36+
# "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature RegionBasedIsolation>"
37+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ExistentialAny>"
38+
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>")
39+
40+
# Prefer the static initialisation for the pluigns.
41+
add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION)
42+
43+
find_package(ArgumentParser)
44+
find_package(LLBuild)
45+
find_package(SwiftDriver)
46+
find_package(SwiftSystem)
47+
find_package(TSC)
48+
# NOTE: these two are required for LLBuild dependencies
49+
find_package(Threads)
50+
find_package(SQLite3)
51+
52+
add_subdirectory(Sources)

Package.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,21 @@ let package = Package(
8383
"SwiftBuild",
8484
"SWBBuildServiceBundle", // the CLI needs to launch the service bundle
8585
],
86+
exclude: ["CMakeLists.txt"],
8687
swiftSettings: swiftSettings(languageMode: .v6)),
8788
.executableTarget(
8889
name: "SWBBuildServiceBundle",
8990
dependencies: [
9091
"SWBBuildService", "SWBBuildSystem", "SWBServiceCore", "SWBUtil", "SWBCore",
9192
],
93+
exclude: ["CMakeLists.txt"],
9294
swiftSettings: swiftSettings(languageMode: .v6)),
9395

9496
// Libraries
9597
.target(
9698
name: "SwiftBuild",
9799
dependencies: ["SWBCSupport", "SWBCore", "SWBProtocol", "SWBUtil", "SWBProjectModel"],
100+
exclude: ["CMakeLists.txt"],
98101
swiftSettings: swiftSettings(languageMode: .v5)),
99102
.target(
100103
name: "SWBBuildService",
@@ -104,10 +107,12 @@ let package = Package(
104107
"SWBTaskExecution",
105108
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
106109
],
110+
exclude: ["CMakeLists.txt"],
107111
swiftSettings: swiftSettings(languageMode: .v5)),
108112
.target(
109113
name: "SWBBuildSystem",
110114
dependencies: ["SWBCore", "SWBTaskConstruction", "SWBTaskExecution"],
115+
exclude: ["CMakeLists.txt"],
111116
swiftSettings: swiftSettings(languageMode: .v5)),
112117
.target(
113118
name: "SWBCore",
@@ -120,6 +125,7 @@ let package = Package(
120125
.product(name: "SwiftDriver", package: "swift-driver"),
121126
"SWBLLBuild",
122127
],
128+
exclude: ["CMakeLists.txt"],
123129
swiftSettings: swiftSettings(languageMode: .v5),
124130
plugins: [
125131
.plugin(name: "SWBSpecificationsPlugin")
@@ -134,12 +140,13 @@ let package = Package(
134140
swiftSettings: swiftSettings(languageMode: .v6)),
135141
.target(
136142
name: "SWBCLibc",
137-
exclude: ["README.md"],
143+
exclude: ["CMakeLists.txt", "README.md"],
138144
publicHeadersPath: ".",
139145
swiftSettings: swiftSettings(languageMode: .v6)),
140146
.target(
141147
name: "SWBLibc",
142148
dependencies: ["SWBCLibc"],
149+
exclude: ["CMakeLists.txt"],
143150
swiftSettings: swiftSettings(languageMode: .v6)),
144151
.target(
145152
name: "SWBLLBuild",
@@ -149,33 +156,40 @@ let package = Package(
149156
.product(name: "libllbuild", package: useLocalDependencies ? "llbuild" : "swift-llbuild"),
150157
.product(name: "llbuildSwift", package: useLocalDependencies ? "llbuild" : "swift-llbuild"),
151158
]),
159+
exclude: ["CMakeLists.txt"],
152160
swiftSettings: swiftSettings(languageMode: .v6)),
153161
.target(
154162
name: "SWBMacro",
155163
dependencies: [
156164
"SWBUtil",
157165
.product(name: "SwiftDriver", package: "swift-driver"),
158166
],
167+
exclude: ["CMakeLists.txt"],
159168
swiftSettings: swiftSettings(languageMode: .v6)),
160169
.target(
161170
name: "SWBProjectModel",
162171
dependencies: ["SWBProtocol"],
172+
exclude: ["CMakeLists.txt"],
163173
swiftSettings: swiftSettings(languageMode: .v6)),
164174
.target(
165175
name: "SWBProtocol",
166176
dependencies: ["SWBUtil"],
177+
exclude: ["CMakeLists.txt"],
167178
swiftSettings: swiftSettings(languageMode: .v6)),
168179
.target(
169180
name: "SWBServiceCore",
170181
dependencies: ["SWBProtocol"],
182+
exclude: ["CMakeLists.txt"],
171183
swiftSettings: swiftSettings(languageMode: .v6)),
172184
.target(
173185
name: "SWBTaskConstruction",
174186
dependencies: ["SWBCore", "SWBUtil"],
187+
exclude: ["CMakeLists.txt"],
175188
swiftSettings: swiftSettings(languageMode: .v5)),
176189
.target(
177190
name: "SWBTaskExecution",
178191
dependencies: ["SWBCore", "SWBUtil", "SWBCAS", "SWBLLBuild", "SWBTaskConstruction"],
192+
exclude: ["CMakeLists.txt"],
179193
swiftSettings: swiftSettings(languageMode: .v5)),
180194
.target(
181195
name: "SWBUtil",
@@ -186,39 +200,48 @@ let package = Package(
186200
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .android])),
187201
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
188202
],
203+
exclude: ["CMakeLists.txt"],
189204
swiftSettings: swiftSettings(languageMode: .v5)),
190205
.target(
191206
name: "SWBCAS",
192207
dependencies: ["SWBUtil", "SWBCSupport"],
208+
exclude: ["CMakeLists.txt"],
193209
swiftSettings: swiftSettings(languageMode: .v6)),
194210

195211
.target(
196212
name: "SWBAndroidPlatform",
197213
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
214+
exclude: ["CMakeLists.txt"],
198215
swiftSettings: swiftSettings(languageMode: .v6)),
199216
.target(
200217
name: "SWBApplePlatform",
201218
dependencies: ["SWBCore", "SWBMacro", "SWBUtil", "SWBTaskConstruction"],
219+
exclude: ["CMakeLists.txt"],
202220
swiftSettings: swiftSettings(languageMode: .v6)),
203221
.target(
204222
name: "SWBGenericUnixPlatform",
205223
dependencies: ["SWBCore", "SWBUtil"],
224+
exclude: ["CMakeLists.txt"],
206225
swiftSettings: swiftSettings(languageMode: .v6)),
207226
.target(
208227
name: "SWBQNXPlatform",
209228
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
229+
exclude: ["CMakeLists.txt"],
210230
swiftSettings: swiftSettings(languageMode: .v6)),
211231
.target(
212232
name: "SWBUniversalPlatform",
213233
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
234+
exclude: ["CMakeLists.txt"],
214235
swiftSettings: swiftSettings(languageMode: .v6)),
215236
.target(
216237
name: "SWBWebAssemblyPlatform",
217238
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
239+
exclude: ["CMakeLists.txt"],
218240
swiftSettings: swiftSettings(languageMode: .v6)),
219241
.target(
220242
name: "SWBWindowsPlatform",
221243
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
244+
exclude: ["CMakeLists.txt"],
222245
swiftSettings: swiftSettings(languageMode: .v6)),
223246

224247
// Helper targets for SwiftPM

Sources/CMakeLists.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright (c) 2014 - 2025 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+
add_subdirectory(SWBCSupport)
12+
add_subdirectory(SWBCLibc)
13+
add_subdirectory(SWBLibc)
14+
add_subdirectory(SWBUtil)
15+
add_subdirectory(SWBMacro)
16+
add_subdirectory(SWBProtocol)
17+
add_subdirectory(SWBServiceCore)
18+
add_subdirectory(SWBCAS)
19+
add_subdirectory(SWBLLBuild)
20+
add_subdirectory(SWBCore)
21+
add_subdirectory(SWBTaskConstruction)
22+
add_subdirectory(SWBAndroidPlatform)
23+
add_subdirectory(SWBApplePlatform)
24+
add_subdirectory(SWBGenericUnixPlatform)
25+
add_subdirectory(SWBQNXPlatform)
26+
add_subdirectory(SWBUniversalPlatform)
27+
add_subdirectory(SWBWebAssemblyPlatform)
28+
add_subdirectory(SWBWindowsPlatform)
29+
add_subdirectory(SWBTaskExecution)
30+
add_subdirectory(SWBBuildSystem)
31+
add_subdirectory(SWBBuildService)
32+
add_subdirectory(SWBProjectModel)
33+
add_subdirectory(SwiftBuild)
34+
35+
add_subdirectory(swbuild)
36+
add_subdirectory(SWBBuildServiceBundle)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright (c) 2014 - 2025 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+
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12+
_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13+
file(CONFIGURE
14+
OUTPUT resource_bundle_accessor.swift
15+
CONTENT [[
16+
import Foundation
17+
extension Foundation.Bundle {
18+
static let module: Bundle = {
19+
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBAndroidPlatform.resources").path
20+
let buildPath = #"@_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBAndroidPlatform.resources"#
21+
let preferredBundle = Bundle(path: mainPath)
22+
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23+
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24+
}
25+
return bundle
26+
}()
27+
}
28+
]]
29+
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30+
31+
add_library(SWBAndroidPlatform STATIC
32+
AndroidSDK.swift
33+
Plugin.swift)
34+
target_link_libraries(SWBAndroidPlatform PUBLIC
35+
SWBCore
36+
SWBMacro
37+
SWBUtil)
38+
target_sources(SWBAndroidPlatform PRIVATE
39+
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright (c) 2014 - 2025 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+
file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
12+
_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
13+
file(CONFIGURE
14+
OUTPUT resource_bundle_accessor.swift
15+
CONTENT [[
16+
import Foundation
17+
extension Foundation.Bundle {
18+
static let module: Bundle = {
19+
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBApplePlatform.resources").path
20+
let buildPath = #"@_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBApplePlatform.resources"#
21+
let preferredBundle = Bundle(path: mainPath)
22+
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
23+
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
24+
}
25+
return bundle
26+
}()
27+
}
28+
]]
29+
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)
30+
31+
add_library(SWBApplePlatform STATIC
32+
Specs/AssetCatalogCompiler.swift
33+
Specs/CopyTiffFile.swift
34+
Specs/CoreDataCompiler.swift
35+
Specs/CoreMLCompiler.swift
36+
Specs/DittoTool.swift
37+
Specs/ExtensionPointsCompiler.swift
38+
Specs/IIGCompiler.swift
39+
Specs/InstrumentsPackageBuilderSpec.swift
40+
Specs/IntentsCompiler.swift
41+
Specs/InterfaceBuilderCompiler.swift
42+
Specs/InterfaceBuilderShared.swift
43+
Specs/MetalCompiler.swift
44+
Specs/MiGCompiler.swift
45+
Specs/OpenCLCompiler.swift
46+
Specs/RealityAssetsCompilerSpec.swift
47+
Specs/ReferenceObjectCompiler.swift
48+
Specs/ResMergerLinkerSpec.swift
49+
Specs/SceneKitToolSpec.swift
50+
Specs/StoryboardLinker.swift
51+
Specs/XCStringsCompiler.swift
52+
ActoolInputFileGroupingStrategy.swift
53+
AssetCatalogCompilerOutputParser.swift
54+
CMakeLists.txt
55+
DevelopmentAssetsTaskProducer.swift
56+
ImageScaleFactorsInputFileGroupingStrategy.swift
57+
InterfaceBuilderCompilerOutputParser.swift
58+
LocalizationInputFileGroupingStrategy.swift
59+
MacCatalystInfoExtension.swift
60+
Plugin.swift
61+
RealityAssetsTaskProducer.swift
62+
StringCatalogCompilerOutputParser.swift
63+
StubBinaryTaskProducer.swift
64+
XCStringsInputFileGroupingStrategy.swift)
65+
set_target_properties(SWBApplePlatform PROPERTIES
66+
Swift_LANGUAGE_VERSION 6)
67+
target_link_libraries(SWBApplePlatform PUBLIC
68+
SWBCore
69+
SWBMacro
70+
SWBUtil
71+
SWBProtocol
72+
SWBTaskConstruction)
73+
target_sources(SWBApplePlatform PRIVATE
74+
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright (c) 2014 - 2025 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+
add_library(SWBBuildService
12+
BuildDependencyInfo.swift
13+
BuildOperationMessages.swift
14+
BuildService.swift
15+
BuildServiceEntryPoint.swift
16+
ClientExchangeDelegate.swift
17+
DependencyGraphMessages.swift
18+
DocumentationInfo.swift
19+
LocalizationInfo.swift
20+
Messages.swift
21+
PlanningOperation.swift
22+
PreviewInfo.swift
23+
ProjectDescriptor.swift
24+
Session.swift
25+
Tools.swift)
26+
set_target_properties(SWBBuildService PROPERTIES
27+
Swift_LANGUAGE_VERSION 5)
28+
target_link_libraries(SWBBuildService PUBLIC
29+
SWBBuildSystem
30+
SWBServiceCore
31+
SWBTaskExecution
32+
SWBAndroidPlatform
33+
SWBApplePlatform
34+
SWBGenericUnixPlatform
35+
SWBQNXPlatform
36+
SWBUniversalPlatform
37+
SWBWebAssemblyPlatform
38+
SWBWindowsPlatform
39+
SwiftSystem::SystemPackage)

0 commit comments

Comments
 (0)