Skip to content

Commit 4eb6d74

Browse files
authored
Allow enabling C++ interop without explicit version (#6416) (#6514)
The Swift compiler now supports `-cxx-interoperability-mode=default` flag. This change makes sure SwiftPM accepts `nil` as a version of Swift/C++ interoperability. rdar://107908465 (cherry picked from commit a54a87f)
1 parent 4352b87 commit 4eb6d74

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

Sources/PackageDescription/BuildSettings.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ public struct SwiftSetting {
377377
///
378378
/// - Parameters:
379379
/// - mode: The language mode, either C or CXX.
380-
/// - version: When using the CXX language mode, pass the version of Swift and C++
381-
/// interoperability; otherwise, `nil`.
380+
/// - version: When using the CXX language mode, pass either the version
381+
/// of Swift and C++ interoperability or `nil`; otherwise, `nil`.
382382
/// - condition: A condition that restricts the application of the build
383383
/// setting.
384384
@available(_PackageDescription, introduced: 5.9)

Sources/PackageLoading/PackageBuilder.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,14 +1089,7 @@ public final class PackageBuilder {
10891089
// `version` is the compatibility version of Swift/C++ interop,
10901090
// which is meant to preserve source compatibility for
10911091
// user projects while Swift/C++ interop is evolving.
1092-
// At the moment the only supported interop version is
1093-
// `swift-5.9` which is aligned with the version of
1094-
// Swift itself, but this might not always be the case
1095-
// in the future.
1096-
guard let version else {
1097-
throw InternalError("C++ interoperability requires a version (e.g. 'swift-5.9')")
1098-
}
1099-
values = ["-cxx-interoperability-mode=\(version)"]
1092+
values = ["-cxx-interoperability-mode=\(version ?? "default")"]
11001093
} else {
11011094
values = []
11021095
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,7 +3299,8 @@ final class BuildPlanTests: XCTestCase {
32993299
name: "exe", dependencies: ["bar"],
33003300
settings: [
33013301
.init(tool: .swift, kind: .define("FOO")),
3302-
.init(tool: .swift, kind: .interoperabilityMode(.C, nil)),
3302+
.init(tool: .swift, kind: .interoperabilityMode(.C, nil), condition: .init(platformNames: ["linux"])),
3303+
.init(tool: .swift, kind: .interoperabilityMode(.Cxx, nil), condition: .init(platformNames: ["macos"])),
33033304
.init(tool: .linker, kind: .linkedLibrary("sqlite3")),
33043305
.init(tool: .linker, kind: .linkedFramework("CoreData"), condition: .init(platformNames: ["macos"])),
33053306
.init(tool: .linker, kind: .unsafeFlags(["-Ilfoo", "-L", "lbar"])),
@@ -3377,7 +3378,7 @@ final class BuildPlanTests: XCTestCase {
33773378
XCTAssertMatch(bar, [.anySequence, "-DDMACOS", "-Isfoo", "-L", "sbar", "-cxx-interoperability-mode=swift-6.0", "-enable-upcoming-feature", "BestFeature", "-enable-upcoming-feature", "WorstFeature", .end])
33783379

33793380
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
3380-
XCTAssertMatch(exe, [.anySequence, "-DFOO", .end])
3381+
XCTAssertMatch(exe, [.anySequence, "-DFOO", "-cxx-interoperability-mode=default", .end])
33813382

33823383
let linkExe = try result.buildProduct(for: "exe").linkArguments()
33833384
XCTAssertMatch(linkExe, [.anySequence, "-lsqlite3", "-llibz", "-framework", "CoreData", "-framework", "best", "-Ilfoo", "-L", "lbar", .anySequence])

0 commit comments

Comments
 (0)