Skip to content

Commit 9b79fa2

Browse files
committed
Auto merge of rust-lang#16930 - lnicola:dist-malloc, r=Veykril
internal: Support choosing the allocator in `xtask dist`
2 parents dacfa72 + f6b9cff commit 9b79fa2

File tree

4 files changed

+110
-71
lines changed

4 files changed

+110
-71
lines changed

crates/rust-analyzer/src/cli/flags.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ pub struct RunTests {
235235
#[derive(Debug)]
236236
pub struct RustcTests {
237237
pub rustc_repo: PathBuf,
238+
238239
pub filter: Option<String>,
239240
}
240241

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: 90 additions & 53 deletions
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.
@@ -81,35 +85,6 @@ pub enum XtaskCmd {
8185
Codegen(Codegen),
8286
}
8387

84-
#[derive(Debug)]
85-
pub struct Codegen {
86-
pub check: bool,
87-
pub codegen_type: Option<CodegenType>,
88-
}
89-
90-
#[derive(Debug, Default)]
91-
pub enum CodegenType {
92-
#[default]
93-
All,
94-
Grammar,
95-
AssistsDocTests,
96-
DiagnosticsDocs,
97-
LintDefinitions,
98-
}
99-
100-
impl FromStr for CodegenType {
101-
type Err = String;
102-
fn from_str(s: &str) -> Result<Self, Self::Err> {
103-
match s {
104-
"all" => Ok(Self::All),
105-
"grammar" => Ok(Self::Grammar),
106-
"assists-doc-tests" => Ok(Self::AssistsDocTests),
107-
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
108-
"lints-definitions" => Ok(Self::LintDefinitions),
109-
_ => Err("Invalid option".to_owned()),
110-
}
111-
}
112-
}
11388
#[derive(Debug)]
11489
pub struct Install {
11590
pub client: bool,
@@ -135,6 +110,8 @@ pub struct Promote {
135110

136111
#[derive(Debug)]
137112
pub struct Dist {
113+
pub mimalloc: bool,
114+
pub jemalloc: bool,
138115
pub client_patch_version: Option<String>,
139116
}
140117

@@ -145,6 +122,65 @@ pub struct PublishReleaseNotes {
145122
pub dry_run: bool,
146123
}
147124

125+
#[derive(Debug)]
126+
pub struct Metrics {
127+
pub measurement_type: Option<MeasurementType>,
128+
}
129+
130+
#[derive(Debug)]
131+
pub struct Bb {
132+
pub suffix: String,
133+
}
134+
135+
#[derive(Debug)]
136+
pub struct Codegen {
137+
pub codegen_type: Option<CodegenType>,
138+
139+
pub check: bool,
140+
}
141+
142+
impl Xtask {
143+
#[allow(dead_code)]
144+
pub fn from_env_or_exit() -> Self {
145+
Self::from_env_or_exit_()
146+
}
147+
148+
#[allow(dead_code)]
149+
pub fn from_env() -> xflags::Result<Self> {
150+
Self::from_env_()
151+
}
152+
153+
#[allow(dead_code)]
154+
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
155+
Self::from_vec_(args)
156+
}
157+
}
158+
// generated end
159+
160+
#[derive(Debug, Default)]
161+
pub enum CodegenType {
162+
#[default]
163+
All,
164+
Grammar,
165+
AssistsDocTests,
166+
DiagnosticsDocs,
167+
LintDefinitions,
168+
}
169+
170+
impl FromStr for CodegenType {
171+
type Err = String;
172+
fn from_str(s: &str) -> Result<Self, Self::Err> {
173+
match s {
174+
"all" => Ok(Self::All),
175+
"grammar" => Ok(Self::Grammar),
176+
"assists-doc-tests" => Ok(Self::AssistsDocTests),
177+
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
178+
"lints-definitions" => Ok(Self::LintDefinitions),
179+
_ => Err("Invalid option".to_owned()),
180+
}
181+
}
182+
}
183+
148184
#[derive(Debug)]
149185
pub enum MeasurementType {
150186
Build,
@@ -185,33 +221,22 @@ impl AsRef<str> for MeasurementType {
185221
}
186222
}
187223

188-
#[derive(Debug)]
189-
pub struct Metrics {
190-
pub measurement_type: Option<MeasurementType>,
191-
}
192-
193-
#[derive(Debug)]
194-
pub struct Bb {
195-
pub suffix: String,
224+
#[derive(Clone, Copy, Debug)]
225+
pub(crate) enum Malloc {
226+
System,
227+
Mimalloc,
228+
Jemalloc,
196229
}
197230

198-
impl Xtask {
199-
#[allow(dead_code)]
200-
pub fn from_env_or_exit() -> Self {
201-
Self::from_env_or_exit_()
202-
}
203-
204-
#[allow(dead_code)]
205-
pub fn from_env() -> xflags::Result<Self> {
206-
Self::from_env_()
207-
}
208-
209-
#[allow(dead_code)]
210-
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
211-
Self::from_vec_(args)
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+
}
212238
}
213239
}
214-
// generated end
215240

216241
impl Install {
217242
pub(crate) fn server(&self) -> Option<ServerOpt> {
@@ -234,3 +259,15 @@ impl Install {
234259
Some(ClientOpt { code_bin: self.code_bin.clone() })
235260
}
236261
}
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)