Skip to content

chore(cmake): add CMake presets #5655

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 4 commits into from
May 14, 2025
Merged

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented May 12, 2025

Description

This adds CMakePresets, which simplify running CMake for pybind11's own test suite, and improves support for IDEs like VSCode.

Two presets are present:

  • cmake --workflow default will build and run tests basically the way we like to do it
  • cmake --workflow venv will use a .venv directory, creating it with uv if not already present

I've also added autodiscovery of a .venv directory by default if it's present and nothing specific was requested.

This requires CMake 3.25+ to run with the presets.

I need to work on two more things, as followups:

  • Ninja needs to work on Windows. That will enable these presets to be used on the main CI jobs
  • We need to move the tests into tests instead of build targets. This would integrate much more elegantly.

Suggested changelog entry:

* Add support for running pybind11's tests via presets in CMake 3.25+.

@henryiii henryiii force-pushed the henryiii/feat/presets branch 3 times, most recently from 29949c4 to 84b306f Compare May 13, 2025 02:52
@henryiii henryiii force-pushed the henryiii/feat/presets branch 2 times, most recently from fbeece2 to ffbedc2 Compare May 13, 2025 04:58
@henryiii henryiii force-pushed the henryiii/feat/presets branch from 7b79a41 to 90d366f Compare May 13, 2025 16:20
@henryiii henryiii marked this pull request as ready for review May 13, 2025 18:24
@henryiii henryiii force-pushed the henryiii/feat/presets branch from 90d366f to e7cf14f Compare May 13, 2025 22:13
@henryiii henryiii requested a review from Copilot May 14, 2025 04:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds CMakePresets to simplify running pybind11's test suite and improve IDE support. The changes include:

  • Adding CMakePresets.json and updating pyproject.toml to ignore it.
  • Introducing new CMake logic in CMakeLists.txt to autodetect and create a virtual environment.
  • Updating the CI workflow in .github/workflows/ci.yml to use the new presets.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pyproject.toml Updated ignore list to exclude CMakePresets.json
CMakePresets.json New file defining configuration, build, and workflow presets
CMakeLists.txt Added logic for autoconfiguring a virtual environment and installing dependencies
.github/workflows/ci.yml CI workflow updated to leverage the new CMake presets

Co-authored-by: Copilot <[email protected]>
@henryiii henryiii merged commit 05a6a03 into pybind:master May 14, 2025
112 of 113 checks passed
@henryiii henryiii deleted the henryiii/feat/presets branch May 14, 2025 05:29
@github-actions github-actions bot added the needs changelog Possibly needs a changelog entry label May 14, 2025
Copy link
Contributor

@cryos cryos left a comment

Choose a reason for hiding this comment

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

Looks great.

@henryiii henryiii removed the needs changelog Possibly needs a changelog entry label May 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants