Skip to content
Draft
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
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@ let package = Package(
"SourceKitLSPAPI",
"SwiftBuildSupport",
"Workspace"
] + swiftTSCBasicsDeps + swiftToolsProtocolsDeps
] + swiftTSCBasicsDeps + swiftToolsProtocolsDeps,
exclude: [
"CMakeLists.txt",
],
),

// MARK: Commands
Expand Down
4 changes: 2 additions & 2 deletions Sources/Commands/Utilities/TestingSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ enum TestingSupport {
// Since XCTestHelper targets macOS, we need the macOS platform paths here.
if let sdkPlatformPaths = try? SwiftSDK.sdkPlatformPaths(for: .macOS) {
// appending since we prefer the user setting (if set) to the one we inject
for frameworkPath in sdkPlatformPaths.frameworks {
for frameworkPath in sdkPlatformPaths.runtimeFrameworkSearchPaths {
env.appendPath(key: "DYLD_FRAMEWORK_PATH", value: frameworkPath.pathString)
}
for libraryPath in sdkPlatformPaths.libraries {
for libraryPath in sdkPlatformPaths.runtimeLibrarySearchPaths {
env.appendPath(key: "DYLD_LIBRARY_PATH", value: libraryPath.pathString)
}
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/LLBuildManifest/LLBuildManifestWriter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,63 +129,63 @@ public struct ManifestToolStream {
fileprivate var buffer = ""

public subscript(key: String) -> Int {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an Int") }
set {
self.buffer += " \(key): \(newValue.description.asJSON)\n"
}
}

public subscript(key: String) -> String {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return a String") }
set {
self.buffer += " \(key): \(newValue.asJSON)\n"
}
}

public subscript(key: String) -> ToolProtocol {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return a ToolProtocol") }
set {
self.buffer += " \(key): \(type(of: newValue).name)\n"
}
}

public subscript(key: String) -> AbsolutePath {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an AbsolutePath") }
set {
self.buffer += " \(key): \(newValue.pathString.asJSON)\n"
}
}

public subscript(key: String) -> [AbsolutePath] {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an array of AbsolutePath") }
set {
self.buffer += " \(key): \(newValue.map(\.pathString).asJSON)\n"
}
}

public subscript(key: String) -> [Node] {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an array of Node") }
set {
self.buffer += " \(key): \(newValue.map(\.encodingName).asJSON)\n"
}
}

public subscript(key: String) -> Bool {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return a Bool") }
set {
self.buffer += " \(key): \(newValue.description)\n"
}
}

public subscript(key: String) -> [String] {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an array of String") }
set {
self.buffer += " \(key): \(newValue.asJSON)\n"
}
}

public subscript(key: String) -> [String: String] {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return a [String: String]") }
set {
self.buffer += " \(key):\n"
for (key, value) in newValue.sorted(by: { $0.key < $1.key }) {
Expand All @@ -195,7 +195,7 @@ public struct ManifestToolStream {
}

package subscript(key: String) -> Environment {
get { fatalError() }
get { fatalError("\(#file):\(#line) at function \(#function) - Cannot get subscript that return an Environment") }
set {
self.buffer += " \(key):\n"
for (key, value) in newValue.sorted(by: { $0.key < $1.key }) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageGraph/VersionSetSpecifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ extension VersionSetSpecifier {
case (_, .any):
return .empty
case (.any, _):
fatalError()
fatalError("\(#file):\(#line) - Illegal call of \(#function) on left hand side value of `.any`")
case (.empty, _):
return .empty
case (_, .empty):
Expand Down
37 changes: 26 additions & 11 deletions Sources/PackageModel/SwiftSDKs/SwiftSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,10 @@ public struct SwiftSDK: Equatable {
#if os(macOS)
do {
let sdkPaths = try SwiftSDK.sdkPlatformPaths(for: darwinPlatform, environment: environment)
extraCCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.frameworks.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-I", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.libraries.flatMap { ["-L", $0.pathString] })
extraCCFlags.append(contentsOf: sdkPaths.buildTimeFrameworkSearchPaths.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeFrameworkSearchPaths.flatMap { ["-F", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeLibrarySearchPaths.flatMap { ["-I", $0.pathString] })
extraSwiftCFlags.append(contentsOf: sdkPaths.buildTimeLibrarySearchPaths.flatMap { ["-L", $0.pathString] })
xctestSupport = .supported
} catch {
xctestSupport = .unsupported(reason: String(describing: error))
Expand Down Expand Up @@ -628,11 +628,21 @@ public struct SwiftSDK: Equatable {
///
/// - SeeAlso: ``sdkPlatformPaths(for:environment:)``
public struct PlatformPaths {
/// Paths of directories containing auxiliary platform frameworks.
public var frameworks: [Basics.AbsolutePath]
/// Paths of directories containing auxiliary platform frameworks which
/// should be included as framework search paths at build time.
public var buildTimeFrameworkSearchPaths: [Basics.AbsolutePath]

/// Paths of directories containing auxiliary platform libraries.
public var libraries: [Basics.AbsolutePath]
/// Paths of directories containing auxiliary platform libraries which
/// should be included as library search paths at build time.
public var buildTimeLibrarySearchPaths: [Basics.AbsolutePath]

/// Paths of directories containing auxiliary platform frameworks which
/// should be included as framework search paths at runtime.
public var runtimeFrameworkSearchPaths: [Basics.AbsolutePath]

/// Paths of directories containing auxiliary platform libraries which
/// should be included as library search paths at runtime.
public var runtimeLibrarySearchPaths: [Basics.AbsolutePath]
}

/// Returns `macosx` sdk platform framework path.
Expand All @@ -641,10 +651,10 @@ public struct SwiftSDK: Equatable {
environment: Environment = .current
) throws -> (fwk: Basics.AbsolutePath, lib: Basics.AbsolutePath) {
let paths = try sdkPlatformPaths(for: .macOS, environment: environment)
guard let frameworkPath = paths.frameworks.first else {
guard let frameworkPath = paths.buildTimeFrameworkSearchPaths.first else {
throw StringError("could not determine SDK platform framework path")
}
guard let libraryPath = paths.libraries.first else {
guard let libraryPath = paths.buildTimeLibrarySearchPaths.first else {
throw StringError("could not determine SDK platform library path")
}
return (fwk: frameworkPath, lib: libraryPath)
Expand Down Expand Up @@ -682,7 +692,12 @@ public struct SwiftSDK: Equatable {
components: "Developer", "usr", "lib"
)

let sdkPlatformFrameworkPath = PlatformPaths(frameworks: [frameworksPath, privateFrameworksPath], libraries: [librariesPath])
let sdkPlatformFrameworkPath = PlatformPaths(
buildTimeFrameworkSearchPaths: [frameworksPath /* omit privateFrameworksPath */],
buildTimeLibrarySearchPaths: [librariesPath],
runtimeFrameworkSearchPaths: [frameworksPath, privateFrameworksPath],
runtimeLibrarySearchPaths: [librariesPath]
)
_sdkPlatformFrameworkPath[darwinPlatform] = sdkPlatformFrameworkPath
return sdkPlatformFrameworkPath
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/QueryEngine/Query.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extension HashEncoder: UnkeyedEncodingContainer {
}

func superEncoder() -> any Encoder {
fatalError()
fatalError("\(#file):\(#line) - Illegal call of function \(#function)")
}
}

Expand Down Expand Up @@ -272,11 +272,11 @@ extension HashEncoder {
}

mutating func superEncoder() -> any Encoder {
fatalError()
fatalError("\(#file):\(#line) - Illegal call of function \(#function)")
}

mutating func superEncoder(forKey key: K) -> any Encoder {
fatalError()
fatalError("\(#file):\(#line) - Illegal call of function \(#function)")
}

typealias Key = K
Expand Down
10 changes: 5 additions & 5 deletions Sources/Runtimes/PackageDescription/PackageDependency.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ extension Package {
traits: traits
)
}

convenience init(
name: String?,
location: String,
Expand All @@ -181,7 +181,7 @@ extension Package {
traits: traits
)
}

convenience init(
id: String,
requirement: RegistryRequirement,
Expand Down Expand Up @@ -1067,7 +1067,7 @@ extension Package.Dependency {
/// ```swift
/// .package(id: "scope.name", "1.2.3"..."1.2.6"),
/// ```
///
///
/// If the package you depend on defines traits, the package manager uses the dependency with its default set of traits.
///
/// - Parameters:
Expand Down Expand Up @@ -1140,11 +1140,11 @@ extension Package.Dependency {
extension Package.Dependency {
@available(*, unavailable, message: "use package(url:exact:) instead")
public static func package(url: String, version: Version) -> Package.Dependency {
fatalError()
fatalError("\(#file):\(#line) - Illegal call of deprecated function \(#function)")
}

@available(*, unavailable, message: "use package(url:_:) instead")
public static func package(url: String, range: Range<Version>) -> Package.Dependency {
fatalError()
fatalError("\(#file):\(#line) - Illegal call of deprecated function \(#function)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public struct BuildParameters: Encodable {
case .library(.dynamic):
return try dynamicLibraryPath(for: product.name)
case .library(.automatic), .plugin:
fatalError()
fatalError("\(#file):\(#line) - Illegal call of function \(#function) with automatica library and plugin")
case .test:
switch buildSystemKind {
case .native, .xcode:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceControl/Repository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public struct RepositorySpecifier: Hashable, Sendable {
if basename.hasSuffix(".git") {
basename = String(basename.dropLast(4))
}
if basename == "/" {
if basename == "/" || basename == "\\" {
return ""
}
return basename
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftBuildSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

add_library(SwiftBuildSupport STATIC
BuildSystem.swift
Diagnostics+Extensions.swift
DotPIFSerializer.swift
PackagePIFBuilder.swift
PackagePIFBuilder+Helpers.swift
Expand Down
26 changes: 26 additions & 0 deletions Sources/SwiftBuildSupport/Diagnostics+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 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 the list of Swift project authors
//
//===----------------------------------------------------------------------===//

import Basics

extension Basics.Diagnostic {
package static var swiftBackDeployWarning: Self {
.warning(
"""
Swift compiler no longer supports statically linking the Swift libraries. They're included in the OS by \
default starting with macOS Mojave 10.14.4 beta 3. For macOS Mojave 10.14.3 and earlier, there's an \
optional "Swift 5 Runtime Support for Command Line Tools" package that can be downloaded from \"More Downloads\" \
for Apple Developers at https://developer.apple.com/download/more/
"""
)
}
}
2 changes: 1 addition & 1 deletion Sources/SwiftBuildSupport/PackagePIFBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public final class PackagePIFBuilder {
case .packageProduct: .packageProduct
case .hostBuildTool: fatalError("Unexpected hostBuildTool type")
@unknown default:
fatalError()
fatalError("Unknown product type: \(pifProductType)")
}
}
}
Expand Down
40 changes: 33 additions & 7 deletions Sources/SwiftBuildSupport/SwiftBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func withSession(

package final class SwiftBuildSystemPlanningOperationDelegate: SWBPlanningOperationDelegate, SWBIndexingDelegate, Sendable {
package init() {}

public func provisioningTaskInputs(
targetGUID: String,
provisioningSourceData: SWBProvisioningTaskInputsSourceData
Expand Down Expand Up @@ -762,7 +762,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
// native build system.
settings["SWIFT_EXEC"] = buildParameters.toolchain.swiftCompilerPath.pathString
}

let overrideToolchains = [buildParameters.toolchain.metalToolchainId, toolchainID?.rawValue].compactMap { $0 }
if !overrideToolchains.isEmpty {
settings["TOOLCHAINS"] = (overrideToolchains + ["$(inherited)"]).joined(separator: " ")
Expand Down Expand Up @@ -920,7 +920,7 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
}
try settings.merge(Self.constructDebuggingSettingsOverrides(from: buildParameters.debuggingParameters), uniquingKeysWith: reportConflict)
try settings.merge(Self.constructDriverSettingsOverrides(from: buildParameters.driverParameters), uniquingKeysWith: reportConflict)
try settings.merge(Self.constructLinkerSettingsOverrides(from: buildParameters.linkingParameters), uniquingKeysWith: reportConflict)
try settings.merge(self.constructLinkerSettingsOverrides(from: buildParameters.linkingParameters, triple: buildParameters.triple), uniquingKeysWith: reportConflict)
try settings.merge(Self.constructTestingSettingsOverrides(from: buildParameters.testingParameters), uniquingKeysWith: reportConflict)
try settings.merge(Self.constructAPIDigesterSettingsOverrides(from: buildParameters.apiDigesterMode), uniquingKeysWith: reportConflict)

Expand All @@ -937,16 +937,27 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
return params
}

public func makeBuildRequest(session: SWBBuildServiceSession, configuredTargets: [SWBTargetGUID], derivedDataPath: Basics.AbsolutePath, symbolGraphOptions: BuildOutput.SymbolGraphOptions?) async throws -> SWBBuildRequest {
public func makeBuildRequest(
session: SWBBuildServiceSession,
configuredTargets: [SWBTargetGUID],
derivedDataPath: Basics.AbsolutePath,
symbolGraphOptions: BuildOutput.SymbolGraphOptions?,
setToolchainSetting: Bool = true,
) async throws -> SWBBuildRequest {
var request = SWBBuildRequest()
request.parameters = try await makeBuildParameters(session: session, symbolGraphOptions: symbolGraphOptions)
request.parameters = try await makeBuildParameters(
session: session,
symbolGraphOptions: symbolGraphOptions,
setToolchainSetting: setToolchainSetting,
)
request.configuredTargets = configuredTargets.map { SWBConfiguredTarget(guid: $0.rawValue, parameters: request.parameters) }
request.useParallelTargets = true
request.useImplicitDependencies = false
request.useDryRun = false
request.hideShellScriptEnvironment = true
request.showNonLoggedProgress = true
request.recordBuildBacktraces = buildParameters.outputParameters.enableTaskBacktraces
request.schedulerLaneWidthOverride = buildParameters.workers

// Override the arena. We need to apply the arena info to both the request-global build
// parameters as well as the target-specific build parameters, since they may have been
Expand Down Expand Up @@ -1007,7 +1018,10 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
return settings
}

private static func constructLinkerSettingsOverrides(from parameters: BuildParameters.Linking) -> [String: String] {
private func constructLinkerSettingsOverrides(
from parameters: BuildParameters.Linking,
triple: Triple,
) -> [String: String] {
var settings: [String: String] = [:]

if parameters.linkerDeadStrip {
Expand All @@ -1025,7 +1039,19 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
break
}

// TODO: shouldLinkStaticSwiftStdlib
if triple.isDarwin() && parameters.shouldLinkStaticSwiftStdlib {
self.observabilityScope.emit(Basics.Diagnostic.swiftBackDeployWarning)
} else {
if parameters.shouldLinkStaticSwiftStdlib {
settings["SWIFT_FORCE_STATIC_LINK_STDLIB"] = "YES"
} else {
settings["SWIFT_FORCE_STATIC_LINK_STDLIB"] = "NO"
}
}

if let resourcesPath = self.buildParameters.toolchain.swiftResourcesPath(isStatic: parameters.shouldLinkStaticSwiftStdlib) {
settings["SWIFT_RESOURCE_DIR"] = resourcesPath.pathString
}

return settings
}
Expand Down
Loading