Support standalone builds (work-in-progress)
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.
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?
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.
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.
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?
It's a 3-step "total standalone":
- Build and install LLVM.
- Build and install MLIR (using installed LLVM).
- Build and install Clang (using installed LLVM and MLIR).
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.
I'll defer this review to both @lanza and @smeenai