llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.78k stars 11.9k forks source link

[libc] incorrect dependencies in overlay mode #92337

Open DunskiPhilippe opened 5 months ago

DunskiPhilippe commented 5 months ago

Hello,

The problem

OCCURES When building llvmorg-18.1.5 tag from sources on linux.

According to the doc, CMake command as simple as

cmake ../llvm -G Ninja -DLLVM_ENABLE_PROJECTS="libc"  \
   -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
   -DCMAKE_BUILD_TYPE=<Debug|Release>                    \  # Select build type
   -DCMAKE_INSTALL_PREFIX=<Your prefix of choice>   

should lead to the ability to create an overlay mode for the libc. We should then be able to build libc with the ninja libc command, then to install an overlay version with the ninja install-llvmlibc one.

however, there is no PHONY named 'install-llvmlibc' generated. And so, ninja asks us if we meant install-llvmlib, which is not the same thing.

Additionally, if we simply attempt to install libc with the ninja install-libc command, ninja wants to install libc-startup as dependency to libc. However, libc-startup is supposed to be build only if LLVM_LIBC_FULL_BUILD is set to true, which is neither the case in overlay mode, nor the default value case

The solution

From what I understood during a quick search, the problem would come from the llvm-project/libc/lib/CMakeLists.txt file because a unconditional dependancy is set on a variable named startup_target for different custom targets (namely install-libc and install-libc-stripped )and, all that because the startup_target is systematically set to libc-startup if libc isn't build for barmetal. IMO, this dependency should not be set, at least on linux, when building libc in overlay mode. Heer is a patch this unerequired dependency:

diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index af7ef2de93dd..dc54648ef2bb 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -60,7 +60,12 @@ if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
   # and install it as part of the libc installation.
   set(startup_target "libc-startup")
 endif()
-
+# We should not depend on libc-startup in overlay mode
+if(NOT ${LLVM_LIBC_FULL_BUILD})
+  # Works at least on linux, but requires more investigations
+  # for other platforms
+  set(startup_target "")
+endif()
 if(LLVM_LIBC_FULL_BUILD)
   set(header_install_target install-libc-headers)
 endif()

"Fun fact" being that it makes makes libllvmlibc.a automatically installed with the ninja install-libc command .

Thanks for reading PS: Excuse me for my poor English, I usually speak in French

nickdesaulniers commented 5 months ago

I've yet to try ninja install-llvmlibc in either mode. I wonder where cmake would install those headers to?

cc @petrhosek @jhuber6 in case they have thoughts here.