mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.94k stars 186 forks source link

clang-tools-extra #105

Closed RussellHaley closed 3 years ago

RussellHaley commented 4 years ago

Hi Martin,

I hope your well. I was wondering if there is currently a way to build the clang-tools-extra packages for Windows? I'd like specifically to get my hands on clang-tidy. My understanding is it can run a linter as well as the clang static analyzer checks?

mstorsjo commented 4 years ago

Just wanted to say that I might still look at this if I have more time later. I'm not familiar with all the tools in clang-tools-extra, as I think some of them might require python or other interpreted languages. But if the tools are in plain C++ and build successfully for mingw, it should be a pretty small change to enable building them (just increasing the build time for making releases). I've just been too swamped to get to this yet...

SquallATF commented 4 years ago

clang-tools-extra can simply enable build for mingw

RussellHaley commented 4 years ago

Hi @mstorsjo. I get too many emails and your message slipped past me (again). No problem, I'm also picking at lldb-mi (debugger machine interface), which is actually more of a need at the moment. I'll open a separate ticket for that.

I did attempt to build the entire LLVM project but I don't see clang-tidy in the output. I'll try again as soon as I can. I'm actually using CMake at work now so I may be in a better place to discern what is happening.

Thanks!

longnguyen2004 commented 4 years ago

lldb-mi would require patches to compile successfully, which @mstorsjo is strongly against. Also, it's not part of the llvm monorepo anymore, which is weird. Lastly, it also requires a curses implementation, which would cause more hassle when building. You'd be better off using an IDE with Debug Adapter Protocol support.

RussellHaley commented 4 years ago

Thanks for the input @longnguyen2004. I'll create a different issue to discuss.

RussellHaley commented 4 years ago

Okay, well as usual (when dealing with me) there seems to be some 'error behind keyboard'. I went back to a clean checkout and added clang-tools-extra to the symlink loop and the -DLLVM_ENABLE_PROJECTS. I can see it is configured and it builds but doesn't install. I can see the binary in the i686-w64-mingw32 build directory.

I am currently reading about install-distribution: https://llvm.org/docs/BuildingADistribution.html. Perhaps clang-tidy needs a separate configuration item to install clang-tidy. I'll keep poking.

mstorsjo commented 4 years ago

It looks like clang-tools-extra requires a bit of different logic for enabling; you don't link/enable it like the other project subdirs, but you either symlink it into clang/tools/extra, or specify the path to it via LLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR to cmake (which avoids symlinks, which is a bit problematic if building on actual windows).

So to enable it, you can do a modification like this:

diff --git a/build-llvm.sh b/build-llvm.sh
index 4d76f08..db8b416 100755
--- a/build-llvm.sh
+++ b/build-llvm.sh
@@ -179,6 +179,7 @@ cmake \
     -DLLDB_ENABLE_CURSES=OFF \
     -DLLDB_ENABLE_LUA=OFF \
     -DLLDB_INCLUDE_TESTS=OFF \
+    -DLLVM_EXTERNAL_CLANG_TOOLS_EXTRA_SOURCE_DIR=$(pwd)/../../clang-tools-extra \
     $CMAKEFLAGS \
     ..

Additionally, you need to whitelist the actual executables you want to keep in strip-llvm.sh, which otherwise will remove unrecognized executables named clang-*.

Enabling clang-tools-extra gives these potential following tools, which each weigh in at 30-60 MB, so one doesn't really want to include all of them unless there's a very specific need for them:

clang-apply-replacements
clang-change-namespace
clang-doc
clang-include-fixer
clang-move
clang-query
clang-reorder-fields
clang-tidy
clangd
clangd-fuzzer
clangd-indexer

But enabling it for your own builds should be pretty straightforward with the above patch at least!

mati865 commented 4 years ago

At MSYS2 we use -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;lld;lldb;openmp;polly": https://github.com/msys2/MINGW-packages/blob/6720d21ac9736c084def6391504837ec5db6b0b3/mingw-w64-clang/PKGBUILD#L305 That gives tools listed at: https://packages.msys2.org/package/mingw-w64-x86_64-clang-tools-extra?repo=mingw64

AFAIK no other changes are necessary to build them.

mstorsjo commented 4 years ago

At MSYS2 we use -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;compiler-rt;lld;lldb;openmp;polly": https://github.com/msys2/MINGW-packages/blob/6720d21ac9736c084def6391504837ec5db6b0b3/mingw-w64-clang/PKGBUILD#L305 That gives tools listed at: https://packages.msys2.org/package/mingw-w64-x86_64-clang-tools-extra?repo=mingw64

AFAIK no other changes are necessary to build them.

Yeah, if using LLVM_ENABLE_PROJECTS for enabling projects, one can enable clang-tools-extra just like the other ones.. When building on unix, I'm still symlinking in clang/lld/lldb into llvm/tools instead of using LLVM_ENABLE_PROJECTS though - for CMake/ccache reasons (*), and in that case, clang-tools-extra has to be symlinked differently.

(*) As long as all source code is below the CMake root project, llvm-project/llvm, multiple source trees can share a ccache, but if the source is at llvm/../clang, CMake ends up using absolute paths, which breaks any ccache reuse between source trees.

RussellHaley commented 3 years ago

I've had this work a couple of times now. Thanks for your help!

mstorsjo commented 2 years ago

FWIW, I made a new release with LLVM 14.0.0 now, https://github.com/mstorsjo/llvm-mingw/releases/tag/20220323, and I included clang-tools-extra in it (I included the clangd and clang-tidy tools).