Skip to content

Update -swift-version to default to 6 for swift-tools-version 6 #7469

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 1 commit into from
May 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ let package = Package(
targets: [
.executableTarget(name: "MyExecutable"),
.executableTarget(name: "MyExecutable2"),

.plugin(
name: "MyPlugin",
capability: .buildTool(),
dependencies: [
"MyExecutable"
]
),

.plugin(
name: "MyPlugin2",
capability: .buildTool(),
Expand All @@ -34,5 +34,6 @@ let package = Package(
"MyPlugin2",
]
),
]
],
swiftLanguageVersions: [.v5]
Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense!

)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP

let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputData = outputString.data(using: .utf8)
FileManager.default.createFile(atPath: outputFile, contents: outputData)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP

let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputData = outputString.data(using: .utf8)
FileManager.default.createFile(atPath: outputFile, contents: outputData)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP

let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputData = outputString.data(using: .utf8)
FileManager.default.createFile(atPath: outputFile, contents: outputData)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ let variableName = URL(fileURLWithPath: inputFile).deletingPathExtension().lastP

let inputData = FileManager.default.contents(atPath: inputFile) ?? Data()
let dataAsHex = inputData.map { String(format: "%02hhx", $0) }.joined()
let outputString = "public var \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputString = "public let \(variableName) = \(dataAsHex.quotedForSourceCode)\n"
let outputData = outputString.data(using: .utf8)
FileManager.default.createFile(atPath: outputFile, contents: outputData)
25 changes: 16 additions & 9 deletions IntegrationTests/Tests/IntegrationTests/BasicTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class BasicTests: XCTestCase {

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

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

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

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

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

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

Expand All @@ -149,6 +146,8 @@ final class BasicTests: XCTestCase {
}

func testSwiftPackageInitLib() throws {
try skipUnlessAtLeastSwift6()

try withTemporaryDirectory { tempDir in
// Create a new package with an executable target.
let packagePath = tempDir.appending(component: "Project")
Expand All @@ -167,6 +166,8 @@ final class BasicTests: XCTestCase {
}

func testSwiftPackageLibsTests() throws {
try skipUnlessAtLeastSwift6()

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

try withTemporaryDirectory { tempDir in
Expand Down Expand Up @@ -225,9 +226,7 @@ final class BasicTests: XCTestCase {
}

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

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

func testSwiftTest() throws {
try skipUnlessAtLeastSwift6()

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

try withTemporaryDirectory { tempDir in
Expand Down Expand Up @@ -377,3 +378,9 @@ private extension Character {
}
}
}

private func skipUnlessAtLeastSwift6() throws {
#if compiler(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif
}
3 changes: 3 additions & 0 deletions IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ final class SwiftPMTests: XCTestCase {
#if !os(macOS)
try XCTSkip("Test requires macOS")
#endif
#if swift(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif

try withTemporaryDirectory { tmpDir in
let packagePath = tmpDir.appending(component: "foo")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ package final class SwiftTargetBuildDescription {
"""
import Foundation

#if compiler(>=6.0)
extension Foundation.Bundle: @unchecked @retroactive Sendable {}
#else
extension Foundation.Bundle: @unchecked Sendable {}
#endif
extension Foundation.Bundle {
static let module: Bundle = {
let mainPath = \(mainPathSubstitution)
Expand Down
17 changes: 0 additions & 17 deletions Sources/CoreCommands/SwiftCommandState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -881,23 +881,6 @@ package final class SwiftCommandState {
}

var extraManifestFlags = self.options.build.manifestFlags
// 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.
if DriverSupport.checkSupportedFrontendFlags(
flags: ["disable-implicit-concurrency-module-import"],
toolchain: try self.toolsBuildParameters.toolchain,
fileSystem: self.fileSystem
) {
extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"]
}
// 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.
if DriverSupport.checkSupportedFrontendFlags(
flags: ["disable-implicit-string-processing-module-import"],
toolchain: try self.toolsBuildParameters.toolchain,
fileSystem: self.fileSystem
) {
extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"]
}

if self.logLevel <= .info {
extraManifestFlags.append("-v")
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/PackageModel/ToolsVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ public struct ToolsVersion: Equatable, Hashable, Codable, Sendable {

// Otherwise, use 4.2
return .v4_2

default:
// Anything above 4 major version uses version 5.
case 5:
return .v5
default:
// Anything above 5 major version uses version 6.
return .v6
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions Sources/SPMTestSupport/XCTSkipHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2024 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
import PackageModel
import XCTest

import class TSCBasic.Process
import struct TSCBasic.StringError

extension Toolchain {
package func skipUnlessAtLeastSwift6(
file: StaticString = #file,
line: UInt = #line
) async throws {
#if compiler(<6.0)
try XCTSkipIf(true, "Skipping because test requires at least Swift 6.0")
#endif
}
}
47 changes: 47 additions & 0 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6368,4 +6368,51 @@ final class BuildPlanTests: XCTestCase {
]
)
}

func testDefaultVersions() throws {
let fs = InMemoryFileSystem(emptyFiles:
"/Pkg/Sources/foo/foo.swift"
)

let expectedVersions = [
ToolsVersion.v4: "4",
ToolsVersion.v4_2: "4.2",
ToolsVersion.v5: "5",
ToolsVersion.v6_0: "6",
ToolsVersion.vNext: "6"
]
for (toolsVersion, expectedVersionString) in expectedVersions {
let observability = ObservabilitySystem.makeForTesting()
let graph = try loadModulesGraph(
fileSystem: fs,
manifests: [
Manifest.createRootManifest(
displayName: "Pkg",
path: "/Pkg",
toolsVersion: toolsVersion,
targets: [
TargetDescription(
name: "foo"
),
]
),
],
observabilityScope: observability.topScope
)

let result = try BuildPlanResult(plan: BuildPlan(
buildParameters: mockBuildParameters(),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
))

XCTAssertMatch(
try result.target(for: "foo").swiftTarget().compileArguments(),
[
"-swift-version", .equal(expectedVersionString)
]
)
}
}
}
3 changes: 2 additions & 1 deletion Tests/BuildTests/BuildSystemDelegateTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import XCTest
import var TSCBasic.localFileSystem

final class BuildSystemDelegateTests: XCTestCase {
func testDoNotFilterLinkerDiagnostics() throws {
func testDoNotFilterLinkerDiagnostics() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()
try XCTSkipIf(!UserToolchain.default.supportsSDKDependentTests(), "skipping because test environment doesn't support this test")
try fixture(name: "Miscellaneous/DoNotFilterLinkerDiagnostics") { fixturePath in
#if !os(macOS)
Expand Down
12 changes: 9 additions & 3 deletions Tests/FunctionalTests/PluginTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ final class PluginTests: XCTestCase {
}
}

func testBuildToolWithoutOutputs() throws {
func testBuildToolWithoutOutputs() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

Expand Down Expand Up @@ -1155,7 +1157,9 @@ final class PluginTests: XCTestCase {
}
}

func testURLBasedPluginAPI() throws {
func testURLBasedPluginAPI() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

// Only run the test if the environment in which we're running actually supports Swift concurrency (which the plugin APIs require).
try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

Expand All @@ -1165,7 +1169,9 @@ final class PluginTests: XCTestCase {
}
}

func testDependentPlugins() throws {
func testDependentPlugins() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try XCTSkipIf(!UserToolchain.default.supportsSwiftConcurrency(), "skipping because test environment doesn't support concurrency")

try fixture(name: "Miscellaneous/Plugins/DependentPlugins") { fixturePath in
Expand Down
5 changes: 4 additions & 1 deletion Tests/FunctionalTests/ResourcesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

import Basics
import PackageModel
import SPMTestSupport
import XCTest

Expand Down Expand Up @@ -126,7 +127,9 @@ class ResourcesTests: XCTestCase {
}
}

func testResourcesOutsideOfTargetCanBeIncluded() throws {
func testResourcesOutsideOfTargetCanBeIncluded() async throws {
try await UserToolchain.default.skipUnlessAtLeastSwift6()

try testWithTemporaryDirectory { tmpPath in
let packageDir = tmpPath.appending(components: "MyPackage")

Expand Down
Loading