MacOS platform required to run macro unit tests: Why?

When you make a new macro Swift package, e.g., using swift package init --type macro, the tests indicate:
// Macro implementations build for the host, so the corresponding module is not available when cross-compiling. Cross-compiled tests may still make use of the macro itself in end-to-end tests.

This seems to mean you have run the macro tests on a MacOS platform. Why is this? E.g., why can't I run the tests on an iOS simulator?

Thanks!

The macro itself will be executed on the host during compilation (remember that the macros are expanded at compilation time, not runtime). The macro’s tests should thus also be run on the host. In theory you could be using APIs in your macro that aren’t available on iOS, which means that your macro plugin wouldn’t even compile for the iOS simulator.

4 Likes