Skip to content

Commit 87a0f5e

Browse files
committed
[utils] swift-xcodegen: Enable some Swift 7 upcoming features
1 parent 55de49d commit 87a0f5e

File tree

15 files changed

+82
-47
lines changed

15 files changed

+82
-47
lines changed

utils/swift-xcodegen/Package.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,34 @@ let package = Package(
3333
swiftLanguageModes: [.v6]
3434
)
3535

36+
// Apply global Swift settings to targets.
37+
do {
38+
var globalSwiftSettings: [SwiftSetting] = [
39+
// Swift 7 mode upcoming features. These must be compatible with 'swift-tools-version'.
40+
.enableUpcomingFeature("ExistentialAny"),
41+
.enableUpcomingFeature("InternalImportsByDefault"),
42+
.enableUpcomingFeature("MemberImportVisibility"),
43+
.enableUpcomingFeature("NonisolatedNonsendingByDefault"),
44+
]
45+
46+
#if compiler(>=6.1)
47+
globalSwiftSettings.append(
48+
.unsafeFlags(["-Werror", "ExistentialAny"])
49+
)
50+
#endif
51+
52+
globalSwiftSettings += [] // avoid unused warning
53+
54+
for target in package.targets where target.type != .plugin {
55+
if let swiftSettings = target.swiftSettings {
56+
// Target-specific settings should come last.
57+
target.swiftSettings = globalSwiftSettings + swiftSettings
58+
} else {
59+
target.swiftSettings = globalSwiftSettings
60+
}
61+
}
62+
}
63+
3664
if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
3765
package.dependencies += [
3866
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.4.0"),

utils/swift-xcodegen/Sources/SwiftXcodeGen/BuildArgs/RunnableTargets.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import System
14+
1315
/// A target that defines a runnable executable.
1416
struct RunnableTarget: Hashable {
1517
var name: String

utils/swift-xcodegen/Sources/SwiftXcodeGen/Command/Command.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -21,7 +21,7 @@ struct Command: Hashable {
2121
}
2222

2323
extension Command: Decodable {
24-
init(from decoder: Decoder) throws {
24+
init(from decoder: any Decoder) throws {
2525
let command = try decoder.singleValueContainer().decode(String.self)
2626
self = try CommandParser.parseCommand(command)
2727
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Command/CompileCommands.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -18,7 +18,7 @@ struct CompileCommands: Decodable {
1818
self.commands = commands
1919
}
2020

21-
public init(from decoder: Decoder) throws {
21+
public init(from decoder: any Decoder) throws {
2222
self.init(try decoder.singleValueContainer().decode([Element].self))
2323
}
2424
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Logging/Logger.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
13+
public import Foundation
1414
import Synchronization
1515

1616
public final class Logger: @unchecked Sendable {
@@ -35,8 +35,8 @@ public final class Logger: @unchecked Sendable {
3535
set { stateLock.withLock { _useColor = newValue } }
3636
}
3737

38-
private var _output: LoggableStream?
39-
public var output: LoggableStream? {
38+
private var _output: (any LoggableStream)?
39+
public var output: (any LoggableStream)? {
4040
get { stateLock.withLock { _output } }
4141
set { stateLock.withLock { _output = newValue } }
4242
}
@@ -100,7 +100,7 @@ extension Logger {
100100
}
101101

102102
public protocol Loggable {
103-
func write(to stream: LoggableStream, useColor: Bool)
103+
func write(to stream: any LoggableStream, useColor: Bool)
104104
}
105105

106106
extension Logger.LogLevel: Loggable, CustomStringConvertible {
@@ -122,7 +122,7 @@ extension Logger.LogLevel: Loggable, CustomStringConvertible {
122122
case .error: .brightRed
123123
}
124124
}
125-
public func write(to stream: LoggableStream, useColor: Bool) {
125+
public func write(to stream: any LoggableStream, useColor: Bool) {
126126
let str = useColor
127127
? "\(fg: ansiColor)\(weight: .bold)\(self)\(fg: .normal)\(weight: .normal)"
128128
: "\(self)"

utils/swift-xcodegen/Sources/SwiftXcodeGen/Ninja/NinjaBuildDir.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import Synchronization
1515
public final class NinjaBuildDir: Sendable {
1616
public let path: AbsolutePath
1717
public let projectRootDir: AbsolutePath
18-
private let _tripleSuffix: Result<String, Error>
18+
private let _tripleSuffix: Result<String, any Error>
1919

2020
private let repoBuildDirs = Mutex<[Repo: RepoBuildDir]>()
2121

2222
private static func detectTripleSuffix(
2323
buildDir: AbsolutePath
24-
) -> Result<String, Error> {
24+
) -> Result<String, any Error> {
2525
Result {
2626
for dir in try buildDir.getDirContents() {
2727
guard buildDir.appending(dir).isDirectory,

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AbsolutePath.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Foundation
14-
import System
13+
public import Foundation
14+
public import System
1515

1616
public struct AbsolutePath: PathProtocol, Sendable {
1717
public let storage: FilePath
@@ -100,7 +100,7 @@ extension AbsolutePath: ExpressibleByStringLiteral, ExpressibleByStringInterpola
100100
}
101101

102102
extension AbsolutePath: Decodable {
103-
public init(from decoder: Decoder) throws {
103+
public init(from decoder: any Decoder) throws {
104104
let storage = FilePath(
105105
try decoder.singleValueContainer().decode(String.self)
106106
)

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/AnyPath.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import ArgumentParser
14-
import System
13+
public import protocol ArgumentParser.ExpressibleByArgument
14+
public import System
1515

1616
public enum AnyPath: PathProtocol, Sendable {
1717
case relative(RelativePath)
@@ -64,7 +64,7 @@ extension AnyPath {
6464
}
6565

6666
extension AnyPath: Decodable {
67-
public init(from decoder: Decoder) throws {
67+
public init(from decoder: any Decoder) throws {
6868
self.init(try decoder.singleValueContainer().decode(String.self))
6969
}
7070
}

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/PathProtocol.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
99
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import System
13+
public import System
14+
import Foundation
1415

1516
public protocol PathProtocol: Hashable, CustomStringConvertible {
1617
var storage: FilePath { get }

utils/swift-xcodegen/Sources/SwiftXcodeGen/Path/RelativePath.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2024 - 2025 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -11,7 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14-
import System
14+
public import System
1515

1616
public struct RelativePath: PathProtocol, Sendable {
1717
public let storage: FilePath
@@ -70,7 +70,7 @@ extension RelativePath: ExpressibleByStringLiteral, ExpressibleByStringInterpola
7070
}
7171

7272
extension RelativePath: Decodable {
73-
public init(from decoder: Decoder) throws {
73+
public init(from decoder: any Decoder) throws {
7474
self.init(try decoder.singleValueContainer().decode(String.self))
7575
}
7676
}

0 commit comments

Comments
 (0)