[llvm-branch-commits] [compiler-rt] Allow running tests without installing first (PR #83088)

Fangrui Song via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 27 12:46:27 PST 2024


================
@@ -168,10 +168,43 @@ def push_dynamic_library_lookup_path(config, new_path):
             r"/i386(?=-[^/]+$)", "/x86_64", config.compiler_rt_libdir
         )
 
+
+# Check if the test compiler resource dir matches the local build directory
+# (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are
+# using an installed clang to test compiler-rt standalone. In the latter case
+# we may need to override the resource dir to match the path of the just-built
+# compiler-rt libraries.
+test_cc_resource_dir, _ = get_path_from_clang(
+    shlex.split(config.target_cflags) + ["-print-resource-dir"], allow_failure=True
+)
+# Normalize the path for comparison
+if test_cc_resource_dir is not None:
+    test_cc_resource_dir = os.path.realpath(test_cc_resource_dir)
+if lit_config.debug:
+    lit_config.note(f"Resource dir for {config.clang} is {test_cc_resource_dir}")
+local_build_resource_dir = os.path.realpath(config.compiler_rt_output_dir)
+if test_cc_resource_dir != local_build_resource_dir:
+    if config.test_standalone_build_libs and config.compiler_id == "Clang":
+        if lit_config.debug:
+            lit_config.note(f'Overriding test compiler resource dir to use '
+                            f'libraries in "{config.compiler_rt_libdir}"')
+        # Ensure that we use the just-built static libraries when linking by
+        # overriding the Clang resource directory. Additionally, we want to use
+        # the builtin headers shipped with clang (e.g. stdint.h), so we
+        # explicitly add this as an include path (since the headers are not
+        # going to be in the current compiler-rt build directory).
+        # We also tell the linker to add an RPATH entry for the local library
+        # directory so that the just-built shared libraries are used.
+        config.target_cflags += f" -nobuiltininc"
----------------
MaskRay wrote:

Can `target_cflags` be made to a `list` instead of space-separate `str`?

https://github.com/llvm/llvm-project/pull/83088


More information about the llvm-branch-commits mailing list