Skip to content

Replace cmake-format with gersemi#7789

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/replace-cmake-format-with-gersemi
Draft

Replace cmake-format with gersemi#7789
Copilot wants to merge 2 commits intomainfrom
copilot/replace-cmake-format-with-gersemi

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 27, 2026

Replaces cmake-format (cmakelang, pinned at 0.6.11) with gersemi as the CMake file formatter.

New files

  • .gersemirc — formatter config: 2-space indent, 80-char line length, favour-inlining
  • cmake/gersemi_definitions.cmake — stub definitions for custom CCF commands (add_ccf_app, add_e2e_test, add_picobench, etc.) and third-party Corrosion commands so gersemi understands their keyword argument structure

Modified scripts

  • scripts/check-cmake-format.sh — swaps cmake-format for gersemi --check / gersemi -i, replaces the per-file loop with a single batch invocation, adds set -o pipefail
  • scripts/setup-dev.shpip install cmakelangpip install gersemi
  • scripts/python-format-checks.sh — removes .cmake-format.py from black's file list

Removed

  • .cmake-format.py — 250-line cmake-format config, superseded by .gersemirc

Reformatted

All CMake files under cmake/, samples/, src/, tests/, and root CMakeLists.txt have been reformatted by gersemi. Changes are whitespace/layout only.

One benign warning remains: _message is flagged as unknown because it's CMake's internal save of the original message() builtin when overridden in the root CMakeLists.txt. This is expected and does not affect formatting.

Copilot AI and others added 2 commits March 27, 2026 17:41
- Add .gersemirc configuration (indent: 2, line_length: 80)
- Add cmake/gersemi_definitions.cmake with custom function stubs
- Update scripts/check-cmake-format.sh to use gersemi
- Update scripts/setup-dev.sh to install gersemi instead of cmakelang
- Update scripts/python-format-checks.sh to remove .cmake-format.py
- Update .github/skills/formatting-and-linting.md to reference gersemi
- Remove .cmake-format.py configuration file
- Reformat all CMake files with gersemi

Agent-Logs-Url: https://github.com/microsoft/CCF/sessions/1db57858-d495-453c-b63c-a69a8b6fc2bc

Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/CCF/sessions/1db57858-d495-453c-b63c-a69a8b6fc2bc

Co-authored-by: achamayou <4016369+achamayou@users.noreply.github.com>
@achamayou
Copy link
Copy Markdown
Member

@copilot is there a way to tweak gersemi settings so as to minimise the reformatting of our cmake?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot is there a way to tweak gersemi settings so as to minimise the reformatting of our cmake?

I tested all available gersemi settings against the original cmake-format output. The current config (indent: 2, line_length: 80, list_expansion: favour-inlining) already produces the smallest diff:

Configuration Changed lines Files
indent=2, len=80, favour-inlining (current) 1120 16
indent=2, len=90, favour-inlining 1157 16
indent=2, len=100, favour-inlining 1254 16
indent=2, len=120, favour-inlining 1295 16
indent=2, len=80, favour-expansion 1799 19
indent=4, len=80, favour-inlining 3034 18

The bulk of the diff (~714 of 1120 lines) is in the root CMakeLists.txt. The changes are structural differences between the two formatters' algorithms — gersemi consistently puts each keyword argument on its own line when wrapping and places the first argument on a new line after the opening parenthesis, while cmake-format tried to pack more onto the same line. These are style differences that no gersemi setting can eliminate.

The definitions and warn_about_unknown_commands settings don't affect the diff size — they only control whether gersemi emits warnings about unrecognised custom commands.

Copilot AI requested a review from achamayou March 27, 2026 17:55
@achamayou
Copy link
Copy Markdown
Member

@copilot how does the run time compare between gersemi and cmake-format on the repo?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 27, 2026

@copilot how does the run time compare between gersemi and cmake-format on the repo?

Benchmarked both on the repo's 22 CMake files (5 runs each, median wall-clock):

Tool Invocation style Time
gersemi single batch (as in new script) ~0.12s
cmake-format per-file loop (as in old script) ~3.14s
cmake-format single batch ~1.85s

gersemi is ~15–25× faster, largely because it processes all files in one Python process while the old script spawned a new cmake-format process per file. Even comparing single-batch invocations, gersemi is ~15× faster.

@achamayou
Copy link
Copy Markdown
Member

@copilot how does the run time compare between gersemi and cmake-format on the repo?

Benchmarked both on the repo's 22 CMake files (5 runs each, median wall-clock):

Tool Invocation style Time
gersemi single batch (as in new script) ~0.12s
cmake-format per-file loop (as in old script) ~3.14s
cmake-format single batch ~1.85s
gersemi is ~15–25× faster, largely because it processes all files in one Python process while the old script spawned a new cmake-format process per file. Even comparing single-batch invocations, gersemi is ~15× faster.

That's quite a bit quicker, arguably real time. What do you think @eddyashton?

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