Skip to content
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

build: upgrade clang-format to v18 #53957

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

RedYetiDev
Copy link
Member

@RedYetiDev RedYetiDev commented Jul 19, 2024

Fixes #50157

This PR updates the Clang formatter from the unmaintained clang-format to @magic-akari's amazing @wasm-fmt/clang-format library.

The old formatter was unmaintained and vastly out of date.

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 19, 2024
@RedYetiDev RedYetiDev added build Issues and PRs related to build files or the CI. tools Issues and PRs related to the tools directory. review wanted PRs that need reviews. labels Jul 19, 2024
Copy link

@magic-akari magic-akari left a comment

Choose a reason for hiding this comment

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

It is my honor that you are using @wasm-fmt/clang-format.

I believe that some stylistic differences may arise from the version of LLVM in use.
The current version of @wasm-fmt/clang-format is based on LLVM 16.0.6.

Should you have specific requirements regarding the LLVM version, I am prepared to release the version that meets your needs.

tools/clang-format/clang-format.mjs Outdated Show resolved Hide resolved
@RedYetiDev
Copy link
Member Author

RedYetiDev commented Jul 20, 2024

Oh! I thought it was v19. Nevertheless, it's newer than angular and actively maintained.

No need to prepare anything special, this is only a draft, and I'm not a core collaborator...

I'm curious to see the feedback on this, as I'm hoping that an update of the formatter (this) (along with the linter in another PR) will help keep the CPP code clean and organized for the future.


The stylistic issues are a result of both the linter and LLVM, so I'm hoping that if the linter is updated, at least one of them will be resolved. I'm going to do more testing to see if they are compatible with each other out of the box, but if not I can always configure the linter to work with the formatter.

@RedYetiDev RedYetiDev changed the title build: upgrade clang-format to v19. build: upgrade clang-format to use WASM Jul 20, 2024
@targos
Copy link
Member

targos commented Jul 20, 2024

The second commit is not acceptable. We've been using a clang-format option that only formats the modified lines to avoid a huge change like this one.

@magic-akari
Copy link

The second commit is not acceptable. We've been using a clang-format option that only formats the modified lines to avoid a huge change like this one.

So, we need to support range formats, right?

@RedYetiDev
Copy link
Member Author

I've undone the file changes to make review easier, but that doesn't mean this is ready for review.

@RedYetiDev
Copy link
Member Author

So, we need to support range formats, right?

I'm not an expert, but I think clang supports them in https://github.com/llvm/llvm-project/blob/710dab6e18ad9ed22c2529b9125d7b8813165ede/clang/tools/clang-format/ClangFormat.cpp#L234-L274, does your package have a config that allows them?

@RedYetiDev RedYetiDev changed the title build: upgrade clang-format to use WASM build: upgrade clang-format to v18 Jul 20, 2024
@RedYetiDev
Copy link
Member Author

Okay, I've switched it to a fork which is basically a copy of angular's, except updated to v18. If the WASM one supports the needs, I'm happy to switch it back, this change is (hopefully) only temporary.

@RedYetiDev RedYetiDev marked this pull request as ready for review July 20, 2024 13:45
@RedYetiDev
Copy link
Member Author

Okay, this fork (suprisingly) works well. It only lints the modified files and lines. I'd love to use the WASM version if it gains that support, because who doesn't love WASM, but (at least for now) this fork works!

(Sorry for dragging you around @magic-akari)

@RedYetiDev
Copy link
Member Author

Also, node-core-clang-format is currently at https://github.com/RedYetiDev/node-core-clang-format, but that can always be moved if needed.

@magic-akari
Copy link

So, we need to support range formats, right?

I'm not an expert, but I think clang supports them in https://github.com/llvm/llvm-project/blob/710dab6e18ad9ed22c2529b9125d7b8813165ede/clang/tools/clang-format/ClangFormat.cpp#L234-L274, does your package have a config that allows them?

Not now, but I am very willing to support them.

@RedYetiDev
Copy link
Member Author

RedYetiDev commented Jul 20, 2024

Great! If your package supports them, that'd be lovely, but I'd hold off on modifying it for a bit, because this change still needs to be reviewed by the core collaborators.

If this does land, and then your package fits the needs, I'd push for moving node-core-clang-format into the org, and having your package as a dep. but that's waaaaay in the future from this point.

@targos
Copy link
Member

targos commented Jul 20, 2024

