Skip to content

Commit 4995a85

Browse files
committed
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
2 parents 22d3669 + 3cf0b9b commit 4995a85

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

mk/prepare.mk

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#
1717
# It requires the following variables to be set:
1818
#
19-
# PREPARE_HOST - the host triple
19+
# PREPARE_HOST - the host triple
2020
# PREPARE_TARGETS - the target triples, space separated
2121
# PREPARE_DEST_DIR - the directory to put the image
2222

@@ -172,7 +172,10 @@ prepare-target-$(2)-host-$(3)-$(1): \
172172
$$(if $$(findstring $(2),$$(CFG_HOST)), \
173173
$$(foreach crate,$$(HOST_CRATES), \
174174
$$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$$(crate)),)
175-
# Only install if this host and target combo is being prepared
175+
# Only install if this host and target combo is being prepared. Also be sure to
176+
# *not* install the rlibs for host crates because there's no need to statically
177+
# link against most of them. They just produce a large amount of extra size
178+
# bloat.
176179
$$(if $$(findstring $(1), $$(PREPARE_STAGE)),\
177180
$$(if $$(findstring $(2), $$(PREPARE_TARGETS)),\
178181
$$(if $$(findstring $(3), $$(PREPARE_HOST)),\
@@ -182,8 +185,7 @@ prepare-target-$(2)-host-$(3)-$(1): \
182185
$$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate))))\
183186
$$(if $$(findstring $(2),$$(CFG_HOST)),\
184187
$$(foreach crate,$$(HOST_CRATES),\
185-
$$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))\
186-
$$(call PREPARE_LIB,$$(call CFG_RLIB_GLOB,$$(crate)))),)\
188+
$$(call PREPARE_LIB,$$(call CFG_LIB_GLOB_$(2),$$(crate)))),)\
187189
$$(call PREPARE_LIB,libmorestack.a) \
188190
$$(call PREPARE_LIB,libcompiler-rt.a),),),)
189191
endef

src/librustc/back/link.rs

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ use std::run;
3434
use std::str;
3535
use std::io;
3636
use std::io::fs;
37+
use flate;
3738
use serialize::hex::ToHex;
3839
use extra::tempfile::TempDir;
3940
use syntax::abi;
@@ -942,6 +943,15 @@ fn link_rlib(sess: Session,
942943
// For LTO purposes, the bytecode of this library is also inserted
943944
// into the archive.
944945
let bc = obj_filename.with_extension("bc");
946+
match fs::File::open(&bc).read_to_end().and_then(|data| {
947+
fs::File::create(&bc).write(flate::deflate_bytes(data))
948+
}) {
949+
Ok(()) => {}
950+
Err(e) => {
951+
sess.err(format!("failed to compress bytecode: {}", e));
952+
sess.abort_if_errors()
953+
}
954+
}
945955
a.add_file(&bc, false);
946956
if !sess.opts.cg.save_temps &&
947957
!sess.opts.output_types.contains(&OutputTypeBitcode) {

src/librustc/back/lto.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use metadata::cstore;
1616
use util::common::time;
1717

1818
use std::libc;
19+
use flate;
1920

2021
pub fn run(sess: session::Session, llmod: ModuleRef,
2122
tm: TargetMachineRef, reachable: &[~str]) {
@@ -55,6 +56,8 @@ pub fn run(sess: session::Session, llmod: ModuleRef,
5556
let bc = time(sess.time_passes(), format!("read {}.bc", name), (), |_|
5657
archive.read(format!("{}.bc", name)));
5758
let bc = bc.expect("missing bytecode in archive!");
59+
let bc = time(sess.time_passes(), format!("inflate {}.bc", name), (), |_|
60+
flate::inflate_bytes(bc));
5861
let ptr = bc.as_ptr();
5962
debug!("linking {}", name);
6063
time(sess.time_passes(), format!("ll link {}", name), (), |()| unsafe {

0 commit comments

Comments
 (0)