about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/llvm/17/llvm/llvm-lit-cfg-add-libs-to-dylib-path.patch
blob: d4ccb2ae982278f5aadab4a85aceb0fd30f5cea3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
diff --git a/test/Unit/lit.cfg.py b/test/Unit/lit.cfg.py
index 81e8dc04acea..479ff95681e2 100644
--- a/test/Unit/lit.cfg.py
+++ b/test/Unit/lit.cfg.py
@@ -3,6 +3,7 @@
 # Configuration file for the 'lit' test runner.
 
 import os
+import platform
 import subprocess
 
 import lit.formats
@@ -55,3 +56,26 @@ if sys.platform in ["win32", "cygwin"] and os.path.isdir(config.shlibdir):
 # Win32 may use %SYSTEMDRIVE% during file system shell operations, so propogate.
 if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ:
     config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"]
+
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+    if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+        yield "LD_LIBRARY_PATH"
+    elif platform.system() == "Darwin":
+        yield "DYLD_LIBRARY_PATH"
+    elif platform.system() == "Windows":
+        yield "PATH"
+    elif platform.system() == "AIX":
+        yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+    shlibpath = os.path.pathsep.join(
+        (config.shlibdir,
+         config.environment.get(shlibpath_var, '')))
+    config.environment[shlibpath_var] = shlibpath
+    break
+else:
+    lit_config.warning("unable to inject shared library path on '{}'"
+                       .format(platform.system()))
diff --git a/test/lit.cfg.py b/test/lit.cfg.py
index 75a38b4c5dad..856fc75c9d74 100644
--- a/test/lit.cfg.py
+++ b/test/lit.cfg.py
@@ -42,6 +42,26 @@ llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
 llvm_config.with_system_environment(
     ["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])
 
+# Add the LLVM dynamic libs to the platform-specific loader search path env var:
+#
+# TODO: this is copied from `clang`'s `lit.cfg.py`; should unify..
+def find_shlibpath_var():
+    if platform.system() in ["Linux", "FreeBSD", "NetBSD", "OpenBSD", "SunOS"]:
+        yield "LD_LIBRARY_PATH"
+    elif platform.system() == "Darwin":
+        yield "DYLD_LIBRARY_PATH"
+    elif platform.system() == "Windows":
+        yield "PATH"
+    elif platform.system() == "AIX":
+        yield "LIBPATH"
+
+for shlibpath_var in find_shlibpath_var():
+    shlibpath = config.llvm_shlib_dir
+    llvm_config.with_environment(shlibpath_var, shlibpath, append_path = True)
+    break
+else:
+    lit_config.warning("unable to inject shared library path on '{}'"
+                       .format(platform.system()))
 
 # Set up OCAMLPATH to include newly built OCaml libraries.
 top_ocaml_lib = os.path.join(config.llvm_lib_dir, "ocaml")
@@ -318,7 +338,7 @@ def have_cxx_shared_library():
 
     try:
         readobj_cmd = subprocess.Popen(
-            [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE
+            [readobj_exe, "--needed-libs", readobj_exe], stdout=subprocess.PIPE, env=config.environment
         )
     except OSError:
         print("could not exec llvm-readobj")