-
Notifications
You must be signed in to change notification settings - Fork 303
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
Add formatting infrastructure to the project #2505
Conversation
313d830
to
932daad
Compare
a5752ad
to
17819d5
Compare
Thank you for this! On updating LLVM: Leaving it at 15 for now has been a conscious choice: My philosophy has been that it should be possible to build workerd using the LLVM version available in the default APT repo in the latest stable release of Ubuntu and Debian, so that developers can build workerd without having to build LLVM themselves or install it from an alternative repository like https://apt.llvm.org/ which is used in the CI build. For Debian (bookworm) that's currently 16 (also available on the earlier Debian Bullseye), for Ubuntu 22.04 it is LLVM 15, the recently introduced Ubuntu 24.04 supports LLVM 18. If we upgrade the version we use to build on CI to 18, we can easily introduce changes that break the build with lower versions. What we can do is to require LLVM 18 and document that installing it may require additional developer actions, or we can update the version we use on CI to 18, but leave the documented minimum version as is and just state that LLVM18 is recommended and add a CI job that uses LLVM16 so that it doesn't break. I would prefer to address compiler upgrades separately from this PR TBH, for now we can just say that clang-format-18 is required for linting. |
Yeah sure, I thought it'd be nice to upgrade our llvm version but I don't mind reverting this change and just requiring clang-format-18 for format |
17819d5
to
c784dd4
Compare
5cd2027
to
4569c12
Compare
Unfortunately format checking fails for me with |
Yea that warning is printed for about 5 files where we have embedded typescript in macros but macro expansion happens after syntax parsing and language recognition in clang-format so it gets confused. |
2e4abf4
to
19de564
Compare
32b5308
to
3382efc
Compare
That's unfortunate – does that only affect a few files or is it a broad issue? Perhaps we can manage this by manually excluding a few files until 19 comes out, or add
sections where appropriate. |
Got it sorted with clang-format-18, I edited the comment above. |
Running the script works on macOS now. Unfortunately, it takes 16s to finish on M1 after freezing on |
The pre-commit hook only runs on staged files, it shouldn't slow down commits at all unless you editted that specific file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @danlapid, I made some minor comments.
3382efc
to
b4c35c8
Compare
One thing that I did when I did the internal formatting was to go through the diff and find cases where clang-format made the code much less readable so I could selectively turn off clang-format for certain lines. I won't block on this because it was incredibly painstaking but if you fancy killing about half a day with some monotonous work then it would be an added bonus 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GG
tools/unix/apply-big-move.sh
Outdated
|
||
source "$(dirname -- $BASH_SOURCE)/find-python3.sh" | ||
PYTHON_PATH=$(get_python3) | ||
$PYTHON_PATH "$(dirname -- $BASH_SOURCE)/../cross/format.py" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW this is a slightly different approach taken than the internal big move script in that you are running against only those files changed wrt. the HEAD commit rather than all files which should be formatted.
The intention of the original approach was that you can use this script to actually apply the big move in the first place by running apply-big-move.sh --apply
so you can be sure you are doing the same (idempotent) thing when applying the big move in the first place and then applying it to each branch's commit.
That being said, assuming you run clang-format on (at least) the set of files that the format.py
script might format, this should still work fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the format.py script is the only way I used to clang-format so it should match :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh, I just realized that you actually changed the semantics of the original script when porting it - you added the --git
option to the script when porting it. This makes a lot more sense now.
tools/unix/apply-big-move.sh
Outdated
# | ||
# This ensures that if further changes are made to this file before the Big Move actually happens, | ||
# then the rebase command that rebases to the commit before the Big Move won't confuse bash. | ||
main "$@"; exit 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed over this, assuming that everything below apply_big_move()
is unchanged. LMK if not.
b4c35c8
to
ead8e82
Compare
Add infrastructure to format c++ files with clang-format. We require clang-format-18 because some of the clang-format options we're using have only been released with clang-format 18. General project llvm version required remains unchanged. Added: 1. clang-format file matching internal one 2. formatting tool based on python for cross-platform 3. pre-commit and pre-push hooks for formatting validation 4. Lint CI action.
ead8e82
to
9f42449
Compare
9f42449
to
d115adb
Compare
Thanks @danlapid! |
I'm having some trouble with
|
For anyone else coming into this try:
if anything goes wrong you can |
Fixes #2507
Add infrastructure to format c++ files with clang-format.
Added:
In terms of CR workflow here's what I was thinking:
Reviewing the entire CR is going to be difficult which is why it's split into 3 distinct commits:
Seeing as how this CR will probably take a while I will not try to resolve conflicts during the CR. Instead whenever we finish the CR I will revert to
At the very least should have @jp4a50 approval before merge.