Skip to content

Commit bdcf60f

Browse files
authored
[6.0] Update -swift-version to default to 6 for swift-tools-version 6 (#7531)
**Explanation**: Changes packages to default to swift version 6 when `swift-tools-version` is set `>= 6.0`. Without this change, all packages will be swift version 5 unless otherwise specified via `swiftLanguageVersions`. Packages default to `swift-tools-version: 6.0` with `swift package init`. Users can opt-out via specifying `swiftLanguageVersions: [.v5]`. **Scope**: New packages/those updated to 6.0. **Risk**: Medium. There's inherent risk due to the language mode bump. The change also removes disabling implicit imports for concurrency and string processing in manifest files, which hasn't been widely tested outside of ... **Testing**: New regression tests. Source compatibility suite run. **Original PR**: #7469
1 parent 915fa72 commit bdcf60f

File tree

22 files changed

+182
-62
lines changed

22 files changed

+182
-62
lines changed

Fixtures/Miscellaneous/Plugins/DependentPlugins/Package.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ let package = Package(
1010
targets: [
1111
.executableTarget(name: "MyExecutable"),
1212
.executableTarget(name: "MyExecutable2"),
13-
13+
1414
.plugin(
1515
name: "MyPlugin",
1616
capability: .buildTool(),
1717
dependencies: [
1818
"MyExecutable"
1919
]
2020
),
21-
21+
2222
.plugin(
2323
name: "MyPlugin2",
2424
capability: .buildTool(),
@@ -34,5 +34,6 @@ let package = Package(
3434
"MyPlugin2",
3535
]
3636
),
37-
]
37+
],
38+
swiftLanguageVersions: [.v5]
3839
)

Fixtures/Miscellaneous/Plugins/MyBuildToolPluginDependencies/Sources/MySourceGenBuildTool/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP
1313

1414
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
1515
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
16-
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
16+
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
1717
let outputData = outputString.data(using: .utf8)
1818
FileManager.default.createFile(atPath: outputFile, contents: outputData)

Fixtures/Miscellaneous/Plugins/MySourceGenPlugin/Sources/MySourceGenBuildTool/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP
1313

1414
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
1515
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
16-
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
16+
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
1717
let outputData = outputString.data(using: .utf8)
1818
FileManager.default.createFile(atPath: outputFile, contents: outputData)

Fixtures/Miscellaneous/Plugins/MySourceGenPluginUsingURLBasedAPI/Sources/MySourceGenBuildTool/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP
1313

1414
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
1515
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
16-
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
16+
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
1717
let outputData = outputString.data(using: .utf8)
1818
FileManager.default.createFile(atPath: outputFile, contents: outputData)

Fixtures/Miscellaneous/Plugins/PluginWithInternalExecutable/Sources/PluginExecutable/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP
1212

1313
let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
1414
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
15-
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
15+
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
1616
let outputData = outputString.data(using: .utf8)
1717
FileManager.default.createFile(atPath: outputFile, contents: outputData)

