From f92bfb580780cda02f9ba8a935538f984d8a4c0d Mon Sep 17 00:00:00 2001 From: Veetaha Date: Sun, 21 Jun 2020 15:58:34 +0300 Subject: Gzip artifacts Co-authored-by: bjorn3 Override miniz_oxide to build it with optimizations Building this crate with optimizations decreases the gzipping part of `cargo xtask dist` from `30-40s` down to `3s`, the overhead for `rustc` to apply optimizations is miserable on this background --- xtask/src/dist.rs | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs index aef68089e..b8f68027c 100644 --- a/xtask/src/dist.rs +++ b/xtask/src/dist.rs @@ -1,4 +1,10 @@ -use std::path::PathBuf; +use flate2::{write::GzEncoder, Compression}; +use std::{ + env, + fs::File, + io, + path::{Path, PathBuf}, +}; use anyhow::Result; @@ -16,7 +22,7 @@ pub fn run_dist(nightly: bool, client_version: Option) -> Result<()> { let release_tag = if nightly { "nightly".to_string() } else { date_iso()? }; dist_client(&version, &release_tag)?; } - dist_server(nightly)?; + dist_server()?; Ok(()) } @@ -46,17 +52,14 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { Ok(()) } -fn dist_server(nightly: bool) -> Result<()> { +fn dist_server() -> Result<()> { if cfg!(target_os = "linux") { - std::env::set_var("CC", "clang"); + env::set_var("CC", "clang"); run!( "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" // We'd want to add, but that requires setting the right linker somehow // --features=jemalloc )?; - if !nightly { - run!("strip ./target/release/rust-analyzer")?; - } } else { run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; } @@ -71,8 +74,20 @@ fn dist_server(nightly: bool) -> Result<()> { panic!("Unsupported OS") }; - fs2::copy(src, dst)?; + let src = Path::new(src); + let dst = Path::new(dst); + + fs2::copy(&src, &dst)?; + gzip(&src, &dst.with_extension("gz"))?; + + Ok(()) +} +fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { + let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); + let mut input = io::BufReader::new(File::open(src_path)?); + io::copy(&mut input, &mut encoder)?; + encoder.finish()?; Ok(()) } -- cgit v1.2.3