Skip to content

Commit

Permalink
Exclude XCBuildSupport when building with CMake
Browse files Browse the repository at this point in the history
XCBuildSupport is not available on non-Darwin platforms, especially Windows, where we have to have full CMake support at the moment. Maintaining XCBuildSupport in these unsupported configurations adds unnecessary overhead, especially in cases like #7258, where we have to add new dependencies only when `XCBuildSupport` is available. We should exclude from CMake builds to reduce this maintenance overhead.
  • Loading branch information
MaxDesiatov committed Feb 22, 2024
1 parent 61d6215 commit 2cba8ef
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 31 deletions.
1 change: 0 additions & 1 deletion Sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ add_subdirectory(swift-package)
add_subdirectory(swift-run)
add_subdirectory(swift-test)
add_subdirectory(Workspace)
add_subdirectory(XCBuildSupport)
7 changes: 5 additions & 2 deletions Sources/Commands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ target_link_libraries(Commands PUBLIC
SourceControl
TSCBasic
TSCUtility
Workspace
XCBuildSupport)
Workspace)

target_compile_definitions(Commands
PRIVATE SKIP_XCBUILD_SUPPORT)

target_link_libraries(Commands PRIVATE
DriverSupport
$<$<NOT:$<PLATFORM_ID:Darwin>>:FoundationXML>)
Expand Down
7 changes: 7 additions & 0 deletions Sources/Commands/PackageTools/DumpCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import Basics
import CoreCommands
import Foundation
import PackageModel

#if !SKIP_XCBUILD_SUPPORT
import XCBuildSupport
#endif

struct DumpSymbolGraph: SwiftCommand {
static let configuration = CommandConfiguration(
Expand Down Expand Up @@ -136,6 +139,7 @@ struct DumpPIF: SwiftCommand {
var preserveStructure: Bool = false

func run(_ swiftTool: SwiftTool) throws {
#if !SKIP_XCBUILD_SUPPORT
let graph = try swiftTool.loadPackageGraph()
let pif = try PIFBuilder.generatePIF(
buildParameters: swiftTool.productsBuildParameters,
Expand All @@ -144,6 +148,9 @@ struct DumpPIF: SwiftCommand {
observabilityScope: swiftTool.observabilityScope,
preservePIFModelStructure: preserveStructure)
print(pif)
#else
fatalError("This subcommand is not available on the current platform")
#endif
}

var toolWorkspaceConfiguration: ToolWorkspaceConfiguration {
Expand Down
3 changes: 3 additions & 0 deletions Sources/Commands/PackageTools/SwiftPackageTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import PackageModel
import SourceControl
import SPMBuildCore
import Workspace

#if !SKIP_XCBUILD_SUPPORT
import XCBuildSupport
#endif

import enum TSCUtility.Diagnostics

Expand Down
3 changes: 3 additions & 0 deletions Sources/Commands/SwiftBuildTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import Build
import CoreCommands
import PackageGraph
import SPMBuildCore

#if !SKIP_XCBUILD_SUPPORT
import XCBuildSupport
#endif

import class TSCBasic.Process
import var TSCBasic.stdoutStream
Expand Down
11 changes: 11 additions & 0 deletions Sources/CoreCommands/BuildSystemSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import Build
import SPMBuildCore

#if !SKIP_XCBUILD_SUPPORT
import XCBuildSupport
#endif

import class Basics.ObservabilityScope
import struct PackageGraph.PackageGraph
Expand Down Expand Up @@ -60,6 +63,7 @@ private struct NativeBuildSystemFactory: BuildSystemFactory {
}
}

#if !SKIP_XCBUILD_SUPPORT
private struct XcodeBuildSystemFactory: BuildSystemFactory {
let swiftTool: SwiftTool

Expand Down Expand Up @@ -87,12 +91,19 @@ private struct XcodeBuildSystemFactory: BuildSystemFactory {
)
}
}
#endif

extension SwiftTool {
public var defaultBuildSystemProvider: BuildSystemProvider {
#if !SKIP_XCBUILD_SUPPORT
.init(providers: [
.native: NativeBuildSystemFactory(swiftTool: self),
.xcode: XcodeBuildSystemFactory(swiftTool: self)
])
#else
.init(providers: [
.native: NativeBuildSystemFactory(swiftTool: self),
])
#endif
}
}
7 changes: 5 additions & 2 deletions Sources/CoreCommands/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ target_link_libraries(CoreCommands PUBLIC
PackageGraph
TSCBasic
TSCUtility
Workspace
XCBuildSupport)
Workspace)

target_compile_definitions(CoreCommands
PRIVATE SKIP_XCBUILD_SUPPORT)

target_link_libraries(CoreCommands PRIVATE
DriverSupport
$<$<NOT:$<PLATFORM_ID:Darwin>>:FoundationXML>)
Expand Down
24 changes: 0 additions & 24 deletions Sources/XCBuildSupport/CMakeLists.txt

This file was deleted.

6 changes: 4 additions & 2 deletions Sources/swift-bootstrap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ target_link_libraries(swift-bootstrap PRIVATE
PackageLoading
PackageModel
TSCBasic
TSCUtility
XCBuildSupport)
TSCUtility)

target_compile_definitions(swift-bootstrap
PRIVATE SKIP_XCBUILD_SUPPORT)
7 changes: 7 additions & 0 deletions Sources/swift-bootstrap/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import PackageGraph
import PackageLoading
import PackageModel
import SPMBuildCore

#if !SKIP_XCBUILD_SUPPORT
import XCBuildSupport
#endif

import struct TSCBasic.KeyedPair
import func TSCBasic.topologicalSort
Expand Down Expand Up @@ -322,6 +325,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
observabilityScope: self.observabilityScope
)
case .xcode:
#if !SKIP_XCBUILD_SUPPORT
return try XcodeBuildSystem(
buildParameters: buildParameters,
packageGraphLoader: packageGraphLoader,
Expand All @@ -330,6 +334,9 @@ struct SwiftBootstrapBuildTool: ParsableCommand {
fileSystem: self.fileSystem,
observabilityScope: self.observabilityScope
)
#else
fatalError("SwiftPM was built without XCBuild support")
#endif
}
}

Expand Down

0 comments on commit 2cba8ef

Please sign in to comment.