-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[libc] Find Python 3 in standalone #118871
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
Conversation
@llvm/pr-subscribers-libc Author: Tristan Ross (RossComputerGuy) Changes
Full diff: https://github.com/llvm/llvm-project/pull/118871.diff 1 Files Affected:
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 5196735bef4e76..cfe3e347980a37 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -8,6 +8,13 @@ endif()
include(${LLVM_COMMON_CMAKE_UTILS}/Modules/CMakePolicy.cmake
NO_POLICY_SCOPE)
+# If we are not building as a part of LLVM, build libc as an
+# standalone project, using LLVM as an external library:
+if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ project(libc)
+ set(LIBC_BUILT_STANDALONE TRUE)
+endif()
+
if (LIBC_CMAKE_VERBOSE_LOGGING)
get_directory_property(LIBC_OLD_PREPROCESSOR_DEFS COMPILE_DEFINITIONS)
foreach(OLD_DEF ${LIBC_OLD_PREPROCESSOR_DEFS})
@@ -30,6 +37,11 @@ endif()
# Default to C++17
set(CMAKE_CXX_STANDARD 17)
+if(LIBC_BUILT_STANDALONE)
+ find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
+ COMPONENTS Interpreter)
+endif()
+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
# The top-level source directory.
|
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.
Isn't there some external use of libc more standalone? I'll defer to @nickdesaulniers.
Thanks for the patch! How are you invoking the build @RossComputerGuy ? (i.e. what explicit command line commands are you running)? |
I'm running with these flags:
I have to specify |
What's the full cmake command? Specifically, what directory are you using as the root for cmake? |
I'm not sure how to extract the full on CMake command but I know it runs with |
libc/CMakeLists.txt
Outdated
if(LIBC_BUILT_STANDALONE) | ||
find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED | ||
COMPONENTS Interpreter) | ||
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.
we also need pyyaml
for newhdrgen. Not sure if that needs to be specified in the cmake, but adding a comment at least would be useful.
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'll add a comment about it at least, I'm not sure how we could add a check inside CMake to ensure the module exists.
275a03c
to
268a37e
Compare
Right, so in #78479, I'm trying to move to only documenting+supporting using llvm-project/runtimes dir as the root for cmake for building llvm-libc. It sounds like you (and @SchrodingerZhu ) are trying to use llvm-project/libc/ as the root for cmake for building llvm-libc. Is there a reason why you cannot use llvm-project/runtimes/ as the root for cmake for llvm-libc? i.e. $ cd llvm-project
$ mkdir build
$ cd build
$ cmake ../runtimes ...
<rather than>
$ cmake ../libc ... |
Oh, I wasn't aware of that change. I'm not sure what would be stopping Nixpkgs from using that once it's merged. Would this allow for building completely separate from the rest of things just like what is possible with |
Yes. We recently removed a dependency on tablegen, which implied a depedency on llvm. This should let us bootstrap clang itself from the libc (avoiding having to build llvm twice, one for libc, again for clang). |
In my case, it is just that llvm-project is too large to be packaged in a single rust package. But that experiment did not go out well. |
See https://github.com/SchrodingerZhu/rust-linux-llvm/blob/main/llvmlibc-src/src/update.sh for how to build libc fully out of tree. It may be broken already as @jhuber6 has reverted some needed changes. |
In that case, if there are no existing use cases, I'd prefer NOT to add more ways to build llvm-libc. Our documentation is already too confusing; we're actively trying to simplify it. We're also not continuously testing such a method of building, so we could regress it by accident. @RossComputerGuy can you please confirm whether my suggestion above (using |
@nickdesaulniers I did try it but I've ran into problems:
|
It can be fixed by adding in the cmake modules under llvm's root and llvm/cmake. |
Yeah, that did make it work. |
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) | ||
project(libc) | ||
set(LIBC_BUILT_STANDALONE TRUE) | ||
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.
Given that libc
doesn't support builds rooted in the libc
directory (and I don't think we want to add support for it), maybe we should be erroring out here instead.
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 don't think so, would we stop supporting standalone builds of everything else (clang, llvm, bolt, lldb, etc.) unless they use runtimes
? I don't really think an error is necessary.
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, but that's because clang, lldb, and maybe bolt, etc do support standalone builds rooted in their subdirectory. libc does not.
So erroring out here has no implications for those other subprojects, nor does the fact that they support standalone builds imply anything for what libc
should do about them.
A better comparison would be libcxx, which I believe does (or, at least, should) error out on builds rooted in the libcxx directory.
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 a warning (or error) would be a very user-friendly feature to add. Then we can point users in the right direction if they make a mistake.
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.
Opened #119426 for this.
Building with the source directory rooted in the libc subdirectory isn't tested in CI and can lead to subtle build problems (cf. llvm#118871). Let's fail fast with a helpful error message instead to help users configure libc correctly.
Building with the source directory rooted in the libc subdirectory isn't tested in CI and can lead to subtle build problems (cf. llvm#118871). Let's fail fast with a helpful error message instead to help users configure libc correctly. Co-authored-by: Nick Desaulniers <[email protected]>
Closing in favor of #119426. |
Building with the source directory rooted in the libc subdirectory isn't tested in CI and can lead to subtle build problems (cf. #118871). Let's fail fast with a helpful error message instead to help users configure libc correctly. Co-authored-by: Nick Desaulniers <[email protected]>
Python3_Executable
wasn't defined when libc is trying to be built in standalone mode. Also adds aproject
define so CMake quits complaining.