Skip to content

Commit

Permalink
build: initial support for building with CMake
Browse files Browse the repository at this point in the history
Add support for building with CMake which is required to get the
toolchain bootstrapped. This partially addresses swiftlang#7.
  • Loading branch information
compnerd committed Feb 5, 2025
1 parent 9425799 commit 8ec6c5d
Show file tree
Hide file tree
Showing 21 changed files with 940 additions and 0 deletions.
48 changes: 48 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

cmake_minimum_required(VERSION 3.26...3.29)
project(SwiftBuild
LANGUAGES C CXX Swift)

set(CMAKE_C_VISIBILITY hidden)
set(CMAKE_CXX_VISIBILITY hidden)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_CXX_EXTENSIONS NO)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)

option(SwiftBuild_USE_LLBUILD_FRAMEWORK "Use LLBuild Framework" NO)

add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name SwiftBuild>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature ConciseMagicFile>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature DeprecateApplicationMain>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature DisableOutwardActorInference>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature ForwardTrailingClosures>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature GlobalConcurrency>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature ImplicitOpenExistentials>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature ImplicitOpenExistentialsImportObjcForwardDeclarations>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature InferSendableFromCaptures>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,$<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>>:SHELL:-enable-upcoming-feature IsolatedDefaultValues>"
# rdar://137809703
# "$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature RegionBasedIsolation>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ExistentialAny>"
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>")

find_package(ArgumentParser)
find_package(LLBuild)
find_package(SwiftDriver)
find_package(SwiftSystem)
find_package(TSC)
# NOTE: these two are required for LLBuild dependencies
find_package(Threads)
find_package(SQLite3)

add_subdirectory(Sources)
29 changes: 29 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_subdirectory(SWBCSupport)
add_subdirectory(SWBCLibc)
add_subdirectory(SWBLibc)
add_subdirectory(SWBUtil)
add_subdirectory(SWBMacro)
add_subdirectory(SWBProtocol)
add_subdirectory(SWBServiceCore)
add_subdirectory(SWBCAS)
add_subdirectory(SWBLLBuild)
add_subdirectory(SWBCore)
add_subdirectory(SWBTaskConstruction)
add_subdirectory(SWBTaskExecution)
add_subdirectory(SWBBuildSystem)
add_subdirectory(SWBBuildService)
add_subdirectory(SWBProjectModel)
add_subdirectory(SwiftBuild)

add_subdirectory(swbuild)
add_subdirectory(SWBBuildServiceBundle)
32 changes: 32 additions & 0 deletions Sources/SWBBuildService/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_library(SWBBuildService
BuildDependencyInfo.swift
BuildOperationMessages.swift
BuildService.swift
BuildServiceEntryPoint.swift
ClientExchangeDelegate.swift
DependencyGraphMessages.swift
DocumentationInfo.swift
LocalizationInfo.swift
Messages.swift
PlanningOperation.swift
PreviewInfo.swift
ProjectDescriptor.swift
Session.swift
Tools.swift)
set_target_properties(SWBBuildService PROPERTIES
Swift_LANGUAGE_VERSION 5)
target_link_libraries(SWBBuildService PUBLIC
SWBBuildSystem
SWBServiceCore
SWBTaskExecution
SwiftSystem::SystemPackage)
22 changes: 22 additions & 0 deletions Sources/SWBBuildServiceBundle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_executable(SWBBuildServiceBundle
main.swift)
set_target_properties(SWBBuildServiceBundle PROPERTIES
Swift_LANGUAGE_VERSION 6)
target_link_libraries(SWBBuildServiceBundle PRIVATE
SWBBuildService
SWBBuildSystem
SWBServiceCore
SWBUtil
SWBCore)

install(TARGETS SWBBuildServiceBundle)
24 changes: 24 additions & 0 deletions Sources/SWBBuildSystem/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_library(SWBBuildSystem
BuildManager.swift
BuildOperation.swift
BuildOperationExtension.swift
BuildSystemCache.swift
CleanOperation.swift
DependencyCycleFormatter.swift
SandboxViolations.swift)
set_target_properties(SWBBuildSystem PROPERTIES
Swift_LANGUAGE_VERSION 5)
target_link_libraries(SWBBuildSystem PUBLIC
SWBCore
SWBTaskConstruction
SWBTaskExecution)
21 changes: 21 additions & 0 deletions Sources/SWBCAS/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_library(SWBCAS
CASFSNode.swift
CASProtocol.swift
Errors.swift
plugin_api_t.swift
ToolchainCASPlugin.swift)
set_target_properties(SWBCAS PROPERTIES
Swift_LANGUAGE_VERSION 6)
target_link_libraries(SWBCAS PUBLIC
SWBUtil
SWBCSupport)
14 changes: 14 additions & 0 deletions Sources/SWBCLibc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_library(SWBCLibc
libc.c)
target_include_directories(SWBCLibc INTERFACE
include)
23 changes: 23 additions & 0 deletions Sources/SWBCSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#[[
This source file is part of the Swift open source project
Copyright (c) 2014 - 2025 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
]]

add_library(SWBCSupport STATIC
CLibclang.cpp
CLibRemarksHelper.c)
target_compile_definitions(SWBCSupport PRIVATE
$<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
$<$<PLATFORM_ID:Windows>:_CRT_NONSTDC_NO_WARNINGS>)
target_compile_options(SWBCSupport PRIVATE
-fblocks)
target_include_directories(SWBCSupport PUBLIC
${CMAKE_CURRENT_SOURCE_DIR})
# TODO(compnerd) wire this up with `find_package`
target_link_libraries(SWBCSupport PRIVATE
BlocksRuntime)
4 changes: 4 additions & 0 deletions Sources/SWBCSupport/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module SWBCSupport {
header "SWBCSupport.h"
export *
}
Loading

0 comments on commit 8ec6c5d

Please sign in to comment.