swift-package-manager: Testing macros in the OSS toolchain snapshots for macOS don't seem to work with SDK bundles

Description

I recently added the Testing library to my Android SDK bundles for Swift 6.1 and 6.2, finagolfin/swift-android-sdk@eb1567b1c, and it works well to cross-compile Testing tests using the latest linux snapshot toolchain and my CI-generated 6.1 SDK bundle, which I checked by cross-compiling @tayloraswift’s swift-png and its tests. 😄

However, @marcprux tells me the same didn’t work with the OSS mac toolchain snapshot when he tried it with another Testing repo, as he got errors saying:

error: external macro implementation type 'TestingMacros.TestDeclarationMacro' could not be found for macro 'Test'; plugin for module 'TestingMacros' not found

suggesting there is some issue with how these Testing macros are installed on macOS.

Reproduction

Follow the instructions to use my Android SDK bundle on macOS, except using the 6.1 bundle linked above, not 6.0.3 as I have not backported the Android patches in this repo to that tag. An alternative would be to try the linux SDK bundle generated by swift-sdk-generator, if it supports this Testing library.

Expected behavior

Testing tests cross-compile fine using the mac toolchain’s prebuilt macros, as they do on linux.

Environment

MacOS

Additional information

I have not reproduced this myself. Marc said he’d file this himself, but I’m doing it now so we don’t forget and so somebody behind this repo can take a look in the meantime.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 25 (25 by maintainers)

Commits related to this issue

Most upvoted comments

Possibly fixed by #8670, Marc, try it with the next trunk snapshot toolchain and let us know.

Looks like this is, or at least was, a bug in Swift Package Manager: in 6.1, it was checking whether the target triple represented macOS, and only then included the necessary macro plugin search paths to locate libTestingMacros.dylib in macOS toolchains. I think that was happening here (link from the release/6.1 branch):

https://github.com/swiftlang/swift-package-manager/blob/release/6.1/Sources/PackageModel/UserToolchain.swift#L676-L684

However, this code all changed somewhat recently in https://github.com/swiftlang/swift-package-manager/pull/8295 and it might have affected this, or perhaps even fixed the issue. I’m not certain, but it would be worth trying using a main development snapshot toolchain which has that change to see.

Regardless, I’m going to transfer this to SwiftPM since it’s something controlled at that layer. It may be a dupe, though.

Also I don’t see a .swiftmodule for TestingMacros. Dunno if that is needed in this context.

I don’t think it is, as the upcoming 6.1 toolchain for linux only has swift-6.1-DEVELOPMENT-SNAPSHOT-2025-03-07-a-fedora39/usr/lib/swift/linux/Testing.swiftmodule/x86_64-unknown-linux-gnu.swiftmodule and the aforementioned plugin usr/lib/swift/host/plugins/libTestingMacros.so, works fine with my 6.1 Android SDK bundle.