Skip to content

Commit de3f697

Browse files
committed
Update -swift-version to default to 6 for swift-tools-version 6
We missed updating this when adding 6.0. The change itself is extremely simple, with the bulk being updates to our tests so they don't fail on old compiler versions (where language version "6" is unknown). Also removes disabling the concurrency and string processing imports from manifest loading, as this was causing the `package` global to not be main actor isolated by default and thus error in Swift 6. They seemed to have been disabled to avoid erroring in SDKs that didn't have them, but that is definitely not an issue any longer.
1 parent cca73b2 commit de3f697

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
@@ -405,6 +405,11 @@ package final class SwiftTargetBuildDescription {
405405
"""
406406
import Foundation
407407
408+
#if compiler(>=6.0)
409+
extension Foundation.Bundle: @unchecked @retroactive Sendable {}
410+
#else
411+
extension Foundation.Bundle: @unchecked Sendable {}
412+
#endif
408413
extension Foundation.Bundle {
409414
static let module: Bundle = {
410415
let mainPath = \(mainPathSubstitution)

Sources/CoreCommands/SwiftCommandState.swift

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

883883
var extraManifestFlags = self.options.build.manifestFlags
884-
// 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.
885-
if DriverSupport.checkSupportedFrontendFlags(
886-
flags: ["disable-implicit-concurrency-module-import"],
887-
toolchain: try self.toolsBuildParameters.toolchain,
888-
fileSystem: self.fileSystem
889-
) {
890-
extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"]
891-
}
892-
// 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.
893-
if DriverSupport.checkSupportedFrontendFlags(
894-
flags: ["disable-implicit-string-processing-module-import"],
895-
toolchain: try self.toolsBuildParameters.toolchain,
896-
fileSystem: self.fileSystem
897-
) {
898-
extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"]
899-
}
900-
901884
if self.logLevel <= .info {
902885
extraManifestFlags.append("-v")
903886
}

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
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import Basics
14+
import PackageModel
15+
import XCTest
16+
17+
import class TSCBasic.Process
18+
import struct TSCBasic.StringError
19+
20+
extension Toolchain {
21+
package func skipUnlessAtLeastSwift6(
22+
file: StaticString = #file,
23+
line: UInt = #line
24+
) async throws {
25+
#if compiler(<6.0)
26+
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
27+
#endif
28+
}
29+
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6368,4 +6368,51 @@ final class BuildPlanTests: XCTestCase {
63686368
]
63696369
)
63706370
}
6371+
6372+
func testDefaultVersions() throws {
6373+
let fs = InMemoryFileSystem(emptyFiles:
6374+
"/Pkg/Sources/foo/foo.swift"
6375+
)
6376+
6377+
let expectedVersions = [
6378+
ToolsVersion.v4: "4",
6379+
ToolsVersion.v4_2: "4.2",
6380+
ToolsVersion.v5: "5",
6381+
ToolsVersion.v6_0: "6",
6382+
ToolsVersion.vNext: "6"
6383+
]
6384+
for (toolsVersion, expectedVersionString) in expectedVersions {
6385+
let observability = ObservabilitySystem.makeForTesting()
6386+
let graph = try loadModulesGraph(
6387+
fileSystem: fs,
6388+
manifests: [
6389+
Manifest.createRootManifest(
6390+
displayName: "Pkg",
6391+
path: "/Pkg",
6392+
toolsVersion: toolsVersion,
6393+
targets: [
6394+
TargetDescription(
6395+
name: "foo"
6396+
),
6397+
]
6398+
),
6399+
],
6400+
observabilityScope: observability.topScope
6401+
)
6402+
6403+
let result = try BuildPlanResult(plan: BuildPlan(
6404+
buildParameters: mockBuildParameters(),
6405+
graph: graph,
6406+
fileSystem: fs,
6407+
observabilityScope: observability.topScope
6408+
))
6409+
6410+
XCTAssertMatch(
6411+
try result.target(for: "foo").swiftTarget().compileArguments(),
6412+
[
6413+
"-swift-version", .equal(expectedVersionString)
6414+
]
6415+
)
6416+
}
6417+
}
63716418
}

Tests/BuildTests/BuildSystemDelegateTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import XCTest
1717
import var TSCBasic.localFileSystem
1818

1919
final class BuildSystemDelegateTests: XCTestCase {
20-
func testDoNotFilterLinkerDiagnostics() throws {
20+
func testDoNotFilterLinkerDiagnostics() async throws {
21+
try await UserToolchain.default.skipUnlessAtLeastSwift6()
2122
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
2223
try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
2324
#if !os(macOS)

Tests/FunctionalTests/PluginTests.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ final class PluginTests: XCTestCase {
178178
}
179179
}
180180

181-
func testBuildToolWithoutOutputs() throws {
181+
func testBuildToolWithoutOutputs() async throws {
182+
try await UserToolchain.default.skipUnlessAtLeastSwift6()
183+
182184
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
183185
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
184186

@@ -1155,7 +1157,9 @@ final class PluginTests: XCTestCase {
11551157
}
11561158
}
11571159

1158-
func testURLBasedPluginAPI() throws {
1160+
func testURLBasedPluginAPI() async throws {
1161+
try await UserToolchain.default.skipUnlessAtLeastSwift6()
1162+
11591163
// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
11601164
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
11611165

@@ -1165,7 +1169,9 @@ final class PluginTests: XCTestCase {
11651169
}
11661170
}
11671171

1168-
func testDependentPlugins() throws {
1172+
func testDependentPlugins() async throws {
1173+
try await UserToolchain.default.skipUnlessAtLeastSwift6()
1174+
11691175
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")
11701176

11711177
try fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in

Tests/FunctionalTests/ResourcesTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Basics
14+
import PackageModel
1415
import SPMTestSupport
1516
import XCTest
1617

@@ -126,7 +127,9 @@ class ResourcesTests: XCTestCase {
126127
}
127128
}
128129

129-
func testResourcesOutsideOfTargetCanBeIncluded() throws {
130+
func testResourcesOutsideOfTargetCanBeIncluded() async throws {
131+
try await UserToolchain.default.skipUnlessAtLeastSwift6()
132+
130133
try testWithTemporaryDirectory { tmpPath in
131134
let packageDir = tmpPath.appending(components: "MyPackage")
132135

0 commit comments

Comments
 (0)