Skip to content

Commit 5454991

Browse files
authored
[libc] Cleanup of hermetic test flag handling (#82384)
Summary: This cleans up the handling of hermetic test flags. Primarily done to simplify the GPU rework patch.
1 parent d39d5cc commit 5454991

File tree

3 files changed

+25
-46
lines changed

3 files changed

+25
-46
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,21 +135,9 @@ function(_get_common_test_compile_options output_var flags)
135135
# list(APPEND compile_options "-Wglobal-constructors")
136136
# endif()
137137
endif()
138-
if (LIBC_TARGET_ARCHITECTURE_IS_GPU)
139-
# TODO: Set these flags
140-
# list(APPEND compile_options "-nogpulib")
141-
# list(APPEND compile_options "-fvisibility=hidden")
142-
# list(APPEND compile_options "-fconvergent-functions")
143-
144-
# # Manually disable all standard include paths and include the resource
145-
# # directory to prevent system headers from being included.
146-
# list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
147-
# list(APPEND compile_options "-nostdinc")
148-
endif()
149138
set(${output_var} ${compile_options} PARENT_SCOPE)
150139
endfunction()
151140

152-
153141
# Obtains NVPTX specific arguments for compilation.
154142
# The PTX feature is primarily based on the CUDA toolchain version. We want to
155143
# be able to target NVPTX without an existing CUDA installation, so we need to
@@ -202,19 +190,21 @@ function(get_nvptx_compile_options output_var gpu_arch)
202190
set(${output_var} ${nvptx_options} PARENT_SCOPE)
203191
endfunction()
204192

205-
#TODO: Fold this into a function to get test framework compile options (which
206-
# need to be separate from the main test compile options because otherwise they
207-
# error)
208-
set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
209-
-fpie -ffreestanding -fno-exceptions -fno-rtti)
210-
# The GPU build requires overriding the default CMake triple and architecture.
211-
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
212-
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
213-
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
214-
--target=${LIBC_GPU_TARGET_TRIPLE}
215-
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
216-
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
217-
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
218-
list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
219-
-nogpulib ${nvptx_options} -fno-use-cxa-atexit --target=${LIBC_GPU_TARGET_TRIPLE})
220-
endif()
193+
function(_get_hermetic_test_compile_options output_var flags)
194+
_get_compile_options_from_flags(compile_flags ${flags})
195+
list(APPEND compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags}
196+
${flags} -fpie -ffreestanding -fno-exceptions -fno-rtti)
197+
198+
# The GPU build requires overriding the default CMake triple and architecture.
199+
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
200+
list(APPEND compile_options
201+
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
202+
--target=${LIBC_GPU_TARGET_TRIPLE}
203+
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
204+
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
205+
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
206+
list(APPEND compile_options
207+
-nogpulib ${nvptx_options} -fno-use-cxa-atexit --target=${LIBC_GPU_TARGET_TRIPLE})
208+
endif()
209+
set(${output_var} ${compile_options} PARENT_SCOPE)
210+
endfunction()

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,20 +457,9 @@ function(add_integration_test test_name)
457457
PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
458458
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
459459
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
460-
target_compile_options(${fq_build_target_name}
461-
PRIVATE -fpie -ffreestanding -fno-exceptions -fno-rtti ${INTEGRATION_TEST_COMPILE_OPTIONS})
462-
# The GPU build requires overriding the default CMake triple and architecture.
463-
if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
464-
target_compile_options(${fq_build_target_name} PRIVATE
465-
-nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
466-
-flto --target=${LIBC_GPU_TARGET_TRIPLE}
467-
-mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
468-
elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
469-
get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
470-
target_compile_options(${fq_build_target_name} PRIVATE
471-
-nogpulib ${nvptx_options} -fno-use-cxa-atexit
472-
--target=${LIBC_GPU_TARGET_TRIPLE})
473-
endif()
460+
461+
_get_hermetic_test_compile_options(compile_options "${INTEGRATION_TEST_COMPILE_OPTIONS}")
462+
target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
474463

475464
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
476465
target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
@@ -628,8 +617,8 @@ function(add_libc_hermetic_test test_name)
628617
)
629618
target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
630619
target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
631-
target_compile_options(${fq_build_target_name}
632-
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} ${HERMETIC_TEST_COMPILE_OPTIONS})
620+
_get_hermetic_test_compile_options(compile_options "${HERMETIC_TEST_COMPILE_OPTIONS}")
621+
target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
633622

634623
set(link_libraries "")
635624
foreach(lib IN LISTS HERMETIC_TEST_LINK_LIBRARIES)

libc/test/UnitTest/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ function(add_unittest_framework_library name)
3636
endif()
3737
target_compile_options(${lib} PUBLIC ${compile_options})
3838
endforeach()
39+
_get_hermetic_test_compile_options(compile_options -nostdinc++)
3940
target_include_directories(${name}.hermetic PRIVATE ${LIBC_BUILD_DIR}/include)
40-
target_compile_options(${name}.hermetic
41-
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdinc++)
41+
target_compile_options(${name}.hermetic PRIVATE ${compile_options})
4242

4343
if(TEST_LIB_DEPENDS)
4444
foreach(dep IN LISTS ${TEST_LIB_DEPENDS})

0 commit comments

Comments
 (0)