[libcxx-commits] [libcxx] [libcxx][libcxxabi][libunwind] Support target-specific flags for tests (PR #65517)

Alexander Richardson via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 6 11:53:15 PDT 2023


https://github.com/arichardson created https://github.com/llvm/llvm-project/pull/65517:

There is currently only limited support for passing target-specific flags (e.g. `-mabi=` or `-march=`) to the testsuites if you don't have a compiler (or wrapper script) that defaults to the expected flags.

While there are parameters to pass `--target=` and
`-isysroot` (https://reviews.llvm.org/D151056 tries to extend that to `--sysroot=` so the linker can find libraries), building for some targets e.g. RISC-V may require additional flags when building with Clang.

This change adds a new target_flags parameter to the testsuite that appends the given flags to `%{flags}` and can be set from CMake using `{LIBUNWIND,LIBCXXABI_LIBCXX}_TEST_TARGET_FLAGS.`

>From a78c0ee59c37865aac027a8359e86e26e63caa89 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Wed, 6 Sep 2023 11:41:56 -0700
Subject: [PATCH] [libcxx][libcxxabi][libunwind] Support target-specific flags
 for tests

There is currently only limited support for passing target-specific
flags (e.g. -mabi= or -march=) to the testsuites if you don't have a
compiler (or wrapper script) that defaults to the expected flags.

While there are parameters to pass --target= and
-isysroot (https://reviews.llvm.org/D151056 tries to extend that to
--sysroot= so the linker can find libraries), building for some targets
e.g. RISC-V may require additional flags when building with Clang.

This change adds a new target_flags parameter to the testsuite that
appends the given flags to %{flags} and can be set from CMake using
`{LIBUNWIND,LIBCXXABI_LIBCXX}_TEST_TARGET_FLAGS.`
---
 libcxx/test/CMakeLists.txt         |  4 ++++
 libcxx/utils/libcxx/test/params.py | 12 ++++++++++++
 libcxxabi/test/CMakeLists.txt      |  4 ++++
 libunwind/test/CMakeLists.txt      |  4 ++++
 4 files changed, 24 insertions(+)

diff --git a/libcxx/test/CMakeLists.txt b/libcxx/test/CMakeLists.txt
index c7036b94dcc596e..4e9a5a99c4b1952 100644
--- a/libcxx/test/CMakeLists.txt
+++ b/libcxx/test/CMakeLists.txt
@@ -32,6 +32,10 @@ else()
   serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
 endif()
 
+if (LIBCXX_TEST_TARGET_FLAGS)
+  serialize_lit_param(target_flags "\"${LIBCXX_TEST_TARGET_FLAGS}\"")
+endif()
+
 if (LLVM_USE_SANITIZER)
   serialize_lit_param(use_sanitizer "\"${LLVM_USE_SANITIZER}\"")
 endif()
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index 4eb799ce01bc2c4..eac670c607a8392 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -110,6 +110,18 @@ def getModuleFlag(cfg, enable_modules):
             ],
         ),
     ),
+    Parameter(
+        name="target_flags",
+        type=str,
+        default=None,
+        help="Additional compile flags (e.g. -mabi=/-march=) to use when "
+        "compiling the test suite. This must be compatible with the target "
+        "that the tests will be run on.",
+        actions=lambda target_flags: [] if not target_flags else [
+            AddFlag(target_flags),
+            AddSubstitution("%{target_flags}", target_flags),
+        ],
+    ),
     Parameter(
         name="std",
         choices=_allStandards,
diff --git a/libcxxabi/test/CMakeLists.txt b/libcxxabi/test/CMakeLists.txt
index 0d861cff980cd5d..198ecb43bb9a6e2 100644
--- a/libcxxabi/test/CMakeLists.txt
+++ b/libcxxabi/test/CMakeLists.txt
@@ -49,6 +49,10 @@ else()
   serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
 endif()
 
+if (LIBCXXABI_TEST_TARGET_FLAGS)
+  serialize_lit_param(target_flags "\"${LIBCXXABI_TEST_TARGET_FLAGS}\"")
+endif()
+
 foreach(param IN LISTS LIBCXXABI_TEST_PARAMS)
   string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
   string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")
diff --git a/libunwind/test/CMakeLists.txt b/libunwind/test/CMakeLists.txt
index e6bd52690442578..a2bccc91327f216 100644
--- a/libunwind/test/CMakeLists.txt
+++ b/libunwind/test/CMakeLists.txt
@@ -32,6 +32,10 @@ else()
   serialize_lit_param(target_triple "\"${LLVM_DEFAULT_TARGET_TRIPLE}\"")
 endif()
 
+if (LIBUNWIND_TEST_TARGET_FLAGS)
+  serialize_lit_param(target_flags "\"${LIBUNWIND_TEST_TARGET_FLAGS}\"")
+endif()
+
 foreach(param IN LISTS LIBUNWIND_TEST_PARAMS)
   string(REGEX REPLACE "(.+)=(.+)" "\\1" name "${param}")
   string(REGEX REPLACE "(.+)=(.+)" "\\2" value "${param}")



More information about the libcxx-commits mailing list