Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f6b9cff

Browse files
committed
Support choosing the allocator in xtask dist
1 parent 84d38c7 commit f6b9cff

File tree

3 files changed

+55
-19
lines changed

3 files changed

+55
-19
lines changed

xtask/src/dist.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ use time::OffsetDateTime;
1010
use xshell::{cmd, Shell};
1111
use zip::{write::FileOptions, DateTime, ZipWriter};
1212

13-
use crate::{date_iso, flags, project_root};
13+
use crate::{
14+
date_iso,
15+
flags::{self, Malloc},
16+
project_root,
17+
};
1418

1519
const VERSION_STABLE: &str = "0.3";
1620
const VERSION_NIGHTLY: &str = "0.4";
@@ -22,6 +26,7 @@ impl flags::Dist {
2226

2327
let project_root = project_root();
2428
let target = Target::get(&project_root);
29+
let allocator = self.allocator();
2530
let dist = project_root.join("dist");
2631
sh.remove_path(&dist)?;
2732
sh.create_dir(&dist)?;
@@ -33,11 +38,11 @@ impl flags::Dist {
3338
// A hack to make VS Code prefer nightly over stable.
3439
format!("{VERSION_NIGHTLY}.{patch_version}")
3540
};
36-
dist_server(sh, &format!("{version}-standalone"), &target)?;
41+
dist_server(sh, &format!("{version}-standalone"), &target, allocator)?;
3742
let release_tag = if stable { date_iso(sh)? } else { "nightly".to_owned() };
3843
dist_client(sh, &version, &release_tag, &target)?;
3944
} else {
40-
dist_server(sh, "0.0.0-standalone", &target)?;
45+
dist_server(sh, "0.0.0-standalone", &target, allocator)?;
4146
}
4247
Ok(())
4348
}
@@ -73,7 +78,12 @@ fn dist_client(
7378
Ok(())
7479
}
7580

76-
fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()> {
81+
fn dist_server(
82+
sh: &Shell,
83+
release: &str,
84+
target: &Target,
85+
allocator: Malloc,
86+
) -> anyhow::Result<()> {
7787
let _e = sh.push_env("CFG_RELEASE", release);
7888
let _e = sh.push_env("CARGO_PROFILE_RELEASE_LTO", "thin");
7989

@@ -87,7 +97,8 @@ fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()>
8797
}
8898

8999
let target_name = &target.name;
90-
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
100+
let features = allocator.to_features();
101+
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
91102

92103
let dst = Path::new("dist").join(&target.artifact_name);
93104
gzip(&target.server_path, &dst.with_extension("gz"))?;

xtask/src/flags.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::str::FromStr;
44

5-
use crate::install::{ClientOpt, Malloc, ServerOpt};
5+
use crate::install::{ClientOpt, ServerOpt};
66

77
xflags::xflags! {
88
src "./src/flags.rs"
@@ -36,6 +36,10 @@ xflags::xflags! {
3636
optional --dry-run
3737
}
3838
cmd dist {
39+
/// Use mimalloc allocator for server
40+
optional --mimalloc
41+
/// Use jemalloc allocator for server
42+
optional --jemalloc
3943
optional --client-patch-version version: String
4044
}
4145
/// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
@@ -106,6 +110,8 @@ pub struct Promote {
106110

107111
#[derive(Debug)]
108112
pub struct Dist {
113+
pub mimalloc: bool,
114+
pub jemalloc: bool,
109115
pub client_patch_version: Option<String>,
110116
}
111117

@@ -215,6 +221,23 @@ impl AsRef<str> for MeasurementType {
215221
}
216222
}
217223

224+
#[derive(Clone, Copy, Debug)]
225+
pub(crate) enum Malloc {
226+
System,
227+
Mimalloc,
228+
Jemalloc,
229+
}
230+
231+
impl Malloc {
232+
pub(crate) fn to_features(self) -> &'static [&'static str] {
233+
match self {
234+
Malloc::System => &[][..],
235+
Malloc::Mimalloc => &["--features", "mimalloc"],
236+
Malloc::Jemalloc => &["--features", "jemalloc"],
237+
}
238+
}
239+
}
240+
218241
impl Install {
219242
pub(crate) fn server(&self) -> Option<ServerOpt> {
220243
if self.client && !self.server {
@@ -236,3 +259,15 @@ impl Install {
236259
Some(ClientOpt { code_bin: self.code_bin.clone() })
237260
}
238261
}
262+
263+
impl Dist {
264+
pub(crate) fn allocator(&self) -> Malloc {
265+
if self.mimalloc {
266+
Malloc::Mimalloc
267+
} else if self.jemalloc {
268+
Malloc::Jemalloc
269+
} else {
270+
Malloc::System
271+
}
272+
}
273+
}

xtask/src/install.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{env, path::PathBuf, str};
55
use anyhow::{bail, format_err, Context};
66
use xshell::{cmd, Shell};
77

8-
use crate::flags;
8+
use crate::flags::{self, Malloc};
99

1010
impl flags::Install {
1111
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
@@ -34,12 +34,6 @@ pub(crate) struct ServerOpt {
3434
pub(crate) dev_rel: bool,
3535
}
3636

37-
pub(crate) enum Malloc {
38-
System,
39-
Mimalloc,
40-
Jemalloc,
41-
}
42-
4337
fn fix_path_for_mac(sh: &Shell) -> anyhow::Result<()> {
4438
let mut vscode_path: Vec<PathBuf> = {
4539
const COMMON_APP_PATH: &str =
@@ -122,7 +116,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> {
122116
if !installed_extensions.contains("rust-analyzer") {
123117
bail!(
124118
"Could not install the Visual Studio Code extension. \
125-
Please make sure you have at least NodeJS 12.x together with the latest version of VS Code installed and try again. \
119+
Please make sure you have at least NodeJS 16.x together with the latest version of VS Code installed and try again. \
126120
Note that installing via xtask install does not work for VS Code Remote, instead you’ll need to install the .vsix manually."
127121
);
128122
}
@@ -131,11 +125,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> {
131125
}
132126

133127
fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> {
134-
let features = match opts.malloc {
135-
Malloc::System => &[][..],
136-
Malloc::Mimalloc => &["--features", "mimalloc"],
137-
Malloc::Jemalloc => &["--features", "jemalloc"],
138-
};
128+
let features = opts.malloc.to_features();
139129
let profile = if opts.dev_rel { "dev-rel" } else { "release" };
140130

141131
let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --profile={profile} --locked --force --features force-always-assert {features...}");

0 commit comments

Comments
 (0)