aboutsummaryrefslogtreecommitdiff
path: root/xtask/src
diff options
context:
space:
mode:
Diffstat (limited to 'xtask/src')
-rw-r--r--xtask/src/dist.rs31
-rw-r--r--xtask/src/install.rs16
-rw-r--r--xtask/src/lib.rs2
-rw-r--r--xtask/src/main.rs22
-rw-r--r--xtask/src/not_bash.rs17
-rw-r--r--xtask/src/release.rs36
6 files changed, 104 insertions, 20 deletions
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 @@
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
@@ -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
49fn dist_server(nightly: bool) -> Result<()> { 55fn 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
86fn 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
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index 9ba77a3aa..a0dc0c9c2 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -19,7 +19,13 @@ pub enum ClientOpt {
19} 19}
20 20
21pub struct ServerOpt { 21pub struct ServerOpt {
22 pub jemalloc: bool, 22 pub malloc: Malloc,
23}
24
25pub enum Malloc {
26 System,
27 Jemalloc,
28 Mimalloc,
23} 29}
24 30
25impl InstallCmd { 31impl InstallCmd {
@@ -130,8 +136,12 @@ fn install_server(opts: ServerOpt) -> Result<()> {
130 ) 136 )
131 } 137 }
132 138
133 let jemalloc = if opts.jemalloc { "--features jemalloc" } else { "" }; 139 let malloc_feature = match opts.malloc {
134 let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", jemalloc); 140 Malloc::System => "",
141 Malloc::Jemalloc => "--features jemalloc",
142 Malloc::Mimalloc => "--features mimalloc",
143 };
144 let res = run!("cargo install --path crates/rust-analyzer --locked --force {}", malloc_feature);
135 145
136 if res.is_err() && old_rust { 146 if res.is_err() && old_rust {
137 eprintln!( 147 eprintln!(
diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs
index 747654c1f..94d451e23 100644
--- a/xtask/src/lib.rs
+++ b/xtask/src/lib.rs
@@ -20,7 +20,7 @@ use walkdir::{DirEntry, WalkDir};
20 20
21use crate::{ 21use crate::{
22 codegen::Mode, 22 codegen::Mode,
23 not_bash::{fs2, pushd, pushenv, rm_rf, run}, 23 not_bash::{fs2, pushd, pushenv, rm_rf},
24}; 24};
25 25
26pub use anyhow::{bail, Context as _, Result}; 26pub use anyhow::{bail, Context as _, Result};
diff --git a/xtask/src/main.rs b/xtask/src/main.rs
index f7a79362d..399ff7204 100644
--- a/xtask/src/main.rs
+++ b/xtask/src/main.rs
@@ -14,10 +14,10 @@ use pico_args::Arguments;
14use xtask::{ 14use xtask::{
15 codegen::{self, Mode}, 15 codegen::{self, Mode},
16 dist::run_dist, 16 dist::run_dist,
17 install::{ClientOpt, InstallCmd, ServerOpt}, 17 install::{ClientOpt, InstallCmd, Malloc, ServerOpt},
18 not_bash::pushd, 18 not_bash::pushd,
19 pre_commit, project_root, 19 pre_commit, project_root,
20 release::ReleaseCmd, 20 release::{PromoteCmd, ReleaseCmd},
21 run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result, 21 run_clippy, run_fuzzer, run_pre_cache, run_rustfmt, Result,
22}; 22};
23 23
@@ -46,6 +46,7 @@ FLAGS:
46 --client-code Install only VS Code plugin 46 --client-code Install only VS Code plugin
47 --server Install only the language server 47 --server Install only the language server
48 --jemalloc Use jemalloc for server 48 --jemalloc Use jemalloc for server
49 --mimalloc Use mimalloc for server
49 -h, --help Prints help information 50 -h, --help Prints help information
50 " 51 "
51 ); 52 );
@@ -61,13 +62,21 @@ FLAGS:
61 return Ok(()); 62 return Ok(());
62 } 63 }
63 64
64 let jemalloc = args.contains("--jemalloc"); 65 let malloc = match (args.contains("--jemalloc"), args.contains("--mimalloc")) {
66 (false, false) => Malloc::System,
67 (true, false) => Malloc::Jemalloc,
68 (false, true) => Malloc::Mimalloc,
69 (true, true) => {
70 eprintln!("error: Cannot use both `--jemalloc` and `--mimalloc`");
71 return Ok(());
72 }
73 };
65 74
66 args.finish()?; 75 args.finish()?;
67 76
68 InstallCmd { 77 InstallCmd {
69 client: if server { None } else { Some(ClientOpt::VsCode) }, 78 client: if server { None } else { Some(ClientOpt::VsCode) },
70 server: if client_code { None } else { Some(ServerOpt { jemalloc }) }, 79 server: if client_code { None } else { Some(ServerOpt { malloc }) },
71 } 80 }
72 .run() 81 .run()
73 } 82 }
@@ -105,6 +114,11 @@ FLAGS:
105 args.finish()?; 114 args.finish()?;
106 ReleaseCmd { dry_run }.run() 115 ReleaseCmd { dry_run }.run()
107 } 116 }
117 "promote" => {
118 let dry_run = args.contains("--dry-run");
119 args.finish()?;
120 PromoteCmd { dry_run }.run()
121 }
108 "dist" => { 122 "dist" => {
109 let nightly = args.contains("--nightly"); 123 let nightly = args.contains("--nightly");
110 let client_version: Option<String> = args.opt_value_from_str("--client")?; 124 let client_version: Option<String> = args.opt_value_from_str("--client")?;
diff --git a/xtask/src/not_bash.rs b/xtask/src/not_bash.rs
index a6431e586..0f3a56b25 100644
--- a/xtask/src/not_bash.rs
+++ b/xtask/src/not_bash.rs
@@ -54,7 +54,8 @@ pub mod fs2 {
54 } 54 }
55} 55}
56 56
57macro_rules! _run { 57#[macro_export]
58macro_rules! run {
58 ($($expr:expr),*) => { 59 ($($expr:expr),*) => {
59 run!($($expr),*; echo = true) 60 run!($($expr),*; echo = true)
60 }; 61 };
@@ -65,7 +66,7 @@ macro_rules! _run {
65 $crate::not_bash::run_process(format!($($expr),*), false, Some($stdin)) 66 $crate::not_bash::run_process(format!($($expr),*), false, Some($stdin))
66 }; 67 };
67} 68}
68pub(crate) use _run as run; 69pub use crate::run;
69 70
70pub struct Pushd { 71pub struct Pushd {
71 _p: (), 72 _p: (),
@@ -153,7 +154,17 @@ fn run_process_inner(cmd: &str, echo: bool, stdin: Option<&[u8]>) -> Result<Stri
153 154
154// FIXME: some real shell lexing here 155// FIXME: some real shell lexing here
155fn shelx(cmd: &str) -> Vec<String> { 156fn shelx(cmd: &str) -> Vec<String> {
156 cmd.split_whitespace().map(|it| it.to_string()).collect() 157 let mut res = Vec::new();
158 for (string_piece, in_quotes) in cmd.split('\'').zip([false, true].iter().copied().cycle()) {
159 if in_quotes {
160 res.push(string_piece.to_string())
161 } else {
162 if !string_piece.is_empty() {
163 res.extend(string_piece.split_ascii_whitespace().map(|it| it.to_string()))
164 }
165 }
166 }
167 res
157} 168}
158 169
159struct Env { 170struct Env {
diff --git a/xtask/src/release.rs b/xtask/src/release.rs
index b6502b952..7fa0966aa 100644
--- a/xtask/src/release.rs
+++ b/xtask/src/release.rs
@@ -1,6 +1,6 @@
1use crate::{ 1use crate::{
2 codegen, is_release_tag, 2 codegen, is_release_tag,
3 not_bash::{date_iso, fs2, run}, 3 not_bash::{date_iso, fs2, pushd, run},
4 project_root, Mode, Result, 4 project_root, Mode, Result,
5}; 5};
6 6
@@ -37,6 +37,8 @@ Release: release:{}[]
37 37
38== Sponsors 38== Sponsors
39 39
40**Become a sponsor:** https://opencollective.com/rust-analyzer/[opencollective.com/rust-analyzer]
41
40== New Features 42== New Features
41 43
42* pr:[] . 44* pr:[] .
@@ -67,3 +69,35 @@ Release: release:{}[]
67 Ok(()) 69 Ok(())
68 } 70 }
69} 71}
72
73pub struct PromoteCmd {
74 pub dry_run: bool,
75}
76
77impl PromoteCmd {
78 pub fn run(self) -> Result<()> {
79 let _dir = pushd("../rust-rust-analyzer");
80 run!("git switch master")?;
81 run!("git fetch upstream")?;
82 run!("git reset --hard upstream/master")?;
83 run!("git submodule update --recursive")?;
84
85 let branch = format!("rust-analyzer-{}", date_iso()?);
86 run!("git switch -c {}", branch)?;
87 {
88 let _dir = pushd("src/tools/rust-analyzer");
89 run!("git fetch origin")?;
90 run!("git reset --hard origin/release")?;
91 }
92 run!("git add src/tools/rust-analyzer")?;
93 run!("git commit -m':arrow_up: rust-analyzer'")?;
94 if !self.dry_run {
95 run!("git push")?;
96 run!(
97 "xdg-open https://github.com/matklad/rust/pull/new/{}?body=r%3F%20%40ghost",
98 branch
99 )?;
100 }
101 Ok(())
102 }
103}