[libc-commits] [libc] b51e6bf - [libc] Allows cross compilation of membenchmarks

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Thu May 11 01:58:02 PDT 2023


Author: Guillaume Chatelet
Date: 2023-05-11T08:57:50Z
New Revision: b51e6bfcb6745d88a0d41be28c6204019c79bea2

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

LOG: [libc] Allows cross compilation of membenchmarks

This patch makes sure:
 - we pass the correct compiler options when building Google benchmarks,
 - we only import the C++ version of the memory functions.

The change in libc/cmake/modules/LLVMLibCTestRules.cmake is here to make sure CMake can generate the right command line in the presence of the CMAKE_CROSSCOMPILING_EMULATOR option.

Relevant documentation:
https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html
https://cmake.org/cmake/help/latest/command/add_custom_command.html#command:add_custom_command
"
If COMMAND specifies an executable target name (created by the `add_executable()` command), it will automatically be replaced by the location of the executable created at build time if either of the following is true:
 - The target is not being cross-compiled (i.e. the CMAKE_CROSSCOMPILING variable is not set to true).
 - New in version 3.6: The target is being cross-compiled and an emulator is provided (i.e. its CROSSCOMPILING_EMULATOR target property is set). In this case, the contents of CROSSCOMPILING_EMULATOR will be prepended to the command before the location of the target executable.
"

Reviewed By: gchatelet

Differential Revision: https://reviews.llvm.org/D150200

Added: 
    

Modified: 
    libc/benchmarks/CMakeLists.txt
    libc/cmake/modules/LLVMLibCTestRules.cmake

Removed: 
    


################################################################################
diff  --git a/libc/benchmarks/CMakeLists.txt b/libc/benchmarks/CMakeLists.txt
index f4e1ff6ec7fa1..c3c12fb892dda 100644
--- a/libc/benchmarks/CMakeLists.txt
+++ b/libc/benchmarks/CMakeLists.txt
@@ -59,10 +59,18 @@ ExternalProject_Add(google-benchmark-libc
           -DBENCHMARK_ENABLE_WERROR:BOOL=${LLVM_ENABLE_WERROR}
           -DBENCHMARK_FORCE_WERROR:BOOL=OFF
           -DBENCHMARK_USE_LIBCXX:BOOL=OFF
-          -DCMAKE_BUILD_TYPE:STRING=RELEASE
+          -DCMAKE_BUILD_TYPE:STRING=Release
+
+          -DCMAKE_SYSTEM_NAME:STRING=${CMAKE_SYSTEM_NAME}
+          -DCMAKE_SYSTEM_PROCESSOR:STRING=${CMAKE_SYSTEM_PROCESSOR}
           -DCMAKE_C_COMPILER:STRING=${CMAKE_C_COMPILER}
           -DCMAKE_CXX_COMPILER:STRING=${CMAKE_CXX_COMPILER}
-          -DCMAKE_CXX_FLAGS:STRING=${BENCHMARK_LIBC_COMPILE_FLAGS}
+          -DCMAKE_CXX_FLAGS:STRING=${CMAKE_CXX_FLAGS}
+          -DCMAKE_FIND_ROOT_PATH:STRING=${CMAKE_FIND_ROOT_PATH}
+
+          -DBUILD_SHARED_LIBS:BOOL=OFF
+          -DCMAKE_EXE_LINKER_FLAGS:STRING=-static
+
           -DCMAKE_CXX_STANDARD:STRING=14
           -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
         )
@@ -181,13 +189,14 @@ add_executable(libc.benchmarks.memory_functions.opt_host
 target_link_libraries(libc.benchmarks.memory_functions.opt_host
   PRIVATE
   libc-memory-benchmark
-  libc.src.string.memcmp_opt_host
-  libc.src.string.bcmp_opt_host
-  libc.src.string.memcpy_opt_host
-  libc.src.string.memset_opt_host
-  libc.src.string.bzero_opt_host
-  libc.src.string.memmove_opt_host
+  libc.src.string.memcmp_opt_host.__internal__
+  libc.src.string.bcmp_opt_host.__internal__
+  libc.src.string.memcpy_opt_host.__internal__
+  libc.src.string.memset_opt_host.__internal__
+  libc.src.string.bzero_opt_host.__internal__
+  libc.src.string.memmove_opt_host.__internal__
   benchmark_main
+  -static
 )
 llvm_update_compile_flags(libc.benchmarks.memory_functions.opt_host)
 

diff  --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake
index 4c1b143b66186..4458c006899e7 100644
--- a/libc/cmake/modules/LLVMLibCTestRules.cmake
+++ b/libc/cmake/modules/LLVMLibCTestRules.cmake
@@ -186,7 +186,7 @@ function(create_libc_unittest fq_target_name)
   if(NOT LIBC_UNITTEST_NO_RUN_POSTBUILD)
     add_custom_target(
       ${fq_target_name}
-      COMMAND $<TARGET_FILE:${fq_build_target_name}>
+      COMMAND ${fq_build_target_name}
       COMMENT "Running unit test ${fq_target_name}"
     )
   endif()


        


More information about the libc-commits mailing list