Skip to content

Commit

Permalink
rustc: Compress bytecode files in rlibs
Browse files Browse the repository at this point in the history
These are only ever used with LTO, so there's no need for reading them to be
speedy.
  • Loading branch information
alexcrichton committed Feb 21, 2014
1 parent 6532d2f commit 991d466
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit 991d466

Please sign in to comment.