-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[Clang] Replace vt_gen with LLVMCodeGenTypes #109601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Replace vt_gen with LLVMCodeGenTypes #109601
Conversation
@llvm/pr-subscribers-clang-codegen @llvm/pr-subscribers-clang Author: Tristan Ross (RossComputerGuy) ChangesFixes a build failure with Clang being built from standalone sources (environments like Nix). Exact error:
This fix can be reproduced via the following script (just set out to some remote source and monorepoSrc to your LLVM source dir):
Full diff: https://github.com/llvm/llvm-project/pull/109601.diff 1 Files Affected:
diff --git a/clang/lib/CodeGen/CMakeLists.txt b/clang/lib/CodeGen/CMakeLists.txt
index 868ec847b9634b..2b1be3f4c3035d 100644
--- a/clang/lib/CodeGen/CMakeLists.txt
+++ b/clang/lib/CodeGen/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen)
+ add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen)
+endif()
+
set(LLVM_LINK_COMPONENTS
AggressiveInstCombine
Analysis
|
a64ba9c
to
cab2a5c
Compare
clang/lib/CodeGen/CMakeLists.txt
Outdated
@@ -1,3 +1,7 @@ | |||
if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I would rather have the cases mirrored here - the path should always exist in general, it is only the standalone case that is special.
if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) | |
if(CLANG_BUILT_STANDALONE AND EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, will do.
clang/lib/CodeGen/CMakeLists.txt
Outdated
@@ -1,3 +1,7 @@ | |||
if(EXISTS ${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen AND CLANG_BUILT_STANDALONE) | |||
add_subdirectory(${LLVM_MAIN_SRC_DIR}/include/llvm/CodeGen llvm/lib/CodeGen) | |||
endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC, even in the standalone case, you need to identify the LLVM build and pass that in via LLVM_DIR
, why is that not sufficient for finding this include path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, are you meaning to use LLVM_DIR
instead of LLVM_MAIN_SRC_DIR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, LLVM_DIR
is passed to the CMake configure step to locate the build of LLVM. That should wire up the include path that should be needed either through a dependency on LLVMCodeGen or through a global include search path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure what you're meaning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that the vt_gen
target is undefined. This is expected. The target should be defined by LLVM, which is a dependency. You should be wiring up the targets from LLVM into the clang build, which would provide the dependency and avoid this issue. The target definition is setup by find_package(LLVM)
which is why you need to specify -D LLVM_DIR=...
to the CMake invocation when configuring clang standalone. The normal build is unified and the target is defined when clang is configured.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that on a clean configure + build?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, Nix always performs a clean configure and build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/CMakeLists.txt#L28-L38 I suspect that you just need to extend that with Nope, there is an explicit dependency on vt_gen
.vt_gen
.
Can you get away with the addition of LLVM_LINK_COMPONENTS LLVMCodeGenTypes
to the ClangCodeGen
target and remove the vt_gen
dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like CMake accepted that change, let's see if it actually compiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sweet, that worked.
I'm not familiar with how LLVM CodeGen works and I am a bit new to LLVM but I looked at |
8e4e93f
to
260d427
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This fixes the problem with standalone builds for me.
This drops the dependency edge between the compile step and generating |
260d427
to
b97cb5a
Compare
clang/lib/CodeGen/CMakeLists.txt
Outdated
@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS | |||
Target | |||
TargetParser | |||
TransformUtils | |||
LLVMCodeGenTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are lexicographically sorted, please maintain that invariant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, didn't realize that.
clang/lib/CodeGen/CMakeLists.txt
Outdated
@@ -31,6 +31,7 @@ set(LLVM_LINK_COMPONENTS | |||
Target | |||
TargetParser | |||
TransformUtils | |||
CodeGenTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is duplicated (L6).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
You're welcome, though it looks like CI is borked.
I've changed it from |
b97cb5a
to
6902072
Compare
Here, I'd missed adding |
Replaced by #109817 |
Fixes a build failure with Clang being built from standalone sources (environments like Nix).
Exact error:
This fix can be reproduced via the following script (just set out to some remote source and monorepoSrc to your LLVM source dir):