Skip to content

Commit 1e2f572

Browse files
committed
librustc: add LLVM LDFLAGS to deps
This commit let librustc automatically pickup LDFLAGS dependencies inherited from LLVM, which may otherwise result in undefined references to external symbols under certain linking environment. A symptom of this issue is eg. a failure when trying to link against librustc (due to unresolved ffi_*i symbols), while using a system-wide LLVM. Signed-off-by: Luca Bruno <lucab@debian.org>
1 parent baf7908 commit 1e2f572

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/etc/mklldeps.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
5757

58+
# LLVM libs
5859
args = [llconfig, '--libs']
5960
args.extend(components)
6061
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -67,6 +68,21 @@
6768
for lib in out.strip().split(' '):
6869
lib = lib[2:] # chop of the leading '-l'
6970
f.write("#[link(name = \"" + lib + "\", kind = \"static\")]\n")
71+
72+
# LLVM ldflags
73+
args = [llconfig, '--ldflags']
74+
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
75+
out, err = proc.communicate()
76+
77+
if err:
78+
print("failed to run llconfig: args = `{}`".format(args))
79+
sys.exit(1)
80+
81+
for lib in out.strip().split(' '):
82+
if lib[:2] == "-l":
83+
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
84+
85+
#extra
7086
f.write("#[link(name = \"stdc++\")]\n")
7187
if os == 'win32':
7288
f.write("#[link(name = \"imagehlp\")]\n")

0 commit comments

Comments
 (0)