How to install clang-format on MinGW (Windows)?

0

1

I tried searching with pacman -Ss for clang-format, git-clang-format, etc, but I'm not having any luck.

However, I have seen some references to it on some other websites, implying it may exist (or have existed) somewhere.

Tyler Shellberg

Posted 2019-11-26T15:55:41.933

Reputation: 123

Answers

1

It turns out that MSYS2 already comes with clang installed, and clang comes with clang-format. As of my version of clang, I have clang-format 9.0.0 installed. it's possible much earlier versions of clang did not come with it installed.

Tyler Shellberg

Posted 2019-11-26T15:55:41.933

Reputation: 123

0

As utilities, clang-format and git-clang-format are available in several forms:

  • As a part of clang.

    [As noted by OP in the final comments below, and with OP's answer to their own question, these should be included with MSYS2/MingGW on Windows].

  • As pre-compiled Python wheels for Linux (only) available via pip (PyPI).

  • As modules available for Node.js. On Windows, use the standard Windows installer to install Node.js. Otherwise, example Linux package manager commands for installing Node.js are here.

Python

For Python versions on Linux, you may wish to try:

python3 -m pip install clang-format 

Node.js

Assuming Node.js is installed, you can also get them both with:

npm install -g clang-format

Note that on Windows, using the Node.js option seems to be the simplest solution for obtaining just clang-format and git-clang-format (without installing MinGW).


Anaksunaman

Posted 2019-11-26T15:55:41.933

Reputation: 9 278

The nodejs modules are just wrappers around the real clang-format, from what I can tell on that page. Doesn't that mean the normal clang-format executable still has to be installed somewhere, or did I misunderstand? – Tyler Shellberg – 2019-11-26T16:52:29.340

Is npm available on mingw/mingw64? I attempted Pacman -Ss npm and as well for "node", but got no results related to node-js. – Tyler Shellberg – 2019-11-26T17:08:00.313

No luck with nodejs either. Wondering if it's possible to build clang-format from source. clang, clang-analyzer, clang-tools-extra, compiler-rt, libblocksruntime (all version 9) are all available on mingw. Apparently clang itself isn't enough to run the compiler though. – Tyler Shellberg – 2019-11-26T17:18:39.857

I saw that you updated your post. With Python3, I get: ERROR: Could not find a version that satisfies the requirement clang-format (from versions: none) ERROR: No matching distribution found for clang-format. For nodejs, I cannot find how to install it on mingw. – Tyler Shellberg – 2019-11-26T18:02:25.890

Both of those alternative commands failed with the same error. No idea what you mean by "specialized". – Tyler Shellberg – 2019-11-26T18:18:33.387

I apparently have clang installed, though I cannot use it to compile anything. Here is an example of what pacman says regarding clang for my mingw: https://pastebin.com/peKkLrui

– Tyler Shellberg – 2019-11-26T18:36:20.550

e>error: target not found: npm``` – Tyler Shellberg – 2019-11-26T18:51:56.357

No. Mingw is its own version of linux. It is not Arch, nor Ubuntu nor anything else. It is also not the Windows Subsystem for Linux, though it is similar in purpose. (At least as I understand things) – Tyler Shellberg – 2019-11-26T19:23:13.877

Mingw is not Windows, though it is running inside of Windows. But if I install things inside Windows, Mingw will not see them - they must be installed through Mingw. IE, if I have Python installed in Windows, Mingw will not see it from its command prompt. If I install Python through Mingw, I cannot use it through a Windows shell prompt. They are separate. – Tyler Shellberg – 2019-11-26T19:31:54.640

I'm an idiot. Apparently clang-format is already included in Msys2/Mingw. Oof. – Tyler Shellberg – 2019-11-26T20:25:55.697