From 32a81d1e161a8b4a498c88ddb79955775d18fbfd Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 14 Apr 2014 09:49:34 -0700 Subject: [PATCH] configure: Enable libc++ with LLVM with clang When clang is enabled, also pass through --enable-libcpp to LLVM's configure command line to help it pick up the most recent c++ runtime library. This also changes the mklldeps.py script to pick up on whether LLVM was linked against stdc++ or c++ based on the --cxxflags that llvm-config prints. In an ongoing attempt to update LLVM, the bots need to update their C compilers to something that supports c++11 (LLVM recently switched). The OSX bots are running Lion (10.7), which only supports up to gcc 4.2 and clang 3.2. Apparently the libstdc++ is too old (even on the most updated command line tools) for LLVM, but using libc++ instead appears to work just fine. --- configure | 2 ++ src/etc/mklldeps.py | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 8099aada558..5b6c26daaa3 100755 --- a/configure +++ b/configure @@ -938,6 +938,7 @@ do LLVM_CXX_64="ccache clang++ -Qunused-arguments" LLVM_CC_64="ccache clang -Qunused-arguments" + LLVM_OPTS="$LLVM_OPTS --enable-libcpp" ;; ("clang") LLVM_CXX_32="clang++ -m32 -Qunused-arguments" @@ -945,6 +946,7 @@ do LLVM_CXX_64="clang++ -Qunused-arguments" LLVM_CC_64="clang -Qunused-arguments" + LLVM_OPTS="$LLVM_OPTS --enable-libcpp" ;; ("ccache gcc") LLVM_CXX_32="ccache g++ -m32" diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 189d0269cd8..8ad9ea2813b 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -56,7 +56,7 @@ for llconfig in sys.argv[3:]: f.write("#[cfg(" + ', '.join(cfg) + ")]\n") # LLVM libs - args = [llconfig, '--libs'] + args = [llconfig, '--libs', '--system-libs'] args.extend(components) proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() @@ -65,9 +65,13 @@ for llconfig in sys.argv[3:]: print("failed to run llconfig: args = `{}`".format(args)) sys.exit(1) - for lib in out.strip().split(' '): - lib = lib[2:] # chop of the leading '-l' - f.write("#[link(name = \"" + lib + "\", kind = \"static\")]\n") + for lib in out.strip().replace("\n", ' ').split(' '): + lib = lib.strip()[2:] # chop of the leading '-l' + f.write("#[link(name = \"" + lib + "\"") + # LLVM libraries are all static libraries + if 'LLVM' in lib: + f.write(", kind = \"static\"") + f.write(")]\n") # LLVM ldflags args = [llconfig, '--ldflags'] @@ -82,8 +86,19 @@ for llconfig in sys.argv[3:]: if lib[:2] == "-l": f.write("#[link(name = \"" + lib[2:] + "\")]\n") - #extra - f.write("#[link(name = \"stdc++\")]\n") - if os == 'win32': - f.write("#[link(name = \"imagehlp\")]\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) + + if 'stdlib=libc++' in out: + f.write("#[link(name = \"c++\")]\n") + else: + f.write("#[link(name = \"stdc++\")]\n") + + # Attach everything to an extern block f.write("extern {}\n")