Skip to content

Commit a4024c5

Browse files
committedJun 20, 2017
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.
1 parent 380100c commit a4024c5

File tree

21 files changed

+71
-2131
lines changed

21 files changed

+71
-2131
lines changed
 

‎COPYRIGHT

-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,6 @@ The Rust Project includes packages written by third parties.
2222
The following third party packages are included, and carry
2323
their own copyright notices and license terms:
2424

25-
* The src/rt/miniz.c file, carrying an implementation of
26-
RFC1950/RFC1951 DEFLATE, by Rich Geldreich
27-
<richgel99@gmail.com>. All uses of this file are
28-
permitted by the embedded "unlicense" notice
29-
(effectively: public domain with warranty disclaimer).
30-
3125
* LLVM. Code for this package is found in src/llvm.
3226

3327
Copyright (c) 2003-2013 University of Illinois at

‎src/libflate/Cargo.toml

-14
This file was deleted.

‎src/libflate/build.rs

-18
This file was deleted.

‎src/libflate/lib.rs

-166
This file was deleted.

‎src/librustc/Cargo.toml

+29
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,32 @@ rustc_errors = { path = "../librustc_errors" }
2222
serialize = { path = "../libserialize" }
2323
syntax = { path = "../libsyntax" }
2424
syntax_pos = { path = "../libsyntax_pos" }
25+
26+
# Note that these dependencies are a lie, they're just here to get linkage to
27+
# work.
28+
#
29+
# We're creating a bunch of dylibs for the compiler but we're also compiling a
30+
# bunch of crates.io crates. Everything in the compiler is compiled as an
31+
# rlib/dylib pair but all crates.io crates tend to just be rlibs. This means
32+
# we've got a problem for dependency graphs that look like:
33+
#
34+
# foo - rustc_trans
35+
# / \
36+
# rustc ---- rustc_driver
37+
# \ /
38+
# foo - rustc_metadata
39+
#
40+
# Here the crate `foo` is linked into the `rustc_trans` and the
41+
# `rustc_metadata` dylibs, meaning we've got duplicate copies! When we then
42+
# go to link `rustc_driver` the compiler notices this and gives us a compiler
43+
# error.
44+
#
45+
# To work around this problem we just add these crates.io dependencies to the
46+
# `rustc` crate which is a shared dependency above. That way the crate `foo`
47+
# shows up in the dylib for the `rustc` crate, deduplicating it and allowing
48+
# crates like `rustc_trans` to use `foo` *through* the `rustc` crate.
49+
#
50+
# tl;dr; this is not needed to get `rustc` to compile, but if you remove it then
51+
# later crate stop compiling. If you can remove this and everything
52+
# compiles, then please feel free to do so!
53+
flate2 = "0.2"

‎src/librustc/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ extern crate syntax_pos;
6363

6464
extern crate serialize as rustc_serialize; // used by deriving
6565

66+
extern crate flate2;
67+
6668
#[macro_use]
6769
mod macros;
6870

‎src/librustc_metadata/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ path = "lib.rs"
99
crate-type = ["dylib"]
1010

1111
[dependencies]
12-
flate = { path = "../libflate" }
12+
flate2 = "0.2"
1313
log = "0.3"
1414
owning_ref = "0.3.3"
1515
proc_macro = { path = "../libproc_macro" }

‎src/librustc_metadata/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern crate log;
3333
#[macro_use]
3434
extern crate syntax;
3535
extern crate syntax_pos;
36-
extern crate flate;
36+
extern crate flate2;
3737
extern crate serialize as rustc_serialize; // used by deriving
3838
extern crate owning_ref;
3939
extern crate rustc_errors as errors;

‎src/librustc_metadata/locator.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ use std::io::{self, Read};
242242
use std::path::{Path, PathBuf};
243243
use std::time::Instant;
244244

245-
use flate;
245+
use flate2::read::ZlibDecoder;
246246
use owning_ref::{ErasedBoxRef, OwningRef};
247247

