Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the size of a rust install slightly #12448

Merged
merged 2 commits into from
Feb 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions mk/prepare.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)),\
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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 {
Expand Down