]> git.lizzy.rs Git - rust.git/commitdiff
llvm: Add an option to statically link libstdc++
authorAlex Crichton <alex@alexcrichton.com>
Wed, 16 Apr 2014 17:45:04 +0000 (10:45 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 17 Apr 2014 18:39:51 +0000 (11:39 -0700)
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.

configure
mk/llvm.mk
mk/target.mk
src/etc/mklldeps.py

index 8d0116cb0ca7d3c58820313f5f196fd7c06ab7f8..983be4e8a0c0a72cc9fdcf9b2f8221bd412d8bce 100755 (executable)
--- a/configure
+++ b/configure
@@ -388,6 +388,7 @@ opt ccache 0 "invoke gcc/clang via ccache to reuse object files between builds"
 opt local-rust 0 "use an installed rustc rather than downloading a snapshot"
 opt pax-flags 0 "apply PaX flags to rustc binaries (required for GRSecurity/PaX-patched kernels)"
 opt inject-std-version 1 "inject the current compiler version of libstd into programs"
+opt llvm-static-stdcpp 0 "statically link to libstdc++ for LLVM"
 opt rpath 1 "build rpaths into rustc itself"
 opt nightly 0 "build nightly packages"
 opt verify-install 1 "verify installed binaries work"
index 13c4ae5e860f73f92cdeede7882c170a5885910b..789ce2dabc25edc056bee81f2e7fb926e04071a1 100644 (file)
@@ -42,16 +42,25 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger
        @$$(call E, make: done cleaning llvm)
        touch $$@
 
+ifeq ($$(CFG_ENABLE_LLVM_STATIC_STDCPP),1)
+LLVM_STDCPP_LOCATION_$(1) = $$(shell $$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
+                                       -print-file-name=libstdc++.a)
+else
+LLVM_STDCPP_LOCATION_$(1) =
+endif
+
 endef
 
 $(foreach host,$(CFG_HOST), \
   $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
$(eval $(call DEF_LLVM_RULES,$(host))))
 
 $(foreach host,$(CFG_HOST), \
- $(eval $(call DEF_LLVM_RULES,$(host))))
+ $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host))))
 
 $(S)src/librustc/lib/llvmdeps.rs: \
                    $(LLVM_CONFIGS) \
-                   $(S)src/etc/mklldeps.py
+                   $(S)src/etc/mklldeps.py \
+                   $(MKFILE_DEPS)
        $(Q)$(CFG_PYTHON) $(S)src/etc/mklldeps.py \
-           "$@" "$(LLVM_COMPONENTS)" $(LLVM_CONFIGS)
+               "$@" "$(LLVM_COMPONENTS)" "$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \
+               $(LLVM_CONFIGS)
index 11c57ac070f39ca8c64afd42b1d056cea225173a..448299965a853e999688b2a8bde24a455c509079 100644 (file)
@@ -83,6 +83,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4):                                    \
                $$(WFLAGS_ST$(1)) \
                -L "$$(RT_OUTPUT_DIR_$(2))" \
                -L "$$(LLVM_LIBDIR_$(2))" \
+               -L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
                --out-dir $$(@D) $$<
        @touch $$@
        $$(call LIST_ALL_OLD_GLOB_MATCHES,\
index 364564168a5e88af7241788aee0c14c10c51e9fa..f745f5d61cb9a19e3065e33303a67ed5412d618b 100644 (file)
 import os
 import sys
 import subprocess
+import itertools
+from os import path
 
 f = open(sys.argv[1], 'wb')
 
 components = sys.argv[2].split(' ')
 components = [i for i in components if i]  # ignore extra whitespaces
+enable_static = sys.argv[3]
 
 f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
@@ -41,7 +44,7 @@ def run(args):
         sys.exit(1)
     return out
 
-for llconfig in sys.argv[3:]:
+for llconfig in sys.argv[4:]:
     f.write("\n")
 
     out = run([llconfig, '--host-target'])
@@ -94,9 +97,13 @@ for llconfig in sys.argv[3:]:
 
     # C++ runtime library
     out = run([llconfig, '--cxxflags'])
-    if 'stdlib=libc++' in out:
-        f.write("#[link(name = \"c++\")]\n")
+    if enable_static == '1':
+      assert('stdlib=libc++' not in out)
+      f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
     else:
+      if 'stdlib=libc++' in out:
+        f.write("#[link(name = \"c++\")]\n")
+      else:
         f.write("#[link(name = \"stdc++\")]\n")
 
     # Attach everything to an extern block