Skip to content

Exclude XCBuildSupport when building with CMake #7358

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 2 commits into from
Feb 23, 2024
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
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 DISABLE_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 !DISABLE_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 !DISABLE_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 !DISABLE_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 !DISABLE_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 !DISABLE_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 !DISABLE_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 !DISABLE_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 DISABLE_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 DISABLE_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 !DISABLE_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 !DISABLE_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")
Copy link
Contributor Author

@MaxDesiatov MaxDesiatov Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is technically unreachable, since case .xcode is never reachable on non-Darwin platforms, and we don't call swift-bootstrap --build-system xcode anywhere during the build process on Darwin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is technically unreachable

Heh, famous last words:
https://ci.swift.org/job/oss-swift-package-macos/2753

--- bootstrap: note: Building SwiftPM (with a freshly built swift-bootstrap)
main/main.swift:345: Fatal error: SwiftPM was built without XCBuild support

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bootstrap/bin/swift-bootstrap ... --arch x86_64 --arch arm64 ...

And:

    private var buildSystem: BuildSystemProvider.Kind {
        #if os(macOS)
        // Force the Xcode build system if we want to build more than one arch.
        return self.architectures.count > 1 ? .xcode : .native
        #else
        // Force building with the native build system on other platforms than macOS.
        return .native
        #endif
    }

#endif
}
}

Expand Down