Skip to content

Commit 4f0d764

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 120312c commit 4f0d764

File tree

28 files changed

+1272
-0
lines changed

28 files changed

+1272
-0
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)

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)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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_executable(SWBBuildServiceBundle
12+
main.swift)
13+
set_target_properties(SWBBuildServiceBundle PROPERTIES
14+
Swift_LANGUAGE_VERSION 6)
15+
target_link_libraries(SWBBuildServiceBundle PRIVATE
16+
SWBBuildService
17+
SWBBuildSystem
18+
SWBServiceCore
19+
SWBUtil
20+
SWBCore)
21+
22+
install(TARGETS SWBBuildServiceBundle)

Sources/SWBBuildSystem/CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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(SWBBuildSystem
12+
BuildManager.swift
13+
BuildOperation.swift
14+
BuildOperationExtension.swift
15+
BuildSystemCache.swift
16+
CleanOperation.swift
17+
DependencyCycleFormatter.swift
18+
SandboxViolations.swift)
19+
set_target_properties(SWBBuildSystem PROPERTIES
20+
Swift_LANGUAGE_VERSION 5)
21+
target_link_libraries(SWBBuildSystem PUBLIC
22+
SWBCore
23+
SWBTaskConstruction
24+
SWBTaskExecution)

Sources/SWBCAS/CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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(SWBCAS
12+
CASFSNode.swift
13+
CASProtocol.swift
14+
Errors.swift
15+
plugin_api_t.swift
16+
ToolchainCASPlugin.swift)
17+
set_target_properties(SWBCAS PROPERTIES
18+
Swift_LANGUAGE_VERSION 6)
19+
target_link_libraries(SWBCAS PUBLIC
20+
SWBUtil
21+
SWBCSupport)

Sources/SWBCLibc/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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(SWBCLibc
12+
libc.c)
13+
target_include_directories(SWBCLibc INTERFACE
14+
include)

Sources/SWBCSupport/CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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(SWBCSupport STATIC
12+
CLibclang.cpp
13+
CLibRemarksHelper.c)
14+
target_compile_definitions(SWBCSupport PRIVATE
15+
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
16+
$<$<PLATFORM_ID:Windows>:_CRT_NONSTDC_NO_WARNINGS>)
17+
target_compile_options(SWBCSupport PRIVATE
18+
-fblocks)
19+
target_include_directories(SWBCSupport PUBLIC
20+
${CMAKE_CURRENT_SOURCE_DIR})
21+
# TODO(compnerd) wire this up with `find_package`
22+
target_link_libraries(SWBCSupport PRIVATE
23+
BlocksRuntime)

Sources/SWBCSupport/module.modulemap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module SWBCSupport {
2+
header "SWBCSupport.h"
3+
export *
4+
}

0 commit comments

Comments
 (0)