aboutsummaryrefslogtreecommitdiff
path: root/xtask/src/dist.rs
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src/dist.rs')
-rw-r--r--xtask/src/dist.rs56
1 files changed, 38 insertions, 18 deletions
diff --git a/xtask/src/dist.rs b/xtask/src/dist.rs
index aef68089e..01d903cde 100644
--- a/xtask/src/dist.rs
+++ b/xtask/src/dist.rs
@@ -1,4 +1,10 @@
1use std::path::PathBuf; 1use flate2::{write::GzEncoder, Compression};
2use std::{
3 env,
4 fs::File,
5 io,
6 path::{Path, PathBuf},
7};
2 8
3use anyhow::Result; 9use anyhow::Result;
4 10
@@ -7,17 +13,24 @@ use crate::{
7 project_root, 13 project_root,
8}; 14};
9 15
10pub fn run_dist(nightly: bool, client_version: Option<String>) -> Result<()> { 16pub struct DistCmd {
11 let dist = project_root().join("dist"); 17 pub nightly: bool,
12 rm_rf(&dist)?; 18 pub client_version: Option<String>,
13 fs2::create_dir_all(&dist)?; 19}
20
21impl DistCmd {
22 pub fn run(self) -> Result<()> {
23 let dist = project_root().join("dist");
24 rm_rf(&dist)?;
25 fs2::create_dir_all(&dist)?;
14 26
15 if let Some(version) = client_version { 27 if let Some(version) = self.client_version {
16 let release_tag = if nightly { "nightly".to_string() } else { date_iso()? }; 28 let release_tag = if self.nightly { "nightly".to_string() } else { date_iso()? };
17 dist_client(&version, &release_tag)?; 29 dist_client(&version, &release_tag)?;
30 }
31 dist_server()?;
32 Ok(())
18 } 33 }
19 dist_server(nightly)?;
20 Ok(())
21} 34}
22 35
23fn dist_client(version: &str, release_tag: &str) -> Result<()> { 36fn dist_client(version: &str, release_tag: &str) -> Result<()> {
@@ -46,17 +59,12 @@ fn dist_client(version: &str, release_tag: &str) -> Result<()> {
46 Ok(()) 59 Ok(())
47} 60}
48 61
49fn dist_server(nightly: bool) -> Result<()> { 62fn dist_server() -> Result<()> {
50 if cfg!(target_os = "linux") { 63 if cfg!(target_os = "linux") {
51 std::env::set_var("CC", "clang"); 64 env::set_var("CC", "clang");
52 run!( 65 run!(
53 "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release" 66 "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
55 // --features=jemalloc
56 )?; 67 )?;
57 if !nightly {
58 run!("strip ./target/release/rust-analyzer")?;
59 }
60 } else { 68 } else {
61 run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?; 69 run!("cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --release")?;
62 } 70 }
@@ -71,8 +79,20 @@ fn dist_server(nightly: bool) -> Result<()> {
71 panic!("Unsupported OS") 79 panic!("Unsupported OS")
72 }; 80 };
73 81
74 fs2::copy(src, dst)?; 82 let src = Path::new(src);
83 let dst = Path::new(dst);
84
85 fs2::copy(&src, &dst)?;
86 gzip(&src, &dst.with_extension("gz"))?;
87
88 Ok(())
89}
75 90
91fn gzip(src_path: &Path, dest_path: &Path) -> Result<()> {
92 let mut encoder = GzEncoder::new(File::create(dest_path)?, Compression::best());
93 let mut input = io::BufReader::new(File::open(src_path)?);
94 io::copy(&mut input, &mut encoder)?;
95 encoder.finish()?;
76 Ok(()) 96 Ok(())
77} 97}
78 98