From 36d5635273f7759b9aedce04bc8b111edb9c0742 Mon Sep 17 00:00:00 2001 From: Alex Crichton <alex@alexcrichton.com> Date: Mon, 14 Apr 2014 12:30:52 -0700 Subject: [PATCH] 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. --- src/etc/mklldeps.py | 51 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 8ad9ea2813b..364564168a5 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -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: