Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions libc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ add_compile_definitions(LIBC_NAMESPACE=${LIBC_NAMESPACE})
set(LIBC_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Architecture to tell clang to optimize for (e.g. -march=... or -mcpu=...)")
set(LIBC_TEST_COMPILE_OPTIONS_DEFAULT "" CACHE STRING "Common compile options for all the tests.")

set(LIBC_LINK_OPTIONS_DEFAULT "" CACHE STRING "Arguments used when linking.")
set(LIBC_TEST_LINK_OPTIONS_DEFAULT "" CACHE STRING "Common link options for all the tests.")

set(LIBC_TEST_CMD "" CACHE STRING
"The full test command in the form <command> binary=@BINARY@, if using another program to test (e.g. QEMU)")
set(LIBC_TEST_HERMETIC_ONLY "" OFF CACHE BOOL "Only enable hermetic tests.")

list(APPEND LIBC_COMPILE_OPTIONS_DEFAULT ${LIBC_COMMON_TUNE_OPTIONS})

# Check --print-resource-dir to find the compiler resource dir if this flag
Expand Down
58 changes: 50 additions & 8 deletions libc/cmake/modules/LLVMLibCTestRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@ function(create_libc_unittest fq_target_name)
_get_common_test_compile_options(compile_options "${LIBC_UNITTEST_C_TEST}"
"${LIBC_UNITTEST_FLAGS}")
# TODO: Ideally we would have a separate function for link options.
set(link_options ${compile_options})
set(link_options
${compile_options}
${LIBC_LINK_OPTIONS_DEFAULT}
${LIBC_TEST_LINK_OPTIONS_DEFAULT}
)
list(APPEND compile_options ${LIBC_UNITTEST_COMPILE_OPTIONS})

if(SHOW_INTERMEDIATE_OBJECTS)
Expand Down Expand Up @@ -580,12 +584,26 @@ function(add_integration_test test_name)
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
"--cuda-path=${LIBC_CUDA_ROOT}")
elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
set(link_options
-nolibc
-nostartfiles
-nostdlib++
-static
${LIBC_LINK_OPTIONS_DEFAULT}
${LIBC_TEST_LINK_OPTIONS_DEFAULT}
)
target_link_options(${fq_build_target_name} PRIVATE ${link_options})
else()
# Older version of gcc does not support `nostdlib++` flag. We use
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib)
list(APPEND link_libraries ${LIBGCC_S_LOCATION})
set(link_options
-nolibc
-nostartfiles
-static
${LIBC_LINK_OPTIONS_DEFAULT}
${LIBC_TEST_LINK_OPTIONS_DEFAULT}
)
target_link_options(${fq_build_target_name} PRIVATE ${link_options})
endif()
target_link_libraries(
${fq_build_target_name}
Expand Down Expand Up @@ -774,11 +792,26 @@ function(add_libc_hermetic test_name)
-march=${LIBC_GPU_TARGET_ARCHITECTURE} -nostdlib -static
"--cuda-path=${LIBC_CUDA_ROOT}")
elseif(LIBC_CC_SUPPORTS_NOSTDLIBPP)
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib++ -static)
set(link_options
-nolibc
-nostartfiles
-nostdlib++
-static
${LIBC_LINK_OPTIONS_DEFAULT}
${LIBC_TEST_LINK_OPTIONS_DEFAULT}
)
target_link_options(${fq_build_target_name} PRIVATE ${link_options})
else()
# Older version of gcc does not support `nostdlib++` flag. We use
# `nostdlib` and link against libgcc_s, which cannot be linked statically.
target_link_options(${fq_build_target_name} PRIVATE -nolibc -nostartfiles -nostdlib)
set(link_options
-nolibc
-nostartfiles
-static
${LIBC_LINK_OPTIONS_DEFAULT}
${LIBC_TEST_LINK_OPTIONS_DEFAULT}
)
target_link_options(${fq_build_target_name} PRIVATE ${link_options})
list(APPEND link_libraries ${LIBGCC_S_LOCATION})
endif()
target_link_libraries(
Expand Down Expand Up @@ -809,9 +842,16 @@ function(add_libc_hermetic test_name)
endif()

if(NOT HERMETIC_TEST_NO_RUN_POSTBUILD)
set(test_cmd ${HERMETIC_TEST_ENV}
if (LIBC_TEST_CMD)
# In the form of "<command> binary=@BINARY@", e.g. "qemu-system-arm -loader$<COMMA>file=@BINARY@"
string(REPLACE "@BINARY@" "$<TARGET_FILE:${fq_build_target_name}>" test_cmd_parsed ${LIBC_TEST_CMD})
string(REPLACE " " ";" test_cmd "${test_cmd_parsed}")
else()
set(test_cmd ${HERMETIC_TEST_ENV}
$<$<BOOL:${LIBC_TARGET_OS_IS_GPU}>:${gpu_loader_exe}> ${CMAKE_CROSSCOMPILING_EMULATOR} ${HERMETIC_TEST_LOADER_ARGS}
$<TARGET_FILE:${fq_build_target_name}> ${HERMETIC_TEST_ARGS})
endif()

add_custom_target(
${fq_target_name}
DEPENDS ${fq_target_name}.__cmd__
Expand Down Expand Up @@ -863,7 +903,9 @@ function(add_libc_test test_name)
# Tests like the file tests perform file operations on disk file. If we
# don't chain up the unit test and hermetic test, then those tests will
# step on each other's files.
add_dependencies(${fq_test_name}.__hermetic__ ${fq_test_name}.__unit__)
if(NOT LIBC_TEST_HERMETIC_ONLY)
add_dependencies(${fq_test_name}.__hermetic__ ${fq_test_name}.__unit__)
endif()
endif()
endif()
endfunction(add_libc_test)
Expand Down
Loading