diff options
author | Veetaha <[email protected]> | 2020-06-21 13:58:34 +0100 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-07-07 21:30:11 +0100 |
commit | f92bfb580780cda02f9ba8a935538f984d8a4c0d (patch) | |
tree | fbf0e24250cc36eaa122904e78cd7cb50fe1c665 /xtask | |
parent | 980a67f44629ed67a54b603aaf9d015a81d61f7a (diff) |
Gzip artifacts
Co-authored-by: bjorn3 <[email protected]>
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
Diffstat (limited to 'xtask')
-rw-r--r-- | xtask/Cargo.toml | 1 | ||||
-rw-r--r-- | xtask/src/dist.rs | 31 |
2 files changed, 24 insertions, 8 deletions
diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index a8b9b010d..8045a98ea 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml | |||
@@ -14,3 +14,4 @@ pico-args = "0.3.1" | |||
14 | quote = "1.0.2" | 14 | quote = "1.0.2" |
15 | proc-macro2 = "1.0.8" | 15 | proc-macro2 = "1.0.8" |
16 | anyhow = "1.0.26" | 16 | anyhow = "1.0.26" |
17 | flate2 = "1.0" | ||
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 @@ | |||
1 | use std::path::PathBuf; | 1 | use flate2::{write::GzEncoder, Compression}; |
2 | use std::{ | ||
3 | env, | ||
4 | fs::File, | ||
5 | io, | ||
6 | path::{Path, PathBuf}, | ||
7 | }; | ||
2 | 8 | ||
3 | use anyhow::Result; | 9 | use anyhow::Result; |
4 | 10 | ||
@@ -16,7 +22,7 @@ pub fn run_dist(nightly: bool, client_version: Option<String>) -> Result<()> { | |||
16 | let release_tag = if nightly { "nightly".to_string() } else { date_iso()? }; | 22 | let release_tag = if nightly { "nightly".to_string() } else { date_iso()? }; |
17 | dist_client(&version, &release_tag)?; | 23 | dist_client(&version, &release_tag)?; |
18 | } | 24 | } |
19 | dist_server(nightly)?; | 25 | dist_server()?; |
20 | Ok(()) | 26 | Ok(()) |
21 | } | 27 | } |
22 | 28 | ||
@@ -46,17 +52,14 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> { | |||
46 | Ok(()) | 52 | Ok(()) |
47 | } | 53 | } |
48 | 54 | ||
49 | fn dist_server(nightly: bool) -> Result<()> { | 55 | fn dist_server() -> Result<()> { |
50 | if cfg!(target_os = "linux") { | 56 | if cfg!(target_os = "linux") { |
51 | std::env::set_var("CC", "clang"); | 57 | env::set_var("CC", "clang"); |
52 | run!( | 58 | run!( |
53 | "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" | 59 | "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" |
54 | // We'd want to add, but that requires setting the right linker somehow | 60 | // We'd want to add, but that requires setting the right linker somehow |
55 | // --features=jemalloc | 61 | // --features=jemalloc |
56 | )?; | 62 | )?; |
57 | if !nightly { | ||
58 | run!("strip ./target/release/rust-analyzer")?; | ||
59 | } | ||
60 | } else { | 63 | } else { |
61 | run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; | 64 | run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; |
62 | } | 65 | } |
@@ -71,8 +74,20 @@ fn dist_server(nightly: bool) -> Result<()> { | |||
71 | panic!("Unsupported OS") | 74 | panic!("Unsupported OS") |
72 | }; | 75 | }; |
73 | 76 | ||
74 | fs2::copy(src, dst)?; | 77 | let src = Path::new(src); |
78 | let dst = Path::new(dst); | ||
79 | |||
80 | fs2::copy(&src, &dst)?; | ||
81 | gzip(&src, &dst.with_extension("gz"))?; | ||
82 | |||
83 | Ok(()) | ||
84 | } | ||
75 | 85 | ||
86 | fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> { | ||
87 | let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best()); | ||
88 | let mut input = io::BufReader::new(File::open(src_path)?); | ||
89 | io::copy(&mut input, &mut encoder)?; | ||
90 | encoder.finish()?; | ||
76 | Ok(()) | 91 | Ok(()) |
77 | } | 92 | } |
78 | 93 | ||