Skip to content

[6.2] Include search path for Swift Testing's macro plugin from toolchain if present #8706

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

Conversation

stmontgomery
Copy link
Contributor

Cherry-pick #8670 to 6.2

…f present (swiftlang#8670)

This modifies the logic for determining compiler flags for locating
Swift Testing content such that it will always include a search path for
Swift Testing's macro plugin at its newer, testing-specific location in
the toolchain, if that directory exists.

### Motivation:

Swift Testing installs a macro plugin library named `TestingMacros` into
the official Swift toolchains for several platforms. By convention, most
Swift macro plugins are installed into the toolchain's
`usr/lib/swift/host/plugins` directory. However, testing libraries are
somewhat special in the sense that they should generally only be
available for use in "non-product" targets, i.e. targets which are not
intended for distribution and only intended for use in qualifying the
main product targets which _will_ be distributed.

For that reason, in Darwin toolchains, Swift Testing's plugin is
installed into a different location than for other platforms:
`usr/lib/swift/host/plugins/testing` (note the final `testing/`
directory) — see the [CMake
rules](https://github.com/swiftlang/swift-testing/blob/72afbb418542654781a6b7853479c7e70a862b6f/Sources/TestingMacros/CMakeLists.txt#L67-L75)
where that is controlled. Over time, we'd like to move the macro plugin
on other platforms to that location for consistency, because the current
_inconsistent_ install path has caused friction for users if they
attempt to form search paths to the plugin on their own — see
swiftlang/swift-testing#1039. So this PR paves
the way for Swift Testing to begin to relocate its plugin by ensuring
that _if_ this distinct plugin directory exists in a toolchain, it will
be preferred.

### Modifications:

- Modify logic in `UserToolchain.swift` to begin passing `-plugin-path`
whenever the relevant, testing-specific plugin path exists in a
toolchain.
- Add a new test which validates this, by simulating the scenario of
_not_ having a custom toolchain and validating the expected flags are
passed. (This most closely matches the current scenario today of using
the toolchain included in Xcode, and in that toolchain the plugin is
already installed into the `testing/`-suffixed path.)

rdar://151319768
@stmontgomery stmontgomery self-assigned this May 21, 2025
@stmontgomery stmontgomery added enhancement build system Changes to interactions with build systems swift test Changes impacting `swift test` tool macros Support for macros labels May 21, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci test

@stmontgomery
Copy link
Contributor Author

@swift-ci test Windows platform

@dschaefer2 dschaefer2 merged commit f6e00e6 into swiftlang:release/6.2 May 22, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system Changes to interactions with build systems enhancement macros Support for macros swift test Changes impacting `swift test` tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants