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.
This commit is contained in:
Alex Crichton 2014-04-14 12:30:52 -07:00
parent 682c401045
commit 36d5635273
1 changed files with 25 additions and 26 deletions

View File

@ -31,11 +31,20 @@ f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// take a look at src/etc/mklldeps.py if you're interested
""")
def run(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if err:
print("failed to run llconfig: args = `{}`".format(args))
print(err)
sys.exit(1)
return out
for llconfig in sys.argv[3:]:
f.write("\n")
proc = subprocess.Popen([llconfig, '--host-target'], stdout = subprocess.PIPE)
out, err = proc.communicate()
out = run([llconfig, '--host-target'])
arch, os = out.split('-', 1)
arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
if 'darwin' in os:
@ -55,16 +64,15 @@ for llconfig in sys.argv[3:]:
f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
version = run([llconfig, '--version']).strip()
# LLVM libs
args = [llconfig, '--libs', '--system-libs']
if version < '3.5':
args = [llconfig, '--libs']
else:
args = [llconfig, '--libs', '--system-libs']
args.extend(components)
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if err:
print("failed to run llconfig: args = `{}`".format(args))
sys.exit(1)
out = run(args)
for lib in out.strip().replace("\n", ' ').split(' '):
lib = lib.strip()[2:] # chop of the leading '-l'
f.write("#[link(name = \"" + lib + "\"")
@ -73,28 +81,19 @@ for llconfig in sys.argv[3:]:
f.write(", kind = \"static\"")
f.write(")]\n")
# llvm-config before 3.5 didn't have a system-libs flag
if version < '3.5':
if os == 'win32':
f.write("#[link(name = \"imagehlp\")]")
# LLVM ldflags
args = [llconfig, '--ldflags']
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if err:
print("failed to run llconfig: args = `{}`".format(args))
sys.exit(1)
out = run([llconfig, '--ldflags'])
for lib in out.strip().split(' '):
if lib[:2] == "-l":
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
# C++ runtime library
args = [llconfig, '--cxxflags']
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = proc.communicate()
if err:
print("failed to run llconfig: args = `{}`".format(args))
sys.exit(1)
out = run([llconfig, '--cxxflags'])
if 'stdlib=libc++' in out:
f.write("#[link(name = \"c++\")]\n")
else: