From acdee8b904178e13616cea8c31bcdb1f063ddef5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 16 Apr 2014 10:45:04 -0700 Subject: [PATCH] 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. --- configure | 1 + mk/llvm.mk | 19 ++++++++++++++----- mk/target.mk | 1 + src/etc/mklldeps.py | 13 ++++++++++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/configure b/configure index 8d0116cb0ca..983be4e8a0c 100755 --- 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" diff --git a/mk/llvm.mk b/mk/llvm.mk index 13c4ae5e860..789ce2dabc2 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -42,16 +42,25 @@ $$(LLVM_STAMP_$(1)): $(S)src/rustllvm/llvm-auto-clean-trigger @$$(call E, make: done cleaning llvm) touch $$@ -endef +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 -$(foreach host,$(CFG_HOST), \ - $(eval LLVM_CONFIGS := $(LLVM_CONFIGS) $(LLVM_CONFIG_$(host)))) +endef $(foreach host,$(CFG_HOST), \ $(eval $(call DEF_LLVM_RULES,$(host)))) +$(foreach host,$(CFG_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) diff --git a/mk/target.mk b/mk/target.mk index 11c57ac070f..448299965a8 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -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,\ diff --git a/src/etc/mklldeps.py b/src/etc/mklldeps.py index 364564168a5..f745f5d61cb 100644 --- a/src/etc/mklldeps.py +++ b/src/etc/mklldeps.py @@ -11,11 +11,14 @@ 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