Skip to content

build: initial support for building with CMake #76

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

Merged
merged 1 commit into from
Feb 12, 2025
Merged
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
52 changes: 52 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#[[
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)

set(SwiftBuild_LANGUAGE_VERSION_6 $<VERSION_LESS:$<TARGET_PROPERTY:Swift_LANGUAGE_VERSION>,6>)
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-package-name SwiftBuild>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ConciseMagicFile>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature DeprecateApplicationMain>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature DisableOutwardActorInference>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ForwardTrailingClosures>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature GlobalConcurrency>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ImplicitOpenExistentials>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature ImplicitOpenExistentialsImportObjcForwardDeclarations>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_LANGUAGE_VERSION_6}>:SHELL:-enable-upcoming-feature InferSendableFromCaptures>"
"$<$<AND:$<COMPILE_LANGUAGE:Swift>,${SwiftBuild_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>")

# Prefer the static initialisation for the pluigns.
add_compile_definitions(USE_STATIC_PLUGIN_INITIALIZATION)

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)
25 changes: 24 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,21 @@ let package = Package(
"SwiftBuild",
"SWBBuildServiceBundle", // the CLI needs to launch the service bundle
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.executableTarget(
name: "SWBBuildServiceBundle",
dependencies: [
"SWBBuildService", "SWBBuildSystem", "SWBServiceCore", "SWBUtil", "SWBCore",
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),

// Libraries
.target(
name: "SwiftBuild",
dependencies: ["SWBCSupport", "SWBCore", "SWBProtocol", "SWBUtil", "SWBProjectModel"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBBuildService",
Expand All @@ -104,10 +107,12 @@ let package = Package(
"SWBTaskExecution",
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBBuildSystem",
dependencies: ["SWBCore", "SWBTaskConstruction", "SWBTaskExecution"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBCore",
Expand All @@ -120,6 +125,7 @@ let package = Package(
.product(name: "SwiftDriver", package: "swift-driver"),
"SWBLLBuild",
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5),
plugins: [
.plugin(name: "SWBSpecificationsPlugin")
Expand All @@ -134,12 +140,13 @@ let package = Package(
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBCLibc",
exclude: ["README.md"],
exclude: ["CMakeLists.txt", "README.md"],
publicHeadersPath: ".",
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBLibc",
dependencies: ["SWBCLibc"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBLLBuild",
Expand All @@ -149,33 +156,40 @@ let package = Package(
.product(name: "libllbuild", package: useLocalDependencies ? "llbuild" : "swift-llbuild"),
.product(name: "llbuildSwift", package: useLocalDependencies ? "llbuild" : "swift-llbuild"),
]),
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBMacro",
dependencies: [
"SWBUtil",
.product(name: "SwiftDriver", package: "swift-driver"),
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBProjectModel",
dependencies: ["SWBProtocol"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBProtocol",
dependencies: ["SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBServiceCore",
dependencies: ["SWBProtocol"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBTaskConstruction",
dependencies: ["SWBCore", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBTaskExecution",
dependencies: ["SWBCore", "SWBUtil", "SWBCAS", "SWBLLBuild", "SWBTaskConstruction"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBUtil",
Expand All @@ -186,39 +200,48 @@ let package = Package(
.product(name: "Crypto", package: "swift-crypto", condition: .when(platforms: [.linux, .android])),
.product(name: "SystemPackage", package: "swift-system", condition: .when(platforms: [.linux, .android, .windows])),
],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v5)),
.target(
name: "SWBCAS",
dependencies: ["SWBUtil", "SWBCSupport"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),

.target(
name: "SWBAndroidPlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBApplePlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil", "SWBTaskConstruction"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBGenericUnixPlatform",
dependencies: ["SWBCore", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBQNXPlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBUniversalPlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBWebAssemblyPlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),
.target(
name: "SWBWindowsPlatform",
dependencies: ["SWBCore", "SWBMacro", "SWBUtil"],
exclude: ["CMakeLists.txt"],
swiftSettings: swiftSettings(languageMode: .v6)),

// Helper targets for SwiftPM
Expand Down
36 changes: 36 additions & 0 deletions Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#[[
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(SWBAndroidPlatform)
add_subdirectory(SWBApplePlatform)
add_subdirectory(SWBGenericUnixPlatform)
add_subdirectory(SWBQNXPlatform)
add_subdirectory(SWBUniversalPlatform)
add_subdirectory(SWBWebAssemblyPlatform)
add_subdirectory(SWBWindowsPlatform)
add_subdirectory(SWBTaskExecution)
add_subdirectory(SWBBuildSystem)
add_subdirectory(SWBBuildService)
add_subdirectory(SWBProjectModel)
add_subdirectory(SwiftBuild)

add_subdirectory(swbuild)
add_subdirectory(SWBBuildServiceBundle)
39 changes: 39 additions & 0 deletions Sources/SWBAndroidPlatform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[[
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
]]

file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
file(CONFIGURE
OUTPUT resource_bundle_accessor.swift
CONTENT [[
import Foundation
extension Foundation.Bundle {
static let module: Bundle = {
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBAndroidPlatform.resources").path
let buildPath = #"@_SWBAndroidPlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBAndroidPlatform.resources"#
let preferredBundle = Bundle(path: mainPath)
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
}
return bundle
}()
}
]]
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)

add_library(SWBAndroidPlatform STATIC
AndroidSDK.swift
Plugin.swift)
target_link_libraries(SWBAndroidPlatform PUBLIC
SWBCore
SWBMacro
SWBUtil)
target_sources(SWBAndroidPlatform PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
74 changes: 74 additions & 0 deletions Sources/SWBApplePlatform/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#[[
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
]]

file(TO_NATIVE_PATH "${CMAKE_CURRENT_BINARY_DIR}"
_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR)
file(CONFIGURE
OUTPUT resource_bundle_accessor.swift
CONTENT [[
import Foundation
extension Foundation.Bundle {
static let module: Bundle = {
let mainPath = Bundle.main.bundleURL.appendingPathComponent("SwiftBuild_SWBApplePlatform.resources").path
let buildPath = #"@_SWBApplePlatform_NATIVE_CMAKE_CURRENT_BINARY_DIR@\SwiftBuild_SWBApplePlatform.resources"#
let preferredBundle = Bundle(path: mainPath)
guard let bundle = preferredBundle ?? Bundle(path: buildPath) else {
Swift.fatalError("could not load resource bundle: from \(mainPath) or \(buildPath)")
}
return bundle
}()
}
]]
ESCAPE_QUOTES @ONLY NEWLINE_STYLE LF)

add_library(SWBApplePlatform STATIC
Specs/AssetCatalogCompiler.swift
Specs/CopyTiffFile.swift
Specs/CoreDataCompiler.swift
Specs/CoreMLCompiler.swift
Specs/DittoTool.swift
Specs/ExtensionPointsCompiler.swift
Specs/IIGCompiler.swift
Specs/InstrumentsPackageBuilderSpec.swift
Specs/IntentsCompiler.swift
Specs/InterfaceBuilderCompiler.swift
Specs/InterfaceBuilderShared.swift
Specs/MetalCompiler.swift
Specs/MiGCompiler.swift
Specs/OpenCLCompiler.swift
Specs/RealityAssetsCompilerSpec.swift
Specs/ReferenceObjectCompiler.swift
Specs/ResMergerLinkerSpec.swift
Specs/SceneKitToolSpec.swift
Specs/StoryboardLinker.swift
Specs/XCStringsCompiler.swift
ActoolInputFileGroupingStrategy.swift
AssetCatalogCompilerOutputParser.swift
CMakeLists.txt
DevelopmentAssetsTaskProducer.swift
ImageScaleFactorsInputFileGroupingStrategy.swift
InterfaceBuilderCompilerOutputParser.swift
LocalizationInputFileGroupingStrategy.swift
MacCatalystInfoExtension.swift
Plugin.swift
RealityAssetsTaskProducer.swift
StringCatalogCompilerOutputParser.swift
StubBinaryTaskProducer.swift
XCStringsInputFileGroupingStrategy.swift)
set_target_properties(SWBApplePlatform PROPERTIES
Swift_LANGUAGE_VERSION 6)
target_link_libraries(SWBApplePlatform PUBLIC
SWBCore
SWBMacro
SWBUtil
SWBProtocol
SWBTaskConstruction)
target_sources(SWBApplePlatform PRIVATE
"${CMAKE_CURRENT_BINARY_DIR}/resource_bundle_accessor.swift")
39 changes: 39 additions & 0 deletions Sources/SWBBuildService/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#[[
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
SWBAndroidPlatform
SWBApplePlatform
SWBGenericUnixPlatform
SWBQNXPlatform
SWBUniversalPlatform
SWBWebAssemblyPlatform
SWBWindowsPlatform
SwiftSystem::SystemPackage)
Loading