[libc] Introduce a full build mode CMake option.

This option will build LLVM libc as a full libc by itself. In this mode,
it is not expected that it will be mixed with other libcs. The
non-full-build mode will be the default LLVM libc build mode. In a future
where LLVM libc is complete enough, the full libc build will be made the
default mode.
This commit is contained in:
Siva Chandra Reddy 2021-03-11 15:25:24 -08:00
parent 4b8eb894bf
commit e9e788d145
8 changed files with 91 additions and 53 deletions

View File

@ -62,6 +62,8 @@ else()
(pass -DLLVM_LIBC_ENABLE_LINTING=ON to cmake).")
endif()
option(LLVM_LIBC_FULL_BUILD "Build and test LLVM libc as if it is the full libc" OFF)
include(CMakeParseArguments)
include(LLVMLibCRules)
include(LLVMLibCCheckCpuFeatures)
@ -81,18 +83,22 @@ foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS)
list(APPEND TARGET_ENTRYPOINT_NAME_LIST ${entrypoint_name})
endforeach()
# We need to set up hdrgen first since other targets depend on it.
add_subdirectory(utils/LibcTableGenUtil)
add_subdirectory(utils/HdrGen)
if(LLVM_LIBC_FULL_BUILD)
# We need to set up hdrgen first since other targets depend on it.
add_subdirectory(utils/LibcTableGenUtil)
add_subdirectory(utils/HdrGen)
endif()
add_subdirectory(include)
add_subdirectory(config)
add_subdirectory(src)
add_subdirectory(utils)
# The loader can potentially depend on the library components so add it
# after the library implementation directories.
add_subdirectory(loader)
if(LLVM_LIBC_FULL_BUILD)
# The loader can potentially depend on the library components so add it
# after the library implementation directories.
add_subdirectory(loader)
endif()
# The lib and test directories are added at the very end as tests
# and libraries potentially draw from the components present in all

View File

@ -58,6 +58,12 @@ function(add_gen_header target_name)
"PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
${ARGN}
)
get_fq_target_name(${target_name} fq_target_name)
if(NOT LLVM_LIBC_FULL_BUILD)
# We don't want to use generated headers if we are doing a non-full-build.
add_custom_target(${fq_target_name})
return()
endif()
if(NOT ADD_GEN_HDR_DEF_FILE)
message(FATAL_ERROR "`add_gen_hdr` rule requires DEF_FILE to be specified.")
endif()
@ -100,7 +106,6 @@ function(add_gen_header target_name)
${LIBC_TABLEGEN_EXE} ${LIBC_TABLEGEN_TARGET}
)
get_fq_target_name(${target_name} fq_target_name)
if(ADD_GEN_HDR_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
endif()

View File

@ -1,7 +1,4 @@
set(TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
libc.src.assert.__assert_fail
# ctype.h entrypoints
libc.src.ctype.isalnum
libc.src.ctype.isalpha
@ -23,23 +20,6 @@ set(TARGET_LIBC_ENTRYPOINTS
# errno.h entrypoints
libc.src.errno.__errno_location
# signal.h entrypoints
libc.src.signal.raise
libc.src.signal.sigaction
libc.src.signal.sigdelset
libc.src.signal.sigaddset
libc.src.signal.sigemptyset
libc.src.signal.sigprocmask
libc.src.signal.sigfillset
libc.src.signal.signal
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.abs
libc.src.stdlib.labs
libc.src.stdlib.llabs
# string.h entrypoints
libc.src.string.bzero
libc.src.string.memchr
@ -62,24 +42,6 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strstr
libc.src.string.strtok
libc.src.string.strtok_r
# sys/mman.h entrypoints
libc.src.sys.mman.mmap
libc.src.sys.mman.munmap
# threads.h entrypoints
libc.src.threads.call_once
libc.src.threads.mtx_init
libc.src.threads.mtx_lock
libc.src.threads.mtx_unlock
libc.src.threads.thrd_create
libc.src.threads.thrd_join
# time.h entrypoints
libc.src.time.mktime
# unistd.h entrypoints
libc.src.unistd.write
)
set(TARGET_LIBM_ENTRYPOINTS
@ -179,6 +141,48 @@ set(TARGET_LIBM_ENTRYPOINTS
libc.src.math.truncl
)
if(LLVM_LIBC_FULL_BUILD)
list(APPEND TARGET_LIBC_ENTRYPOINTS
# assert.h entrypoints
libc.src.assert.__assert_fail
# stdlib.h entrypoints
libc.src.stdlib._Exit
libc.src.stdlib.abort
libc.src.stdlib.abs
libc.src.stdlib.labs
libc.src.stdlib.llabs
# signal.h entrypoints
libc.src.signal.raise
libc.src.signal.sigaction
libc.src.signal.sigdelset
libc.src.signal.sigaddset
libc.src.signal.sigemptyset
libc.src.signal.sigprocmask
libc.src.signal.sigfillset
libc.src.signal.signal
# sys/mman.h entrypoints
libc.src.sys.mman.mmap
libc.src.sys.mman.munmap
# threads.h entrypoints
libc.src.threads.call_once
libc.src.threads.mtx_init
libc.src.threads.mtx_lock
libc.src.threads.mtx_unlock
libc.src.threads.thrd_create
libc.src.threads.thrd_join
# time.h entrypoints
libc.src.time.mktime
# unistd.h entrypoints
libc.src.unistd.write
)
endif()
set(TARGET_LLVMLIBC_ENTRYPOINTS
${TARGET_LIBC_ENTRYPOINTS}
${TARGET_LIBM_ENTRYPOINTS}

View File

@ -1,16 +1,21 @@
add_subdirectory(assert)
add_subdirectory(__support)
add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(math)
add_subdirectory(string)
if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
add_subdirectory(assert)
add_subdirectory(signal)
add_subdirectory(stdio)
add_subdirectory(stdlib)
add_subdirectory(string)
# TODO: Add this target conditional to the target OS.
add_subdirectory(sys)
add_subdirectory(threads)
add_subdirectory(time)
add_subdirectory(unistd)
add_subdirectory(__support)

View File

@ -7,7 +7,12 @@ add_header_library(
add_custom_target(check-libc)
add_custom_target(exhaustive-check-libc)
add_subdirectory(config)
add_subdirectory(loader)
add_subdirectory(src)
add_subdirectory(utils)
if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
add_subdirectory(config)
add_subdirectory(loader)

View File

@ -1,8 +1,13 @@
add_subdirectory(assert)
add_subdirectory(ctype)
add_subdirectory(errno)
add_subdirectory(fenv)
add_subdirectory(math)
if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
add_subdirectory(assert)
add_subdirectory(signal)
add_subdirectory(stdio)
add_subdirectory(stdlib)

View File

@ -1,3 +1,8 @@
add_subdirectory(FPUtil)
add_subdirectory(CPP)
if(NOT LLVM_LIBC_FULL_BUILD)
return()
endif()
add_subdirectory(tools)

View File

@ -2,5 +2,8 @@ add_subdirectory(CPP)
add_subdirectory(FPUtil)
add_subdirectory(MPFRWrapper)
add_subdirectory(testutils)
add_subdirectory(tools)
add_subdirectory(UnitTest)
if(LLVM_LIBC_FULL_BUILD)
add_subdirectory(tools)
endif()