Skip to content

Commit 2543177

Browse files
committed
auto merge of #12651 : lucab/rust/llvmdep-ldflags, r=alexcrichton
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_* symbols), while using a system-wide LLVM. Signed-off-by: Luca Bruno <[email protected]>
2 parents 910012a + 357cadf commit 2543177

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

.travis.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,11 @@ before_script:
2626
# Note that this is meant to run in a "fairly small" amount of time, so this
2727
# isn't exhaustive at all.
2828
#
29-
# The "-lffi and -lncurses" are required for LLVM. The LLVM that rust builds
30-
# manually disables bringing in these two libraries, but the stock LLVM was
31-
# apparently built with these options. We provide these options when building so
32-
# the `rustc` binary can successfully link.
33-
#
3429
# As a result of https://github.com/travis-ci/travis-ci/issues/1066, we run
3530
# everything in one large command instead of multiple commands.
3631
script: |
3732
make tidy &&
38-
RUSTFLAGS="-C link-args='-lffi -lncurses'" make -j4 rustc-stage1 &&
33+
make -j4 rustc-stage1 &&
3934
make check-stage1-std check-stage1-rpass check-stage1-cfail check-stage1-rfail
4035
4136
env:

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)