Is there a way for `swift test` to infer the C++ interop mode?

I have a Package.swift which leverages C++ interop with the following target:

    .target(
      name: "MyTarget",
      dependencies: ["CxxDependency"],
      swiftSettings: [
        .interoperabilityMode(.Cxx)
      ]),

...and a single test target:

    .testTarget(
      name: "MyTargetTests",
      dependencies: ["MyTarget"],
      swiftSettings: [
        .interoperabilityMode(.Cxx)
      ]),

However when I run swift test I get the following error:

error: module 'MyTargetTests' was built with C++ interoperability enabled, but current compilation does not enable C++ interoperability
@testable import MyTargetTests
                 ^

Running swift test -Xswiftc -cxx-interoperability-mode=default fixes the issue, so this isn't a huge deal. Just curious: is there a way to get this "special" project being compiled to run the tests to infer the compatibility mode?

Hey, this is a known issue: Auto Generated *PackageDiscoveredTest Is Incompatible With C++ Interop · Issue #6990 · apple/swift-package-manager · GitHub . Unfortunately your workaround is the only solution I know of so far, so I don't think we have other fixes for the "special" project yet.

2 Likes

That's what I figured, thanks for the confirmation!