Skip to content

Fix incorrect implementation-only import for CMake build #553

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
merged 1 commit into from
Jul 19, 2024

Conversation

stmontgomery
Copy link
Contributor

This resolves a warning seen when building the project with CMake, since that style currently still requires @_implementationOnly import instead of private import or other access levels.

ABIEntryPoint.swift:12:16: warning: '_TestingInternals' inconsistently imported as implementation-only

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@stmontgomery stmontgomery added bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process labels Jul 19, 2024
@stmontgomery stmontgomery self-assigned this Jul 19, 2024
@stmontgomery
Copy link
Contributor Author

@swift-ci please test

@stmontgomery stmontgomery merged commit b19c9af into swiftlang:main Jul 19, 2024
3 checks passed
@stmontgomery stmontgomery deleted the fix-cmake-import-warnings branch July 19, 2024 02:44
stmontgomery added a commit that referenced this pull request Jul 19, 2024
…KE' (#554)

This removes the `SWT_BUILDING_WITH_CMAKE` compilation condition, and
the `@_implementationOnly import _TestingInternals` declarations it
guards.

### Motivation:

When support for building via CMake was first added (in #387), many
source files in the `Testing` target were modified to avoid using
`private`- or `internal`-level imports of the `_TestingInternals` module
and instead use the older `@_implementationOnly import` style when
building via CMake. As a result, many files have:

```swift
#if SWT_BUILDING_WITH_CMAKE
@_implementationOnly import _TestingInternals
#else
private import _TestingInternals
#endif
```

This has proven to be a maintenance problem for us, because as new files
are added over time, it's not immediately obvious that they need to use
this pattern for importing this module—leading to warnings when building
with CMake such as the one fixed by #553.

I wasn't aware of the reasoning behind the above change at the time, but
I investigated it recently and here's what I concluded: Early on, the
changes in #387 did _not_ enable Library Evolution (LE) for the
`Testing` module, meaning it was still a non-resilient module.
[SE-0409](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0409-access-level-on-imports.md)
states that all dependencies of non-resilient modules must be loaded by
clients, so it would make sense that under those conditions, the build
of a client who imports `Testing` would fail because clients do not have
visibility to the `_TestingInternals` module. However, in a later PR
commit LE was enabled, but nobody realized that those `import` code
changes were no longer necessary and could be reverted.

I was able to reproduce this and confirm the theory: I added an example
client target in the CMake build, then disabled LE in the `Testing`
module, and attempted to build the client. It failed with the expected
missing module error. Then, re-enabling LE and rebuilding everything,
the error went away. Hopefully this is sufficient proof that reverting
this is safe, but I'll check with the main contributor of that PR to
check and see if there were any other issues before landing.

But overall, the goal here is to simplify these imports to reduce
maintenance burden and fully embrace SE-0409.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working build 🧱 Affects the project's build configuration or process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants