[libc-commits] [libc] 5454991 - [libc] Cleanup of hermetic test flag handling (#82384)

via libc-commits libc-commits at lists.llvm.org
Tue Feb 20 10:23:52 PST 2024


Author: Joseph Huber
Date: 2024-02-20T12:23:48-06:00
New Revision: 5454991c29945d791b82a9e25b1f605f54c75710

URL: https://github.com/llvm/llvm-project/commit/5454991c29945d791b82a9e25b1f605f54c75710
DIFF: https://github.com/llvm/llvm-project/commit/5454991c29945d791b82a9e25b1f605f54c75710.diff

LOG: [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.

Added: 
    

Modified: 
    libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
    libc/cmake/modules/LLVMLibCTestRules.cmake
    libc/test/UnitTest/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
index f1f919f8c77eee..140e4d51a9c2e7 100644
--- a/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
+++ b/libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
@@ -135,21 +135,9 @@ function(_get_common_test_compile_options output_var flags)
     #   list(APPEND compile_options "-Wglobal-constructors")
     # endif()
   endif()
-  if (LIBC_TARGET_ARCHITECTURE_IS_GPU)
-    # TODO: Set these flags
-    # list(APPEND compile_options "-nogpulib")
-    # list(APPEND compile_options "-fvisibility=hidden")
-    # list(APPEND compile_options "-fconvergent-functions")
-
-    # # Manually disable all standard include paths and include the resource
-    # # directory to prevent system headers from being included.
-    # list(APPEND compile_options "-isystem${COMPILER_RESOURCE_DIR}/include")
-    # list(APPEND compile_options "-nostdinc")
-  endif()
   set(${output_var} ${compile_options} PARENT_SCOPE)
 endfunction()
 
-
 # Obtains NVPTX specific arguments for compilation.
 # The PTX feature is primarily based on the CUDA toolchain version. We want to
 # 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)
   set(${output_var} ${nvptx_options} PARENT_SCOPE)
 endfunction()
 
-#TODO: Fold this into a function to get test framework compile options (which
-# need to be separate from the main test compile options because otherwise they
-# error)
-set(LIBC_HERMETIC_TEST_COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_DEFAULT}
-    -fpie -ffreestanding -fno-exceptions -fno-rtti)
-# The GPU build requires overriding the default CMake triple and architecture.
-if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
-  list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
-       -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
-       --target=${LIBC_GPU_TARGET_TRIPLE}
-       -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
-elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
-  get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
-  list(APPEND LIBC_HERMETIC_TEST_COMPILE_OPTIONS
-       -nogpulib ${nvptx_options} -fno-use-cxa-atexit --target=${LIBC_GPU_TARGET_TRIPLE})
-endif()
+function(_get_hermetic_test_compile_options output_var flags)
+  _get_compile_options_from_flags(compile_flags ${flags})
+  list(APPEND compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${compile_flags}
+       ${flags} -fpie -ffreestanding -fno-exceptions -fno-rtti)
+
+  # The GPU build requires overriding the default CMake triple and architecture.
+  if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
+    list(APPEND compile_options
+         -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE} -flto
+         --target=${LIBC_GPU_TARGET_TRIPLE}
+         -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
+  elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
+    get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
+    list(APPEND compile_options
+         -nogpulib ${nvptx_options} -fno-use-cxa-atexit --target=${LIBC_GPU_TARGET_TRIPLE})
+  endif()
+  set(${output_var} ${compile_options} PARENT_SCOPE)
+endfunction()

diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index f5952ab789ed76..6ca9516ff7a0e4 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -457,20 +457,9 @@ function(add_integration_test test_name)
       PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
   target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
   target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
-  target_compile_options(${fq_build_target_name}
-      PRIVATE -fpie -ffreestanding -fno-exceptions -fno-rtti ${INTEGRATION_TEST_COMPILE_OPTIONS})
-  # The GPU build requires overriding the default CMake triple and architecture.
-  if(LIBC_GPU_TARGET_ARCHITECTURE_IS_AMDGPU)
-    target_compile_options(${fq_build_target_name} PRIVATE
-                           -nogpulib -mcpu=${LIBC_GPU_TARGET_ARCHITECTURE}
-                           -flto --target=${LIBC_GPU_TARGET_TRIPLE}
-                           -mcode-object-version=${LIBC_GPU_CODE_OBJECT_VERSION})
-  elseif(LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
-    get_nvptx_compile_options(nvptx_options ${LIBC_GPU_TARGET_ARCHITECTURE})
-    target_compile_options(${fq_build_target_name} PRIVATE
-                           -nogpulib ${nvptx_options} -fno-use-cxa-atexit
-                           --target=${LIBC_GPU_TARGET_TRIPLE})
-  endif()
+
+  _get_hermetic_test_compile_options(compile_options "${INTEGRATION_TEST_COMPILE_OPTIONS}")
+  target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
 
   if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
     target_link_options(${fq_build_target_name} PRIVATE -nostdlib -static)
@@ -628,8 +617,8 @@ function(add_libc_hermetic_test test_name)
   )
   target_include_directories(${fq_build_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
   target_include_directories(${fq_build_target_name} PRIVATE ${LIBC_SOURCE_DIR})
-  target_compile_options(${fq_build_target_name}
-      PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} ${HERMETIC_TEST_COMPILE_OPTIONS})
+  _get_hermetic_test_compile_options(compile_options "${HERMETIC_TEST_COMPILE_OPTIONS}")
+  target_compile_options(${fq_build_target_name} PRIVATE ${compile_options})
 
   set(link_libraries "")
   foreach(lib IN LISTS HERMETIC_TEST_LINK_LIBRARIES)

diff  --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 0848f5696194a3..4a615d4bd5e1ce 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -36,9 +36,9 @@ function(add_unittest_framework_library name)
     endif()
     target_compile_options(${lib} PUBLIC ${compile_options})
   endforeach()
+  _get_hermetic_test_compile_options(compile_options -nostdinc++)
   target_include_directories(${name}.hermetic PRIVATE ${LIBC_BUILD_DIR}/include)
-  target_compile_options(${name}.hermetic
-      PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdinc++)
+  target_compile_options(${name}.hermetic PRIVATE ${compile_options})
 
   if(TEST_LIB_DEPENDS)
     foreach(dep IN LISTS ${TEST_LIB_DEPENDS})


        


More information about the libc-commits mailing list