clangir icon indicating copy to clipboard operation
clangir copied to clipboard

Support standalone builds (work-in-progress)

Open mgorny opened this issue 1 year ago • 7 comments

Per https://github.com/llvm/llvm-project/issues/119130. This is incomplete and non-working at this point, but I'd like some early feedback on the approach, especially since it is a bit tedious. I have included llvm/llvm-project#119408 too, since it made linking much easier via mlir_target_link_libraries.

mgorny avatar Dec 19 '24 12:12 mgorny

I guess we should rebase ClangIR on top of latest LLVM to have https://github.com/llvm/llvm-project/pull/119408 in it and simplify this PR first?

keryell avatar Dec 19 '24 17:12 keryell

I've gotten clang itself working — or at least it seems to compile trivial programs with -fclangir, and the examples seem to print something that looks ClangIR-y. I'm working on tests now. Once I'm done, I'll rebase on top of ClangIR main.

mgorny avatar Dec 22 '24 12:12 mgorny

Ok, it turned out easier than I anticipated. I think it's fine to merge it as-is, including the mlir backport, since the next rebase will simply "eat" it, or rebase-then-merge, if you prefer.

mgorny avatar Dec 22 '24 13:12 mgorny

With the invocation:

cmake -Sclang -Bclang/build/Release -DCMAKE_BUILD_TYPE=Release -DLLVM_DIR=build/Release/lib/cmake -DCLANG_ENABLE_CIR=YES -GNinja

on Linux-x86_64 I end up with

CMake Error at lib/FrontendTool/CMakeLists.txt:56 (mlir_target_link_libraries):
  Unknown CMake command "mlir_target_link_libraries".

The LLVM build does include MLIR. Is this the right standalone invocation?

lanza avatar Dec 23 '24 06:12 lanza

It's a 3-step "total standalone":

  1. Build and install LLVM.
  2. Build and install MLIR (using installed LLVM).
  3. Build and install Clang (using installed LLVM and MLIR).

mgorny avatar Dec 23 '24 06:12 mgorny

I mean, I suppose it will also work if you include MLIR in your LLVM build, i.e. -DLLVM_ENABLE_PROJECTS='llvm;mlir' but I haven't tried that, as it kinda defeats the purpose of standalone building.

mgorny avatar Dec 23 '24 06:12 mgorny

I'll defer this review to both @lanza and @smeenai

bcardosolopes avatar Jan 06 '25 15:01 bcardosolopes