Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove the in-tree flate crate
A long time coming this commit removes the `flate` crate in favor of the
`flate2` crate on crates.io. The functionality in `flate2` originally flowered
out of `flate` itself and is additionally the namesake for the crate. This will
leave a gap in the naming (there's not `flate` crate), which will likely cause a
particle collapse of some form somewhere.
  • Loading branch information
alexcrichton committed Jun 20, 2017
1 parent 380100c commit a4024c5
Show file tree
Hide file tree
Showing 21 changed files with 71 additions and 2,131 deletions.
6 changes: 0 additions & 6 deletions COPYRIGHT
Expand Up @@ -22,12 +22,6 @@ The Rust Project includes packages written by third parties.
The following third party packages are included, and carry
their own copyright notices and license terms:

* The src/rt/miniz.c file, carrying an implementation of
RFC1950/RFC1951 DEFLATE, by Rich Geldreich
<richgel99@gmail.com>. All uses of this file are
permitted by the embedded "unlicense" notice
(effectively: public domain with warranty disclaimer).

* LLVM. Code for this package is found in src/llvm.

Copyright (c) 2003-2013 University of Illinois at
Expand Down
14 changes: 0 additions & 14 deletions src/libflate/Cargo.toml

This file was deleted.

18 changes: 0 additions & 18 deletions src/libflate/build.rs

This file was deleted.

166 changes: 0 additions & 166 deletions src/libflate/lib.rs

This file was deleted.

29 changes: 29 additions & 0 deletions src/librustc/Cargo.toml
Expand Up @@ -22,3 +22,32 @@ rustc_errors = { path = "../librustc_errors" }
serialize = { path = "../libserialize" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }

# Note that these dependencies are a lie, they're just here to get linkage to
# work.
#
# We're creating a bunch of dylibs for the compiler but we're also compiling a
# bunch of crates.io crates. Everything in the compiler is compiled as an
# rlib/dylib pair but all crates.io crates tend to just be rlibs. This means
# we've got a problem for dependency graphs that look like:
#
# foo - rustc_trans
# / \
# rustc ---- rustc_driver
# \ /
# foo - rustc_metadata
#
# Here the crate `foo` is linked into the `rustc_trans` and the
# `rustc_metadata` dylibs, meaning we've got duplicate copies! When we then
# go to link `rustc_driver` the compiler notices this and gives us a compiler
# error.
#
# To work around this problem we just add these crates.io dependencies to the
# `rustc` crate which is a shared dependency above. That way the crate `foo`
# shows up in the dylib for the `rustc` crate, deduplicating it and allowing
# crates like `rustc_trans` to use `foo` *through* the `rustc` crate.
#
# tl;dr; this is not needed to get `rustc` to compile, but if you remove it then
# later crate stop compiling. If you can remove this and everything
# compiles, then please feel free to do so!
flate2 = "0.2"
2 changes: 2 additions & 0 deletions src/librustc/lib.rs
Expand Up @@ -63,6 +63,8 @@ extern crate syntax_pos;

extern crate serialize as rustc_serialize; // used by deriving

extern crate flate2;

#[macro_use]
mod macros;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
flate = { path = "../libflate" }
flate2 = "0.2"
log = "0.3"
owning_ref = "0.3.3"
proc_macro = { path = "../libproc_macro" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/lib.rs
Expand Up @@ -33,7 +33,7 @@ extern crate log;
#[macro_use]
extern crate syntax;
extern crate syntax_pos;
extern crate flate;
extern crate flate2;
extern crate serialize as rustc_serialize; // used by deriving
extern crate owning_ref;
extern crate rustc_errors as errors;
Expand Down
7 changes: 4 additions & 3 deletions src/librustc_metadata/locator.rs
Expand Up @@ -242,7 +242,7 @@ use std::io::{self, Read};
use std::path::{Path, PathBuf};
use std::time::Instant;

use flate;
use flate2::read::ZlibDecoder;
use owning_ref::{ErasedBoxRef, OwningRef};

pub struct CrateMismatch {
Expand Down Expand Up @@ -861,8 +861,9 @@ fn get_metadata_section_imp(target: &Target,
// Header is okay -> inflate the actual metadata
let compressed_bytes = &buf[header_len..];
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
match flate::inflate_bytes(compressed_bytes) {
Ok(inflated) => {
let mut inflated = Vec::new();
match ZlibDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
Ok(_) => {
let buf = unsafe { OwningRef::new_assert_stable_address(inflated) };
buf.map_owner_box().erase_owner()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ crate-type = ["dylib"]
test = false

[dependencies]
flate = { path = "../libflate" }
flate2 = "0.2"
log = "0.3"
owning_ref = "0.3.3"
rustc = { path = "../librustc" }
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_trans/back/link.rs
Expand Up @@ -42,7 +42,8 @@ use std::mem;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::str;
use flate;
use flate2::Compression;
use flate2::write::ZlibEncoder;
use syntax::ast;
use syntax::attr;
use syntax_pos::Span;
Expand Down Expand Up @@ -570,7 +571,9 @@ fn link_rlib<'a>(sess: &'a Session,
e))
}

let bc_data_deflated = flate::deflate_bytes(&bc_data);
let mut bc_data_deflated = Vec::new();
ZlibEncoder::new(&mut bc_data_deflated, Compression::Default)
.write_all(&bc_data).unwrap();

let mut bc_file_deflated = match fs::File::create(&bc_deflated_filename) {
Ok(file) => file,
Expand Down
29 changes: 16 additions & 13 deletions src/librustc_trans/back/lto.rs
Expand Up @@ -21,8 +21,9 @@ use rustc::hir::def_id::LOCAL_CRATE;
use back::write::{ModuleConfig, with_llvm_pmb};

use libc;
use flate;
use flate2::read::ZlibDecoder;

use std::io::Read;
use std::ffi::CString;
use std::path::Path;

Expand Down Expand Up @@ -112,13 +113,14 @@ pub fn run(sess: &session::Session,
link::RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET..
(link::RLIB_BYTECODE_OBJECT_V1_DATA_OFFSET + data_size as usize)];

match flate::inflate_bytes(compressed_data) {
Ok(inflated) => inflated,
Err(_) => {
sess.fatal(&format!("failed to decompress bc of `{}`",
name))
}
let mut inflated = Vec::new();
let res = ZlibDecoder::new(compressed_data)
.read_to_end(&mut inflated);
if res.is_err() {
sess.fatal(&format!("failed to decompress bc of `{}`",
name))
}
inflated
} else {
sess.fatal(&format!("Unsupported bytecode format version {}",
version))
Expand All @@ -129,13 +131,14 @@ pub fn run(sess: &session::Session,
// the object must be in the old, pre-versioning format, so
// simply inflate everything and let LLVM decide if it can
// make sense of it
match flate::inflate_bytes(bc_encoded) {
Ok(bc) => bc,
Err(_) => {
sess.fatal(&format!("failed to decompress bc of `{}`",
name))
}
let mut inflated = Vec::new();
let res = ZlibDecoder::new(bc_encoded)
.read_to_end(&mut inflated);
if res.is_err() {
sess.fatal(&format!("failed to decompress bc of `{}`",
name))
}
inflated
})
};

Expand Down
7 changes: 5 additions & 2 deletions src/librustc_trans/base.rs
Expand Up @@ -727,7 +727,9 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
link_meta: &LinkMeta,
exported_symbols: &NodeSet)
-> (ContextRef, ModuleRef, EncodedMetadata) {
use flate;
use std::io::Write;
use flate2::Compression;
use flate2::write::ZlibEncoder;

let (metadata_llcx, metadata_llmod) = unsafe {
context::create_context_and_module(tcx.sess, "metadata")
Expand Down Expand Up @@ -767,7 +769,8 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,

assert!(kind == MetadataKind::Compressed);
let mut compressed = cstore.metadata_encoding_version().to_vec();
compressed.extend_from_slice(&flate::deflate_bytes(&metadata.raw_data));
ZlibEncoder::new(&mut compressed, Compression::Default)
.write_all(&metadata.raw_data).unwrap();

let llmeta = C_bytes_in_context(metadata_llcx, &compressed);
let llconst = C_struct_in_context(metadata_llcx, &[llmeta], false);
Expand Down

0 comments on commit a4024c5

Please sign in to comment.