rustc: Compress bytecode files in rlibs

These are only ever used with LTO, so there's no need for reading them to be
speedy.
This commit is contained in:
Alex Crichton 2014-02-21 10:54:00 -08:00
parent 6532d2fa0d
commit 991d466c18
2 changed files with 13 additions and 0 deletions

View File

@ -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) {

View File

@ -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 {