IntegrationTests/Tests/IntegrationTests/BasicTests.swift

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ final class BasicTests: XCTestCase {
1919

2020
func testExamplePackageDealer() throws {
2121
try XCTSkipIf(isSelfHosted, "These packages don't use the latest runtime library, which doesn't work with self-hosted builds.")
22+
try skipUnlessAtLeastSwift6()
2223

2324
try withTemporaryDirectory { tempDir in
2425
let packagePath = tempDir.appending(component: "dealer")
@@ -93,9 +94,7 @@ final class BasicTests: XCTestCase {
9394
}
9495

9596
func testSwiftPackageInitExec() throws {
96-
#if swift(<5.5)
97-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
98-
#endif
97+
try skipUnlessAtLeastSwift6()
9998

10099
try withTemporaryDirectory { tempDir in
101100
// Create a new package with an executable target.
@@ -122,9 +121,7 @@ final class BasicTests: XCTestCase {
122121
}
123122

124123
func testSwiftPackageInitExecTests() throws {
125-
#if swift(<5.5)
126-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
127-
#endif
124+
try skipUnlessAtLeastSwift6()
128125

129126
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
130127

@@ -149,6 +146,8 @@ final class BasicTests: XCTestCase {
149146
}
150147

151148
func testSwiftPackageInitLib() throws {
149+
try skipUnlessAtLeastSwift6()
150+
152151
try withTemporaryDirectory { tempDir in
153152
// Create a new package with an executable target.
154153
let packagePath = tempDir.appending(component: "Project")
@@ -167,6 +166,8 @@ final class BasicTests: XCTestCase {
167166
}
168167

169168
func testSwiftPackageLibsTests() throws {
169+
try skipUnlessAtLeastSwift6()
170+
170171
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
171172

172173
try withTemporaryDirectory { tempDir in
@@ -225,9 +226,7 @@ final class BasicTests: XCTestCase {
225226
}
226227

227228
func testSwiftRun() throws {
228-
#if swift(<5.5)
229-
try XCTSkipIf(true, "skipping because host compiler doesn't support '-entry-point-function-name'")
230-
#endif
229+
try skipUnlessAtLeastSwift6()
231230

232231
try withTemporaryDirectory { tempDir in
233232
let packagePath = tempDir.appending(component: "secho")
@@ -256,6 +255,8 @@ final class BasicTests: XCTestCase {
256255
}
257256

258257
func testSwiftTest() throws {
258+
try skipUnlessAtLeastSwift6()
259+
259260
try XCTSkip("FIXME: swift-test invocations are timing out in Xcode and self-hosted CI")
260261

261262
try withTemporaryDirectory { tempDir in
@@ -377,3 +378,9 @@ private extension Character {
377378
}
378379
}
379380
}
381+
382+
private func skipUnlessAtLeastSwift6() throws {
383+
#if compiler(<6.0)
384+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
385+
#endif
386+
}

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ final class SwiftPMTests: XCTestCase {
5353
#if !os(macOS)
5454
try XCTSkip("Test requires macOS")
5555
#endif
56+
#if swift(<6.0)
57+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
58+
#endif
5659

5760
try withTemporaryDirectory { tmpDir in
5861
let packagePath = tmpDir.appending(component: "foo")

Sources/Build/BuildDescription/SwiftTargetBuildDescription.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ public final class SwiftTargetBuildDescription {
389389
"""
390390
import Foundation
391391
392+
#if compiler(>=6.0)
393+
extension Foundation.Bundle: @unchecked @retroactive Sendable {}
394+
#else
395+
extension Foundation.Bundle: @unchecked Sendable {}
396+
#endif
392397
extension Foundation.Bundle {
393398
static let module: Bundle = {
394399
let mainPath = \(mainPathSubstitution)

Sources/CoreCommands/SwiftCommandState.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -882,23 +882,6 @@ public final class SwiftCommandState {
882882
}
883883

884884
var extraManifestFlags = self.options.build.manifestFlags
885-
// Disable the implicit concurrency import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a Concurrency module.
886-
if DriverSupport.checkSupportedFrontendFlags(
887-
flags: ["disable-implicit-concurrency-module-import"],
888-
toolchain: try self.toolsBuildParameters.toolchain,
889-
fileSystem: self.fileSystem
890-
) {
891-
extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"]
892-
}
893-
// Disable the implicit string processing import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a StringProcessing module.
894-
if DriverSupport.checkSupportedFrontendFlags(
895-
flags: ["disable-implicit-string-processing-module-import"],
896-
toolchain: try self.toolsBuildParameters.toolchain,
897-
fileSystem: self.fileSystem
898-
) {
899-
extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"]
900-
}
901-
902885
if self.logLevel <= .info {
903886
extraManifestFlags.append("-v")
904887
}

Sources/PackageModel/ToolsVersion.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ public struct ToolsVersion: Equatable, Hashable, Codable, Sendable {
182182

183183
// Otherwise, use 4.2
184184
return .v4_2
185-
186-
default:
187-
// Anything above 4 major version uses version 5.
185+
case 5:
188186
return .v5
187+
default:
188+
// Anything above 5 major version uses version 6.
189+
return .v6
189190
}
190191
}
191192
}

0 commit comments

Comments
 (0)