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.
This commit is contained in:
Alex Crichton 2017-06-08 14:10:36 -07:00
parent 380100c568
commit a4024c58e1
21 changed files with 71 additions and 2131 deletions

View File

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

View File

@ -1,14 +0,0 @@
[package]
authors = ["The Rust Project Developers"]
name = "flate"
version = "0.0.0"
build = "build.rs"
[lib]
name = "flate"
path = "lib.rs"
crate-type = ["dylib"]
[build-dependencies]
build_helper = { path = "../build_helper" }
gcc = "0.3.50"

View File

@ -1,18 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate gcc;
fn main() {
println!("cargo:rerun-if-changed=../rt/miniz.c");
gcc::Config::new()
.file("../rt/miniz.c")
.compile("libminiz.a");
}

View File

@ -1,166 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Simple [DEFLATE][def]-based compression. This is a wrapper around the
//! [`miniz`][mz] library, which is a one-file pure-C implementation of zlib.
//!
//! [def]: https://en.wikipedia.org/wiki/DEFLATE
//! [mz]: https://code.google.com/p/miniz/
#![crate_name = "flate"]
#![crate_type = "rlib"]
#![crate_type = "dylib"]
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
html_root_url = "https://doc.rust-lang.org/nightly/",
test(attr(deny(warnings))))]
#![deny(warnings)]
#![feature(libc)]
#![feature(unique)]
#![cfg_attr(test, feature(rand))]
extern crate libc;
use libc::{c_int, c_void, size_t};
use std::fmt;
use std::ops::Deref;
use std::ptr::Unique;
use std::slice;
#[derive(Clone, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Error {
_unused: (),
}
impl Error {
fn new() -> Error {
Error { _unused: () }
}
}
impl fmt::Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
"decompression error".fmt(f)
}
}
pub struct Bytes {
ptr: Unique<u8>,
len: usize,
}
impl Deref for Bytes {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe { slice::from_raw_parts(self.ptr.as_ptr(), self.len) }
}
}
impl Drop for Bytes {
fn drop(&mut self) {
unsafe {
libc::free(self.ptr.as_ptr() as *mut _);
}
}
}
extern "C" {
/// Raw miniz compression function.
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *mut c_void;
/// Raw miniz decompression function.
fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
src_buf_len: size_t,
pout_len: *mut size_t,
flags: c_int)
-> *mut c_void;
}
const LZ_FAST: c_int = 0x01; // LZ with 1 probe, "fast"
const TDEFL_GREEDY_PARSING_FLAG: c_int = 0x04000; // fast greedy parsing instead of lazy parsing
/// Compress a buffer without writing any sort of header on the output. Fast
/// compression is used because it is almost twice as fast as default
/// compression and the compression ratio is only marginally worse.
pub fn deflate_bytes(bytes: &[u8]) -> Bytes {
let flags = LZ_FAST | TDEFL_GREEDY_PARSING_FLAG;
unsafe {
let mut outsz: size_t = 0;
let res = tdefl_compress_mem_to_heap(bytes.as_ptr() as *const _,
bytes.len() as size_t,
&mut outsz,
flags);
assert!(!res.is_null());
Bytes {
ptr: Unique::new(res as *mut u8),
len: outsz as usize,
}
}
}
/// Decompress a buffer without parsing any sort of header on the input.
pub fn inflate_bytes(bytes: &[u8]) -> Result<Bytes, Error> {
let flags = 0;
unsafe {
let mut outsz: size_t = 0;
let res = tinfl_decompress_mem_to_heap(bytes.as_ptr() as *const _,
bytes.len() as size_t,
&mut outsz,
flags);
if !res.is_null() {
Ok(Bytes {
ptr: Unique::new(res as *mut u8),
len: outsz as usize,
})
} else {
Err(Error::new())
}
}
}
#[cfg(test)]
mod tests {
#![allow(deprecated)]
use super::{deflate_bytes, inflate_bytes};
use std::__rand::{Rng, thread_rng};
#[test]
fn test_flate_round_trip() {
let mut r = thread_rng();
let mut words = vec![];
for _ in 0..20 {
let range = r.gen_range(1, 10);
let v = r.gen_iter::<u8>().take(range).collect::<Vec<u8>>();
words.push(v);
}
for _ in 0..20 {
let mut input = vec![];
for _ in 0..2000 {
input.extend_from_slice(r.choose(&words).unwrap());
}
let cmp = deflate_bytes(&input);
let out = inflate_bytes(&cmp).unwrap();
assert_eq!(&*input, &*out);
}
}
#[test]
fn test_zlib_flate() {
let bytes = vec![1, 2, 3, 4, 5];
let deflated = deflate_bytes(&bytes);
let inflated = inflate_bytes(&deflated).unwrap();
assert_eq!(&*inflated, &*bytes);
}
}

