Skip to content

Pass '-needed…' linker flags for XCTest libraries to suppress warnings in test targets which exclusively use Swift Testing and enable LD_WARN_UNUSED_DYLIBS #379

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

@stmontgomery stmontgomery commented Apr 6, 2025

Xcode test targets are always linked with XCTest.framework and libXCTestSwiftSupport.dylib, since these flags are specified in their product type .xcspec:

-framework XCTest -lXCTestSwiftSupport

When a test target has enabled LD_WARN_UNUSED_DYLIBS (or manually passes -warn_unused_dylibs to the linker), and it exclusively uses Swift Testing (or more precisely, when it doesn’t directly link any symbols from any XCTest library listed above), currently two warnings will be shown:

⚠️ ld: warning: linking with (@rpath/XCTest.framework/Versions/A/XCTest) but not using any symbols from it
⚠️ ld: warning: linking with (@rpath/libXCTestSwiftSupport.dylib) but not using any symbols from it

These warnings should be suppressed by default. Test targets get these linker flags from the product type, and these libraries do need to be linked and loaded even if a test target doesn’t use XCTest.

This Radar tracks modifying the linker flags passed so they add -needed_framework XCTest and -needed-lXCTestSwiftSupport to suppress these warnings.

Fixes rdar://148694760

…s in test targets which exclusively use Swift Testing and enable LD_WARN_UNUSED_DYLIBS

Fixes rdar://148694760
@stmontgomery stmontgomery added the bug Something isn't working label Apr 6, 2025
@stmontgomery stmontgomery requested a review from briancroom April 6, 2025 15:35
@stmontgomery stmontgomery self-assigned this Apr 6, 2025
@stmontgomery
Copy link
Contributor Author

@swift-ci test

@stmontgomery stmontgomery merged commit fa0371a into swiftlang:main Apr 7, 2025
3 checks passed
@stmontgomery stmontgomery deleted the needed-XCTest-linker-flags branch April 7, 2025 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants