Skip to content

[cmake] Build swift-testing with CMake. #387

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 14 commits into from
May 20, 2024
Merged

[cmake] Build swift-testing with CMake. #387

merged 14 commits into from
May 20, 2024

Conversation

jeffdav
Copy link
Contributor

@jeffdav jeffdav commented Apr 30, 2024

Add files needed to build swift-testing with CMake.

Motivation:

Being able to build with CMake is useful in many scenarios. The immediate need is to bring swift-testing to Windows. To do so we need to support a non-SPM path to allow building targets that would otherwise hit the export symbol limit on Windows.

Modifications:

  • Added CMake files to build Testing, TestingInternal, and TestingMacros.
  • Build TestingMacros as an ExternalProject targeting the build machine.
  • Add SwiftTesting_GenerateDerivedSources which generates a runner-swift-testing.swift and returns a variable that allows consumers to compile it with their sources.

Result:

  • Can build swift-testing with CMake. Example command lines:
cmake -S . -B b -G Ninja -D CMAKE_CXX_COMPILER=clang
cmake --build .\b
  • Example diff that converts swift-webdriver to use swift-testing via CMake.

Checklist:

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

@grynspan grynspan added enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs labels Apr 30, 2024
Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR! There's still some work to be done, but this is a great start.

@stmontgomery
Copy link
Contributor

Thank you @jeffdav! Appreciate the helpful contribution. I have several comments so far and will take a second pass tomorrow

@grynspan
Copy link
Contributor

grynspan commented May 1, 2024

Open question: how do we test this change?

@grynspan
Copy link
Contributor

grynspan commented May 1, 2024

@jeffdav Could we ask you to just push additional commits so it's easier for us to see incremental changes? We'll squash the whole thing when we merge the PR. Thanks!

@jeffdav
Copy link
Contributor Author

jeffdav commented May 1, 2024

No problem. I wasn't sure what the right thing to do was. I'd honestly prefer incremental diffs. :)

@jeffdav
Copy link
Contributor Author

jeffdav commented May 1, 2024

Oh, but github does have a little "compare" link next to each force-push, which I hadn't realized.

@grynspan
Copy link
Contributor

grynspan commented May 1, 2024

Something else for you to consider: we should have instructions somewhere (perhaps in a dedicated .md file in Documentation/) showing how to build swift-testing from source using CMake.

@jeffdav
Copy link
Contributor Author

jeffdav commented May 2, 2024

Something else for you to consider: we should have instructions somewhere (perhaps in a dedicated .md file in Documentation/) showing how to build swift-testing from source using CMake.

Added. I'd love feedback on the documentation (consider this a 1st draft).

@jeffdav jeffdav requested a review from grynspan May 2, 2024 19:33
Copy link
Contributor

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking good. I think disabling C++ exceptions on _TestingInternal will help make the experience a little smoother, but beyond that, it seems to be working as I would expect. Install story can come later.

Copy link
Contributor

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jeffdav
Copy link
Contributor Author

jeffdav commented May 16, 2024

@grynspan any further concerns on your side?

@grynspan
Copy link
Contributor

Nope, I defer to @etcwilde here.

(FYI we don't use Swift's C++ interop feature, so its lack of support for exceptions doesn't make a difference to us. However, we also don't throw any exceptions or intend to catch any, so it's moot.)

@grynspan
Copy link
Contributor

Oh—please update the file lists before merging. There are a number of new files added since you opened this PR.

@jeffdav
Copy link
Contributor Author

jeffdav commented May 16, 2024

Oh—please update the file lists before merging. There are a number of new files added since you opened this PR.

Done!

Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grynspan
Copy link
Contributor

@swift-ci please test

@grynspan
Copy link
Contributor

@jeffdav I know you folks obviously work with Windows. The Windows failure we're seeing is a compiler bug unrelated to your PR. If you're comfortable with merging the PR despite the failure, we can proceed. (I'm unsure if you can see a merge button—if not, ping me and I'll do it.)

@jeffdav
Copy link
Contributor Author

jeffdav commented May 19, 2024

@jeffdav I know you folks obviously work with Windows. The Windows failure we're seeing is a compiler bug unrelated to your PR. If you're comfortable with merging the PR despite the failure, we can proceed. (I'm unsure if you can see a merge button—if not, ping me and I'll do it.)

Yeah, I'm familiar with that compiler bug for other reasons. :)

@jeffdav
Copy link
Contributor Author

jeffdav commented May 20, 2024

@grynspan Thanks for your help! I don't have a merge button.

@grynspan
Copy link
Contributor

@swift-ci please test

@grynspan grynspan merged commit a12f93e into swiftlang:main May 20, 2024
2 of 3 checks passed
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
enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants