Skip to content

Commit 36d5635

Browse files
committed
etc: The --system-libs flag is LLVM 3.5+
Older version of LLVM did not have this flag, so we need to fall back to our previous library detection when using older versions of LLVM.
1 parent 682c401 commit 36d5635

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

src/etc/mklldeps.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,20 @@
3131
// take a look at src/etc/mklldeps.py if you're interested
3232
""")
3333

34+
def run(args):
35+
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
36+
out, err = proc.communicate()
37+
38+
if err:
39+
print("failed to run llconfig: args = `{}`".format(args))
40+
print(err)
41+
sys.exit(1)
42+
return out
43+
3444
for llconfig in sys.argv[3:]:
3545
f.write("\n")
3646

37-
proc = subprocess.Popen([llconfig, '--host-target'], stdout = subprocess.PIPE)
38-
out, err = proc.communicate()
47+
out = run([llconfig, '--host-target'])
3948
arch, os = out.split('-', 1)
4049
arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
4150
if 'darwin' in os:
@@ -55,16 +64,15 @@
5564

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

67+
version = run([llconfig, '--version']).strip()
68+
5869
# LLVM libs
59-
args = [llconfig, '--libs', '--system-libs']
70+
if version < '3.5':
71+
args = [llconfig, '--libs']
72+
else:
73+
args = [llconfig, '--libs', '--system-libs']
6074
args.extend(components)
61-
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62-
out, err = proc.communicate()
63-
64-
if err:
65-
print("failed to run llconfig: args = `{}`".format(args))
66-
sys.exit(1)
67-
75+
out = run(args)
6876
for lib in out.strip().replace("\n", ' ').split(' '):
6977
lib = lib.strip()[2:] # chop of the leading '-l'
7078
f.write("#[link(name = \"" + lib + "\"")
@@ -73,28 +81,19 @@
7381
f.write(", kind = \"static\"")
7482
f.write(")]\n")
7583

76-
# LLVM ldflags
77-
args = [llconfig, '--ldflags']
78-
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
79-
out, err = proc.communicate()
80-
81-
if err:
82-
print("failed to run llconfig: args = `{}`".format(args))
83-
sys.exit(1)
84+
# llvm-config before 3.5 didn't have a system-libs flag
85+
if version < '3.5':
86+
if os == 'win32':
87+
f.write("#[link(name = \"imagehlp\")]")
8488

89+
# LLVM ldflags
90+
out = run([llconfig, '--ldflags'])
8591
for lib in out.strip().split(' '):
8692
if lib[:2] == "-l":
8793
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
8894

8995
# C++ runtime library
90-
args = [llconfig, '--cxxflags']
91-
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
92-
out, err = proc.communicate()
93-
94-
if err:
95-
print("failed to run llconfig: args = `{}`".format(args))
96-
sys.exit(1)
97-
96+
out = run([llconfig, '--cxxflags'])
9897
if 'stdlib=libc++' in out:
9998
f.write("#[link(name = \"c++\")]\n")
10099
else:

0 commit comments

Comments
 (0)