248248
pub struct CrateMismatch {
@@ -861,8 +861,9 @@ fn get_metadata_section_imp(target: &Target,
861861
// Header is okay -> inflate the actual metadata
862862
let compressed_bytes = &buf[header_len..];
863863
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
864-
match flate::inflate_bytes(compressed_bytes) {
865-
Ok(inflated) => {
864+
let mut inflated = Vec::new();
865+
match ZlibDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
866+
Ok(_) => {
866867
let buf = unsafe { OwningRef::new_assert_stable_address(inflated) };
867868
buf.map_owner_box().erase_owner()
868869
}

‎src/librustc_trans/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ crate-type = ["dylib"]
1010
test = false
1111

1212
[dependencies]
13-
flate = { path = "../libflate" }
13+
flate2 = "0.2"
1414
log = "0.3"
1515
owning_ref = "0.3.3"
1616
rustc = { path = "../librustc" }

‎src/librustc_trans/back/link.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ use std::mem;
4242
use std::path::{Path, PathBuf};
4343
use std::process::Command;
4444
use std::str;
45-
use flate;
45+
use flate2::Compression;
46+
use flate2::write::ZlibEncoder;
4647
use syntax::ast;
4748
use syntax::attr;
4849
use syntax_pos::Span;
@@ -570,7 +571,9 @@ fn link_rlib<'a>(sess: &'a Session,
570571
e))
571572
}
572573

573-
let bc_data_deflated = flate::deflate_bytes(&bc_data);
574+
let mut bc_data_deflated = Vec::new();
575+
ZlibEncoder::new(&mut bc_data_deflated, Compression::Default)
576+
.write_all(&bc_data).unwrap();
574577

575578
let mut bc_file_deflated = match fs::File::create(&bc_deflated_filename) {
576579
Ok(file) => file,

‎src/librustc_trans/back/lto.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ use rustc::hir::def_id::LOCAL_CRATE;
2121
use back::write::{ModuleConfig, with_llvm_pmb};
2222

2323
use libc;
24-
use flate;
24+
use flate2::read::ZlibDecoder;
2525

26+
use std::io::Read;
2627
use std::ffi::CString;
2728
use std::path::Path;
2829

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

115-
match flate::inflate_bytes(compressed_data) {
116-
Ok(inflated) => inflated,
117-
Err(_) => {
118-
sess.fatal(&format!("failed to decompress bc of `{}`",
119-
name))
120-
}
116+
let mut inflated = Vec::new();
117+
let res = ZlibDecoder::new(compressed_data)
118+
.read_to_end(&mut inflated);
119+
if res.is_err() {
120+
sess.fatal(&format!("failed to decompress bc of `{}`",
121+
name))
121122
}
123+
inflated
122124
} else {
123125
sess.fatal(&format!("Unsupported bytecode format version {}",
124126
version))
@@ -129,13 +131,14 @@ pub fn run(sess: &session::Session,
129131
// the object must be in the old, pre-versioning format, so
130132
// simply inflate everything and let LLVM decide if it can
131133
// make sense of it
132-
match flate::inflate_bytes(bc_encoded) {
133-
Ok(bc) => bc,
134-
Err(_) => {
135-
sess.fatal(&format!("failed to decompress bc of `{}`",
136-
name))
137-
}
134+
let mut inflated = Vec::new();
135+
let res = ZlibDecoder::new(bc_encoded)
136+
.read_to_end(&mut inflated);
137+
if res.is_err() {
138+
sess.fatal(&format!("failed to decompress bc of `{}`",
139+
name))
138140
}
141+
inflated
139142
})
140143
};
141144

‎src/librustc_trans/base.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,9 @@ fn write_metadata<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'gcx>,
727727
link_meta: &LinkMeta,
728728
exported_symbols: &NodeSet)
729729
-> (ContextRef, ModuleRef, EncodedMetadata) {
730-
use flate;
730+
use std::io::Write;
731+
use flate2::Compression;
732+
use flate2::write::ZlibEncoder;
731733

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

768770
assert!(kind == MetadataKind::Compressed);
769771
let mut compressed = cstore.metadata_encoding_version().to_vec();
770-
compressed.extend_from_slice(&flate::deflate_bytes(&metadata.raw_data));
772+
ZlibEncoder::new(&mut compressed, Compression::Default)
773+
.write_all(&metadata.raw_data).unwrap();
771774

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

‎src/librustc_trans/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
use rustc::dep_graph::WorkProduct;
4040
use syntax_pos::symbol::Symbol;
4141

42-
extern crate flate;
42+
extern crate flate2;
4343
extern crate libc;
4444
extern crate owning_ref;
4545
#[macro_use] extern crate rustc;

‎src/rt/miniz.c

-1,890
This file was deleted.

‎src/test/run-make/no-duplicate-libs/bar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(lang_items, libc, compiler_builtins_lib)]
11+
#![feature(lang_items, alloc_system, compiler_builtins_lib)]
1212
#![crate_type = "dylib"]
1313
#![no_std]
1414

15-
extern crate libc;
15+
extern crate alloc_system;
1616
extern crate compiler_builtins;
1717

1818
#[no_mangle]

‎src/test/run-make/no-duplicate-libs/foo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(lang_items, libc, compiler_builtins_lib)]
11+
#![feature(lang_items, alloc_system, compiler_builtins_lib)]
1212
#![no_std]
1313
#![crate_type = "dylib"]
1414

15-
extern crate libc;
15+
extern crate alloc_system;
1616
extern crate compiler_builtins;
1717

1818
#[no_mangle]

‎src/test/run-make/save-analysis-fail/foo.rs

-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ extern crate graphviz;
1717

1818
extern crate krate2;
1919
extern crate krate2 as krate3;
20-
extern crate flate as myflate;
2120

2221
use graphviz::RenderOption;
2322
use std::collections::{HashMap,HashSet};
@@ -51,7 +50,6 @@ fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
5150

5251
krate2::hello();
5352
krate3::hello();
54-
myflate::deflate_bytes(&[]);
5553

5654
let x = (3isize, 4usize);
5755
let y = x.1;

‎src/test/run-make/save-analysis/foo.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern crate graphviz;
1818

1919
extern crate krate2;
2020
extern crate krate2 as krate3;
21-
extern crate flate as myflate;
2221

2322
use graphviz::RenderOption;
2423
use std::collections::{HashMap,HashSet};
@@ -52,7 +51,6 @@ fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
5251

5352
krate2::hello();
5453
krate3::hello();
55-
myflate::deflate_bytes(&[]);
5654

5755
let x = (3isize, 4usize);
5856
let y = x.1;

‎src/test/run-pass/smallest-hello-world.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
// pretty-expanded FIXME #23616
1414

15-
#![feature(intrinsics, lang_items, start, no_core, libc)]
15+
#![feature(intrinsics, lang_items, start, no_core, alloc_system)]
1616
#![no_core]
1717

18-
extern crate libc;
18+
extern crate alloc_system;
1919

2020
extern { fn puts(s: *const u8); }
2121
extern "rust-intrinsic" { fn transmute<T, U>(t: T) -> U; }

‎src/tools/tidy/src/style.rs

-3
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ pub fn check(path: &Path, bad: &mut bool) {
101101
filename.starts_with(".#") {
102102
return
103103
}
104-
if filename == "miniz.c" {
105-
return
106-
}
107104

108105
contents.truncate(0);
109106
t!(t!(File::open(file), file).read_to_string(&mut contents));

0 commit comments

Comments
 (0)
Please sign in to comment.