Skip to content

[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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Comment on lines +13 to +16
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #119426 for this.


if (LIBC_CMAKE_VERBOSE_LOGGING)
get_directory_property(LIBC_OLD_PREPROCESSOR_DEFS COMPILE_DEFINITIONS)
foreach(OLD_DEF ${LIBC_OLD_PREPROCESSOR_DEFS})
Expand All @@ -30,6 +37,14 @@ endif()
# Default to C++17
set(CMAKE_CXX_STANDARD 17)

if(LIBC_BUILT_STANDALONE)
# Python 3 is required and needs to be manually imported in
# a standalone build.
# NOTE: We specifically need pyyaml in order for hdrgen to work.
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.
Expand Down
Loading