about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-02-22 17:46:53 -0800
committerbors <bors@rust-lang.org>2014-02-22 17:46:53 -0800
commit4995a85f401e17ea7a9b8eab32335b5fd13ce248 (patch)
treeb14f5367835f027143cc50efe514900d65837f62
parent22d3669b9e7f40a5c05425141dcba6137189ee31 (diff)
parent3cf0b9bd113e25b9b8020cff6ed7bcd82760473e (diff)
auto merge of #12448 : alexcrichton/rust/smaller-rust, r=brson
Two optimizations:

1. Compress `foo.bc` in each rlib with `flate`. These are just taking up space and are only used with LTO, no need for LTO to be speedy.
2. Stop install `librustc.rlib` and friends, this is a *huge* source of bloat. There's no need for us to install static libraries for these components.

cc #12440
-rw-r--r--mk/prepare.mk10
-rw-r--r--src/librustc/back/link.rs10
-rw-r--r--src/librustc/back/lto.rs3
3 files changed, 19 insertions, 4 deletions
diff --git a/mk/prepare.mk b/mk/prepare.mk
index 361b9c7ea9b..356ce2e908e 100644
--- a/mk/prepare.mk
+++ b/mk/prepare.mk
@@ -16,7 +16,7 @@
 #
 # It requires the following variables to be set:
 #
-#   PREPARE_HOST - the host triple 
+#   PREPARE_HOST - the host triple
 #   PREPARE_TARGETS - the target triples, space separated
 #   PREPARE_DEST_DIR - the directory to put the image
 
@@ -172,7 +172,10 @@ prepare-target-$(2)-host-$(3)-$(1): \
         $$(if $$(findstring $(2),$$(CFG_HOST)), \
           $$(foreach crate,$$(HOST_CRATES), \
             $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
-# Only install if this host and target combo is being prepared
+# Only install if this host and target combo is being prepared. Also be sure to
+# *not* install the rlibs for host crates because there's no need to statically
+# link against most of them. They just produce a large amount of extra size
+# bloat.
 	$$(if $$(findstring $(1), $$(PREPARE_STAGE)),\
       $$(if $$(findstring $(2), $$(PREPARE_TARGETS)),\
         $$(if $$(findstring $(3), $$(PREPARE_HOST)),\
@@ -182,8 +185,7 @@ prepare-target-$(2)-host-$(3)-$(1): \
             $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate))))\
           $$(if $$(findstring $(2),$$(CFG_HOST)),\
             $$(foreach crate,$$(HOST_CRATES),\
-              $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))\
-              $$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))),)\
+              $$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),)\
           $$(call PREPARE_LIB,libmorestack.a) \
           $$(call PREPARE_LIB,libcompiler-rt.a),),),)
 endef
diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs
index a9d7d231cef..bd0748761ee 100644
--- a/src/librustc/back/link.rs
+++ b/src/librustc/back/link.rs
@@ -34,6 +34,7 @@ use std::run;
 use std::str;
 use std::io;
 use std::io::fs;
+use flate;
 use serialize::hex::ToHex;
 use extra::tempfile::TempDir;
 use syntax::abi;
@@ -942,6 +943,15 @@ fn link_rlib(sess: Session,
             // For LTO purposes, the bytecode of this library is also inserted
             // into the archive.
             let bc = obj_filename.with_extension("bc");
+            match fs::File::open(&bc).read_to_end().and_then(|data| {
+                fs::File::create(&bc).write(flate::deflate_bytes(data))
+            }) {
+                Ok(()) => {}
+                Err(e) => {
+                    sess.err(format!("failed to compress bytecode: {}", e));
+                    sess.abort_if_errors()
+                }
+            }
             a.add_file(&bc, false);
             if !sess.opts.cg.save_temps &&
                !sess.opts.output_types.contains(&OutputTypeBitcode) {
diff --git a/src/librustc/back/lto.rs b/src/librustc/back/lto.rs
index b2440dcedbd..75fde2fdc51 100644
--- a/src/librustc/back/lto.rs
+++ b/src/librustc/back/lto.rs
@@ -16,6 +16,7 @@ use metadata::cstore;
 use util::common::time;
 
 use std::libc;
+use flate;
 
 pub fn run(sess: session::Session, llmod: ModuleRef,
            tm: TargetMachineRef, reachable: &[~str]) {
@@ -55,6 +56,8 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
         let bc = time(sess.time_passes(), format!("read {}.bc", name), (), |_|
                       archive.read(format!("{}.bc", name)));
         let bc = bc.expect("missing bytecode in archive!");
+        let bc = time(sess.time_passes(), format!("inflate {}.bc", name), (), |_|
+                      flate::inflate_bytes(bc));
         let ptr = bc.as_ptr();
         debug!("linking {}", name);
         time(sess.time_passes(), format!("ll link {}", name), (), |()| unsafe {