View File

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

View File

@ -63,6 +63,8 @@
extern crate serialize as rustc_serialize; // used by deriving
extern crate flate2;
#[macro_use]
mod macros;

View File

@ -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" }

View File

@ -33,7 +33,7 @@
#[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;

View File

@ -242,7 +242,7 @@
use std::path::{Path, PathBuf};
use std::time::Instant;
use flate;
use flate2::read::ZlibDecoder;
use owning_ref::{ErasedBoxRef, OwningRef};
pub struct CrateMismatch {
@ -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()
}

View File

@ -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" }

View File

@ -42,7 +42,8 @@
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;
@ -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,

View File

@ -21,8 +21,9 @@
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;
@ -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))
@ -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
})
};

View File

@ -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")
@ -767,7 +769,8 @@ enum MetadataKind {
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);

View File

@ -39,7 +39,7 @@
use rustc::dep_graph::WorkProduct;
use syntax_pos::symbol::Symbol;
extern crate flate;
extern crate flate2;
extern crate libc;
extern crate owning_ref;
#[macro_use] extern crate rustc;

File diff suppressed because it is too large Load Diff

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(lang_items, libc, compiler_builtins_lib)]
#![feature(lang_items, alloc_system, compiler_builtins_lib)]
#![crate_type = "dylib"]
#![no_std]
extern crate libc;
extern crate alloc_system;
extern crate compiler_builtins;
#[no_mangle]

View File

@ -8,11 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(lang_items, libc, compiler_builtins_lib)]
#![feature(lang_items, alloc_system, compiler_builtins_lib)]
#![no_std]
#![crate_type = "dylib"]
extern crate libc;
extern crate alloc_system;
extern crate compiler_builtins;
#[no_mangle]

View File

@ -17,7 +17,6 @@
extern crate krate2;
extern crate krate2 as krate3;
extern crate flate as myflate;
use graphviz::RenderOption;
use std::collections::{HashMap,HashSet};
@ -51,7 +50,6 @@ fn foo(x: &Write) {}
krate2::hello();
krate3::hello();
myflate::deflate_bytes(&[]);
let x = (3isize, 4usize);
let y = x.1;

View File

@ -18,7 +18,6 @@
extern crate krate2;
extern crate krate2 as krate3;
extern crate flate as myflate;
use graphviz::RenderOption;
use std::collections::{HashMap,HashSet};
@ -52,7 +51,6 @@ fn foo(x: &Write) {}
krate2::hello();
krate3::hello();
myflate::deflate_bytes(&[]);
let x = (3isize, 4usize);
let y = x.1;

View File

@ -12,10 +12,10 @@
// pretty-expanded FIXME #23616
#![feature(intrinsics, lang_items, start, no_core, libc)]
#![feature(intrinsics, lang_items, start, no_core, alloc_system)]
#![no_core]
extern crate libc;
extern crate alloc_system;
extern { fn puts(s: *const u8); }
extern "rust-intrinsic" { fn transmute<T, U>(t: T) -> U; }

View File

@ -101,9 +101,6 @@ pub fn check(path: &Path, bad: &mut bool) {
filename.starts_with(".#") {
return
}
if filename == "miniz.c" {
return
}
contents.truncate(0);
t!(t!(File::open(file), file).read_to_string(&mut contents));