Skip to content

If required clang-format version is not installed fetch it automatically#3574

Open
JonnyPtn wants to merge 1 commit intoSFML:masterfrom
JonnyPtn:fix_format
Open

If required clang-format version is not installed fetch it automatically#3574
JonnyPtn wants to merge 1 commit intoSFML:masterfrom
JonnyPtn:fix_format

Conversation

@JonnyPtn
Copy link
Contributor

Formatting can be a regular pain when contributing - You need to have the exact clang-format version and there's no clear indication which version that is (17 is not enough, it has to be the exact minor version)

Believe the required version is 17.0.6, so this adds pre-built binaries for Mac and linux (will add windows, and possibly other architectures if we are happy to use this approach)

While we can't control everyone's IDE/environment setup, we can control which version our format script uses, and including the binaries means we can guarantee everyone who runs that script will get the correct output.

@eXpl0it3r
Copy link
Member

Not really a fan of this, even if it makes part of the development easier in a sense.

We've finally managed to get rid of binaries in the repo, just to check-in new binaries.

I'd rather try and improve the strictness of the required version or provide more guidance or implement some auto-format workflow or something in this direction.

@JonnyPtn
Copy link
Contributor Author

Did we get rid of the dependency binaries because we believe pre-built binaries are inherently bad and should be avoided at all costs? If so, yes, this is dead in the water

I'd hope we did it because there was a better alternative that improves developer workflow. So look at the current workflow for formatting, reasonably assuming the majority of contributors won't have clang 17.0.6 set up in their environment:

  • Find the correct clang-format binary. Best I could find was the github releases, so I had to download ~800MB of llvm+clang just to get a 3MB clang-format binary
  • Reconfigure SFML to use that binary
  • Build the format target

And i have to remember to do that every time I'm contributing, across multiple machines/platforms.

Using pre-built binaries means that workflow is just "build the format target", for every contributor, on every platform (and on CI).

Do you think the current workflow is better? Yes we could look at automating the formatting but I'm always a bit skeptical about having CI submit code changes

@eXpl0it3r
Copy link
Member

There were multiple reasons why we removed binaries and it's not that prebuilt binaries are inherently bad. Two of the big ones were:

  • Building dependencies manually for every update for all platforms requires a ton of time, so we rarely updated the prebuilt binaries
  • Each binary blob bloats the repository size. Adding more dependencies like we've done with HarfBuzz, would've added many MB more. Sure it's currently "just" 3.x MB per platform (why is there no Windows binary?), but those blobs need to be updated every so often, so overtime it still accumulates and inflates the overall repository size

I don't think SFML needs "to fix" the delivery channel of LLVM tools, but even so, I'd rather publish the tool somewhere and fetch it in CI, instead of adding it to the repository.

@JonnyPtn
Copy link
Contributor Author

JonnyPtn commented Sep 15, 2025

Yeah so the building dependencies argument is irrelevant as it doesn't apply here - The repo size is the reason i was expecting, and yeah I can't really argue against it as it's subjective. For me a few extra MB in the repo to improve the workflow of almost every contributor is worth it.

Fetching the binaries when configuring cmake was an option I considered, but couldn't see a way to avoid the 800MB download without hosting our own binaries somewhere - if you are able to host them somewhere suitable I'm happy to update this PR to do that.

On the subject of updating it periodically - I expect that's going to happen quite rarely, as it would also involve reformatting the whole source code, but I also think pre-built binaries are an improvement here as we would be able to use a version which has our preffered formatting, rather than one which is conveniently available in CI (which I believe is why we're on the current version?). And of course, we can prune the blob history as part of that update process so the concern about history size is easy to solve

@eXpl0it3r
Copy link
Member

Even though it puts more maintenance work on us, I could see us creating a separate repo that distributes the binaries either in GitHub releases or in the repo itself, including the necessary license notice to comply with Apache License v2.0.

If the expected format version doesn't match, we could then conditionally download the format binary and ensure that the right executable is used.

@JonnyPtn
Copy link
Contributor Author

JonnyPtn commented Oct 2, 2025

I don't see much benefit in doing that, but it's still an improvement on the current situation so happy to run with it if it's a suitable compromise

@eXpl0it3r
Copy link
Member

I've PoC-ed this idea with a separate repo that has the binaries as GitHub release, here: https://github.com/eXpl0it3r/clang-format/releases

One could use it like so:

FetchContent_Declare(
    clang-format
    URL "https://github.com/eXpl0it3r/clang-format/releases/download/llvmorg-18.0.0/clang-format-windows-x64.exe"
    DOWNLOAD_NO_EXTRACT TRUE
)
FetchContent_MakeAvailable(clang-format)

@JonnyPtn
Copy link
Contributor Author

Thanks - have updated so that if clang-format isn't found (or isn't the correct version) it will download the required version from that repo

@JonnyPtn JonnyPtn changed the title Add clang-format binaries for consistent and easy formatting If required clang-format version is not installed fetch it automatically Oct 16, 2025
@JonnyPtn JonnyPtn marked this pull request as ready for review January 15, 2026 15:14
@JonnyPtn
Copy link
Contributor Author

Have rebased onto latest master and set ready for review

If we don't want to use this approach I still think we should consider other options to make it easier for contributors to handle formatting (and maybe analysis too) locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants