Skip to content

Commit acdee8b

Browse files
committed
llvm: Add an option to statically link libstdc++
The goal of the snapshot bots is to produce binaries which can run in as many locations as possible. Currently we build on Centos 6 for this reason, but with LLVM's update to C++11, this reduces the number of platforms that we could possibly run on. This adds a --enable-llvm-static-stdcpp option to the ./configure script for Rust which will enable building a librustc with a static dependence on libstdc++. This normally isn't necessary, but this option can be used on the snapshot builders in order to continue to make binaries which should be able to run in as many locations as possible.
1 parent 36d5635 commit acdee8b

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
388388
opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
389389
opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
390390
opt inject-std-version 1 "inject the current compiler version of libstd into programs"
391+
opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
391392
opt rpath 1 "build rpaths into rustc itself"
392393
opt nightly 0 "build nightly packages"
393394
opt verify-install 1 "verify installed binaries work"

mk/llvm.mk

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,25 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
4242
@$$(call E, make: done cleaning llvm)
4343
touch $$@
4444

45+
ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
46+
LLVM_STDCPP_LOCATION_$(1) = $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
47+
-print-file-name=libstdc++.a)
48+
else
49+
LLVM_STDCPP_LOCATION_$(1) =
50+
endif
51+
4552
endef
4653

4754
$(foreach host,$(CFG_HOST), \
48-
$(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
55+
$(eval $(call DEF_LLVM_RULES,$(host))))
4956

5057
$(foreach host,$(CFG_HOST), \
51-
$(eval $(call DEF_LLVM_RULES,$(host))))
58+
$(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
5259

5360
$(S)src/librustc/lib/llvmdeps.rs: \
5461
$(LLVM_CONFIGS) \
55-
$(S)src/etc/mklldeps.py
62+
$(S)src/etc/mklldeps.py \
63+
$(MKFILE_DEPS)
5664
$(Q)$(CFG_PYTHON) $(S)src/etc/mklldeps.py \
57-
"$@" "$(LLVM_COMPONENTS)" $(LLVM_CONFIGS)
65+
"$@" "$(LLVM_COMPONENTS)" "$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
66+
$(LLVM_CONFIGS)

mk/target.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8383
$$(WFLAGS_ST$(1)) \
8484
-L "$$(RT_OUTPUT_DIR_$(2))" \
8585
-L "$$(LLVM_LIBDIR_$(2))" \
86+
-L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
8687
--out-dir $$(@D) $$<
8788
@touch $$@
8889
$$(call LIST_ALL_OLD_GLOB_MATCHES,\

src/etc/mklldeps.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
import os
1212
import sys
1313
import subprocess
14+
import itertools
15+
from os import path
1416

1517
f = open(sys.argv[1], 'wb')
1618

1719
components = sys.argv[2].split(' ')
1820
components = [i for i in components if i] # ignore extra whitespaces
21+
enable_static = sys.argv[3]
1922

2023
f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2124
// file at the top-level directory of this distribution and at
@@ -41,7 +44,7 @@ def run(args):
4144
sys.exit(1)
4245
return out
4346

44-
for llconfig in sys.argv[3:]:
47+
for llconfig in sys.argv[4:]:
4548
f.write("\n")
4649

4750
out = run([llconfig, '--host-target'])
@@ -94,9 +97,13 @@ def run(args):
9497

9598
# C++ runtime library
9699
out = run([llconfig, '--cxxflags'])
97-
if 'stdlib=libc++' in out:
98-
f.write("#[link(name = \"c++\")]\n")
100+
if enable_static == '1':
101+
assert('stdlib=libc++' not in out)
102+
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
99103
else:
104+
if 'stdlib=libc++' in out:
105+
f.write("#[link(name = \"c++\")]\n")
106+
else:
100107
f.write("#[link(name = \"stdc++\")]\n")
101108

102109
# Attach everything to an extern block

0 commit comments

Comments
 (0)