fwiw I started working on a fork as well (https://github.com/targos/clang-format/tree/test-build). I just didn't have much time to continue. I think it's important to have an approach where the builds can be trusted. That's why I investigated doing them on GitHub actions.

@RedYetiDev
Copy link
Member Author

RedYetiDev commented Jul 20, 2024

Regarding GitHub actions, I came across https://github.com/muttleyxd/clang-tools-static-binaries, which uploads copies of them.
I figured that, if this were to land, it could be automated with something similar.

Although that's a step for the future IMO.

@RedYetiDev
Copy link
Member Author

Sweet! All tests are passing :-)

@magic-akari
Copy link

Starting from version 17.0.6, @wasm-fmt/clang-format supports range formatting.
I plan to incorporate it into my other projects.
Moreover, the versioning will align with LLVM, and I will update with each new LLVM release.

@RedYetiDev
Copy link
Member Author

RedYetiDev commented Jul 21, 2024

Great! I'll try to incorporate it into this PR soon, but I'm quite busy for the rest of this month (sorry!)

Thank you so so much for your development and help to incorporate it, it's truly amazing.

tools/clang-format/package.json Outdated Show resolved Hide resolved
@RedYetiDev RedYetiDev marked this pull request as draft July 22, 2024 00:15
@RedYetiDev
Copy link
Member Author

Hey everyone, I’m a bit busy for the next week or two, I know this was unfortunate time to open this PR, but I’ll undraft when I get a chance to complete it.

thanks!

@magic-akari
Copy link

Starting from version 18.1.6, you can effortlessly swap out angular's clang-format for a drop-in replacement with @wasm-fmt/clang-format.

@RedYetiDev
Copy link
Member Author

Thanks! I'm still out of town, but I'll check it out in a few days!

Copy link

@magic-akari magic-akari left a comment

Choose a reason for hiding this comment

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

Since I don't have approval access, I can only give a LGTM. 👍

@RedYetiDev
Copy link
Member Author

All tests pass, lint error is unrelated to this PR and was patched in a different PR.

@RedYetiDev
Copy link
Member Author

Thanks for your feedback, @magic-akari. @anonrig care to re-review?

Copy link
Member Author

@RedYetiDev RedYetiDev left a comment

Choose a reason for hiding this comment

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

Review notes

@@ -9,11 +9,11 @@ AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
Copy link
Member Author

@RedYetiDev RedYetiDev Aug 7, 2024

Choose a reason for hiding this comment

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

Review note: This was changed, as AllowShortBlocksOnASingleLine is a Never/Empty/Always value.

https://clang.llvm.org/docs/ClangFormatStyleOptions.html#allowshortblocksonasingleline

AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
Copy link
Member Author

@RedYetiDev RedYetiDev Aug 7, 2024

Choose a reason for hiding this comment

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

Review note: This was changed, as the behavior of AllowShortLoopsOnASingleLine was changed since this was true. In order for formatting to remain the same as it currently is, AllowShortLoopsOnASingleLine should be false.

https://clang.llvm.org/docs/ClangFormatStyleOptions.html#allowshortloopsonasingleline

@RedYetiDev
Copy link
Member Author

@anonrig @targos It's been a week without any objections, any more comments?

@targos
Copy link
Member

targos commented Aug 14, 2024

Changes LGTM. @nodejs/security-wg can you have a look?

@RedYetiDev
Copy link
Member Author

@targos you merged main into this branch, would you like me to rebase?

@RedYetiDev
Copy link
Member Author

No objections from the security team in a week, WDYT?

"name": "node-core-clang-format",
"version": "1.0.0",
"description": "Formatting C++ files for Node.js core",
"license": "MIT",
Copy link
Member

Choose a reason for hiding this comment

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

Why this was removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because this isn't a package, so it doesn't make sense to have a package name, it may confuse users.

Copy link
Member

Choose a reason for hiding this comment

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

I think an empty package json is more confusing

Copy link
Member Author

Choose a reason for hiding this comment

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

I just think the name, version, and license are misleading, as there isn't any source code here.

Copy link
Member Author

Choose a reason for hiding this comment

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

@marco-ippolito I've re-added the description, do you want me to add the rest?

@targos
Copy link
Member

targos commented Aug 24, 2024

I don't know how I did this merge. In any case, it was unintentional, sorry.

@RedYetiDev RedYetiDev added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Aug 29, 2024
@RedYetiDev RedYetiDev removed c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. review wanted PRs that need reviews. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

the npm clang-format package is unmaintained and obsolete
6 participants