From 2cba8ef2876ce437bfd1d6e75a8d4ed18478a8b2 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 22 Feb 2024 15:12:41 +0000 Subject: [PATCH 1/2] Exclude `XCBuildSupport` when building with CMake 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 https://github.com/apple/swift-package-manager/pull/7258, where we have to add new dependencies only when `XCBuildSupport` is available. We should exclude from CMake builds to reduce this maintenance overhead. --- Sources/CMakeLists.txt | 1 - Sources/Commands/CMakeLists.txt | 7 ++++-- .../Commands/PackageTools/DumpCommands.swift | 7 ++++++ .../PackageTools/SwiftPackageTool.swift | 3 +++ Sources/Commands/SwiftBuildTool.swift | 3 +++ Sources/CoreCommands/BuildSystemSupport.swift | 11 +++++++++ Sources/CoreCommands/CMakeLists.txt | 7 ++++-- Sources/XCBuildSupport/CMakeLists.txt | 24 ------------------- Sources/swift-bootstrap/CMakeLists.txt | 6 +++-- Sources/swift-bootstrap/main.swift | 7 ++++++ 10 files changed, 45 insertions(+), 31 deletions(-) delete mode 100644 Sources/XCBuildSupport/CMakeLists.txt diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index a8aa9f771bc..a148ae10fb8 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -37,4 +37,3 @@ add_subdirectory(swift-package) add_subdirectory(swift-run) add_subdirectory(swift-test) add_subdirectory(Workspace) -add_subdirectory(XCBuildSupport) diff --git a/Sources/Commands/CMakeLists.txt b/Sources/Commands/CMakeLists.txt index b20e318afad..456232223c3 100644 --- a/Sources/Commands/CMakeLists.txt +++ b/Sources/Commands/CMakeLists.txt @@ -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 $<$>:FoundationXML>) diff --git a/Sources/Commands/PackageTools/DumpCommands.swift b/Sources/Commands/PackageTools/DumpCommands.swift index 35845334ad2..f753292a354 100644 --- a/Sources/Commands/PackageTools/DumpCommands.swift +++ b/Sources/Commands/PackageTools/DumpCommands.swift @@ -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( @@ -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, @@ -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 { diff --git a/Sources/Commands/PackageTools/SwiftPackageTool.swift b/Sources/Commands/PackageTools/SwiftPackageTool.swift index 61495a66a1b..15e3596e68e 100644 --- a/Sources/Commands/PackageTools/SwiftPackageTool.swift +++ b/Sources/Commands/PackageTools/SwiftPackageTool.swift @@ -20,7 +20,10 @@ import PackageModel import SourceControl import SPMBuildCore import Workspace + +#if !SKIP_XCBUILD_SUPPORT import XCBuildSupport +#endif import enum TSCUtility.Diagnostics diff --git a/Sources/Commands/SwiftBuildTool.swift b/Sources/Commands/SwiftBuildTool.swift index 521eb0c9405..a23e570b67c 100644 --- a/Sources/Commands/SwiftBuildTool.swift +++ b/Sources/Commands/SwiftBuildTool.swift @@ -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 diff --git a/Sources/CoreCommands/BuildSystemSupport.swift b/Sources/CoreCommands/BuildSystemSupport.swift index 1f2a45bbdc7..46e5f4cca2f 100644 --- a/Sources/CoreCommands/BuildSystemSupport.swift +++ b/Sources/CoreCommands/BuildSystemSupport.swift @@ -12,7 +12,10 @@ import Build import SPMBuildCore + +#if !SKIP_XCBUILD_SUPPORT import XCBuildSupport +#endif import class Basics.ObservabilityScope import struct PackageGraph.PackageGraph @@ -60,6 +63,7 @@ private struct NativeBuildSystemFactory: BuildSystemFactory { } } +#if !SKIP_XCBUILD_SUPPORT private struct XcodeBuildSystemFactory: BuildSystemFactory { let swiftTool: SwiftTool @@ -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 } } diff --git a/Sources/CoreCommands/CMakeLists.txt b/Sources/CoreCommands/CMakeLists.txt index 13d446033e1..7b2e22378b7 100644 --- a/Sources/CoreCommands/CMakeLists.txt +++ b/Sources/CoreCommands/CMakeLists.txt @@ -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 $<$>:FoundationXML>) diff --git a/Sources/XCBuildSupport/CMakeLists.txt b/Sources/XCBuildSupport/CMakeLists.txt deleted file mode 100644 index 178e0bc1ba7..00000000000 --- a/Sources/XCBuildSupport/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -# This source file is part of the Swift open source project -# -# Copyright (c) 2014 - 2020 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(XCBuildSupport STATIC - PIF.swift - PIFBuilder.swift - XCBuildDelegate.swift - XCBuildMessage.swift - XCBuildOutputParser.swift - XcodeBuildSystem.swift) -target_link_libraries(XCBuildSupport PUBLIC - Build - TSCBasic - TSCUtility - PackageGraph -) - -set_target_properties(XCBuildSupport PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/Sources/swift-bootstrap/CMakeLists.txt b/Sources/swift-bootstrap/CMakeLists.txt index f2c40f4c8a0..531de6269bc 100644 --- a/Sources/swift-bootstrap/CMakeLists.txt +++ b/Sources/swift-bootstrap/CMakeLists.txt @@ -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) diff --git a/Sources/swift-bootstrap/main.swift b/Sources/swift-bootstrap/main.swift index b879f9a79bb..73425fecec4 100644 --- a/Sources/swift-bootstrap/main.swift +++ b/Sources/swift-bootstrap/main.swift @@ -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 @@ -322,6 +325,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand { observabilityScope: self.observabilityScope ) case .xcode: + #if !SKIP_XCBUILD_SUPPORT return try XcodeBuildSystem( buildParameters: buildParameters, packageGraphLoader: packageGraphLoader, @@ -330,6 +334,9 @@ struct SwiftBootstrapBuildTool: ParsableCommand { fileSystem: self.fileSystem, observabilityScope: self.observabilityScope ) + #else + fatalError("SwiftPM was built without XCBuild support") + #endif } } From 9f48027fcc72d572c1bac9099f6c175e71b71d17 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 22 Feb 2024 17:06:02 +0000 Subject: [PATCH 2/2] Address PR feedback --- Sources/Commands/CMakeLists.txt | 2 +- Sources/Commands/PackageTools/DumpCommands.swift | 4 ++-- Sources/Commands/PackageTools/SwiftPackageTool.swift | 2 +- Sources/Commands/SwiftBuildTool.swift | 2 +- Sources/CoreCommands/BuildSystemSupport.swift | 6 +++--- Sources/CoreCommands/CMakeLists.txt | 2 +- Sources/swift-bootstrap/CMakeLists.txt | 2 +- Sources/swift-bootstrap/main.swift | 4 ++-- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/Commands/CMakeLists.txt b/Sources/Commands/CMakeLists.txt index 456232223c3..eb8242ee3e0 100644 --- a/Sources/Commands/CMakeLists.txt +++ b/Sources/Commands/CMakeLists.txt @@ -62,7 +62,7 @@ target_link_libraries(Commands PUBLIC Workspace) target_compile_definitions(Commands - PRIVATE SKIP_XCBUILD_SUPPORT) + PRIVATE DISABLE_XCBUILD_SUPPORT) target_link_libraries(Commands PRIVATE DriverSupport diff --git a/Sources/Commands/PackageTools/DumpCommands.swift b/Sources/Commands/PackageTools/DumpCommands.swift index f753292a354..3a569807e70 100644 --- a/Sources/Commands/PackageTools/DumpCommands.swift +++ b/Sources/Commands/PackageTools/DumpCommands.swift @@ -16,7 +16,7 @@ import CoreCommands import Foundation import PackageModel -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT import XCBuildSupport #endif @@ -139,7 +139,7 @@ struct DumpPIF: SwiftCommand { var preserveStructure: Bool = false func run(_ swiftTool: SwiftTool) throws { - #if !SKIP_XCBUILD_SUPPORT + #if !DISABLE_XCBUILD_SUPPORT let graph = try swiftTool.loadPackageGraph() let pif = try PIFBuilder.generatePIF( buildParameters: swiftTool.productsBuildParameters, diff --git a/Sources/Commands/PackageTools/SwiftPackageTool.swift b/Sources/Commands/PackageTools/SwiftPackageTool.swift index 15e3596e68e..ececa15cf65 100644 --- a/Sources/Commands/PackageTools/SwiftPackageTool.swift +++ b/Sources/Commands/PackageTools/SwiftPackageTool.swift @@ -21,7 +21,7 @@ import SourceControl import SPMBuildCore import Workspace -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT import XCBuildSupport #endif diff --git a/Sources/Commands/SwiftBuildTool.swift b/Sources/Commands/SwiftBuildTool.swift index a23e570b67c..ed01e55084b 100644 --- a/Sources/Commands/SwiftBuildTool.swift +++ b/Sources/Commands/SwiftBuildTool.swift @@ -17,7 +17,7 @@ import CoreCommands import PackageGraph import SPMBuildCore -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT import XCBuildSupport #endif diff --git a/Sources/CoreCommands/BuildSystemSupport.swift b/Sources/CoreCommands/BuildSystemSupport.swift index 46e5f4cca2f..ec96b4170df 100644 --- a/Sources/CoreCommands/BuildSystemSupport.swift +++ b/Sources/CoreCommands/BuildSystemSupport.swift @@ -13,7 +13,7 @@ import Build import SPMBuildCore -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT import XCBuildSupport #endif @@ -63,7 +63,7 @@ private struct NativeBuildSystemFactory: BuildSystemFactory { } } -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT private struct XcodeBuildSystemFactory: BuildSystemFactory { let swiftTool: SwiftTool @@ -95,7 +95,7 @@ private struct XcodeBuildSystemFactory: BuildSystemFactory { extension SwiftTool { public var defaultBuildSystemProvider: BuildSystemProvider { - #if !SKIP_XCBUILD_SUPPORT + #if !DISABLE_XCBUILD_SUPPORT .init(providers: [ .native: NativeBuildSystemFactory(swiftTool: self), .xcode: XcodeBuildSystemFactory(swiftTool: self) diff --git a/Sources/CoreCommands/CMakeLists.txt b/Sources/CoreCommands/CMakeLists.txt index 7b2e22378b7..3d65ad22ce4 100644 --- a/Sources/CoreCommands/CMakeLists.txt +++ b/Sources/CoreCommands/CMakeLists.txt @@ -21,7 +21,7 @@ target_link_libraries(CoreCommands PUBLIC Workspace) target_compile_definitions(CoreCommands - PRIVATE SKIP_XCBUILD_SUPPORT) + PRIVATE DISABLE_XCBUILD_SUPPORT) target_link_libraries(CoreCommands PRIVATE DriverSupport diff --git a/Sources/swift-bootstrap/CMakeLists.txt b/Sources/swift-bootstrap/CMakeLists.txt index 531de6269bc..6371d1a01d4 100644 --- a/Sources/swift-bootstrap/CMakeLists.txt +++ b/Sources/swift-bootstrap/CMakeLists.txt @@ -19,4 +19,4 @@ target_link_libraries(swift-bootstrap PRIVATE TSCUtility) target_compile_definitions(swift-bootstrap - PRIVATE SKIP_XCBUILD_SUPPORT) + PRIVATE DISABLE_XCBUILD_SUPPORT) diff --git a/Sources/swift-bootstrap/main.swift b/Sources/swift-bootstrap/main.swift index 73425fecec4..02ceae1ca1e 100644 --- a/Sources/swift-bootstrap/main.swift +++ b/Sources/swift-bootstrap/main.swift @@ -21,7 +21,7 @@ import PackageLoading import PackageModel import SPMBuildCore -#if !SKIP_XCBUILD_SUPPORT +#if !DISABLE_XCBUILD_SUPPORT import XCBuildSupport #endif @@ -325,7 +325,7 @@ struct SwiftBootstrapBuildTool: ParsableCommand { observabilityScope: self.observabilityScope ) case .xcode: - #if !SKIP_XCBUILD_SUPPORT + #if !DISABLE_XCBUILD_SUPPORT return try XcodeBuildSystem( buildParameters: buildParameters, packageGraphLoader: packageGraphLoader,