Auto merge of #16930 - lnicola:dist-malloc, r=Veykril
internal: Support choosing the allocator in `xtask dist`
This commit is contained in:
commit
9b79fa2393
@ -235,6 +235,7 @@ pub struct RunTests {
|
||||
#[derive(Debug)]
|
||||
pub struct RustcTests {
|
||||
pub rustc_repo: PathBuf,
|
||||
|
||||
pub filter: Option<String>,
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,11 @@
|
||||
use xshell::{cmd, Shell};
|
||||
use zip::{write::FileOptions, DateTime, ZipWriter};
|
||||
|
||||
use crate::{date_iso, flags, project_root};
|
||||
use crate::{
|
||||
date_iso,
|
||||
flags::{self, Malloc},
|
||||
project_root,
|
||||
};
|
||||
|
||||
const VERSION_STABLE: &str = "0.3";
|
||||
const VERSION_NIGHTLY: &str = "0.4";
|
||||
@ -22,6 +26,7 @@ pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
|
||||
|
||||
let project_root = project_root();
|
||||
let target = Target::get(&project_root);
|
||||
let allocator = self.allocator();
|
||||
let dist = project_root.join("dist");
|
||||
sh.remove_path(&dist)?;
|
||||
sh.create_dir(&dist)?;
|
||||
@ -33,11 +38,11 @@ pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
|
||||
// A hack to make VS Code prefer nightly over stable.
|
||||
format!("{VERSION_NIGHTLY}.{patch_version}")
|
||||
};
|
||||
dist_server(sh, &format!("{version}-standalone"), &target)?;
|
||||
dist_server(sh, &format!("{version}-standalone"), &target, allocator)?;
|
||||
let release_tag = if stable { date_iso(sh)? } else { "nightly".to_owned() };
|
||||
dist_client(sh, &version, &release_tag, &target)?;
|
||||
} else {
|
||||
dist_server(sh, "0.0.0-standalone", &target)?;
|
||||
dist_server(sh, "0.0.0-standalone", &target, allocator)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -73,7 +78,12 @@ fn dist_client(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()> {
|
||||
fn dist_server(
|
||||
sh: &Shell,
|
||||
release: &str,
|
||||
target: &Target,
|
||||
allocator: Malloc,
|
||||
) -> anyhow::Result<()> {
|
||||
let _e = sh.push_env("CFG_RELEASE", release);
|
||||
let _e = sh.push_env("CARGO_PROFILE_RELEASE_LTO", "thin");
|
||||
|
||||
@ -87,7 +97,8 @@ fn dist_server(sh: &Shell, release: &str, target: &Target) -> anyhow::Result<()>
|
||||
}
|
||||
|
||||
let target_name = &target.name;
|
||||
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} --release").run()?;
|
||||
let features = allocator.to_features();
|
||||
cmd!(sh, "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target_name} {features...} --release").run()?;
|
||||
|
||||
let dst = Path::new("dist").join(&target.artifact_name);
|
||||
gzip(&target.server_path, &dst.with_extension("gz"))?;
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
|
||||
use crate::install::{ClientOpt, Malloc, ServerOpt};
|
||||
use crate::install::{ClientOpt, ServerOpt};
|
||||
|
||||
xflags::xflags! {
|
||||
src "./src/flags.rs"
|
||||
@ -36,6 +36,10 @@
|
||||
optional --dry-run
|
||||
}
|
||||
cmd dist {
|
||||
/// Use mimalloc allocator for server
|
||||
optional --mimalloc
|
||||
/// Use jemalloc allocator for server
|
||||
optional --jemalloc
|
||||
optional --client-patch-version version: String
|
||||
}
|
||||
/// Read a changelog AsciiDoc file and update the GitHub Releases entry in Markdown.
|
||||
@ -81,35 +85,6 @@ pub enum XtaskCmd {
|
||||
Codegen(Codegen),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Codegen {
|
||||
pub check: bool,
|
||||
pub codegen_type: Option<CodegenType>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub enum CodegenType {
|
||||
#[default]
|
||||
All,
|
||||
Grammar,
|
||||
AssistsDocTests,
|
||||
DiagnosticsDocs,
|
||||
LintDefinitions,
|
||||
}
|
||||
|
||||
impl FromStr for CodegenType {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"all" => Ok(Self::All),
|
||||
"grammar" => Ok(Self::Grammar),
|
||||
"assists-doc-tests" => Ok(Self::AssistsDocTests),
|
||||
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
|
||||
"lints-definitions" => Ok(Self::LintDefinitions),
|
||||
_ => Err("Invalid option".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Debug)]
|
||||
pub struct Install {
|
||||
pub client: bool,
|
||||
@ -135,6 +110,8 @@ pub struct Promote {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Dist {
|
||||
pub mimalloc: bool,
|
||||
pub jemalloc: bool,
|
||||
pub client_patch_version: Option<String>,
|
||||
}
|
||||
|
||||
@ -145,6 +122,65 @@ pub struct PublishReleaseNotes {
|
||||
pub dry_run: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Metrics {
|
||||
pub measurement_type: Option<MeasurementType>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Bb {
|
||||
pub suffix: String,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Codegen {
|
||||
pub codegen_type: Option<CodegenType>,
|
||||
|
||||
pub check: bool,
|
||||
}
|
||||
|
||||
impl Xtask {
|
||||
#[allow(dead_code)]
|
||||
pub fn from_env_or_exit() -> Self {
|
||||
Self::from_env_or_exit_()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_env() -> xflags::Result<Self> {
|
||||
Self::from_env_()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
|
||||
Self::from_vec_(args)
|
||||
}
|
||||
}
|
||||
// generated end
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub enum CodegenType {
|
||||
#[default]
|
||||
All,
|
||||
Grammar,
|
||||
AssistsDocTests,
|
||||
DiagnosticsDocs,
|
||||
LintDefinitions,
|
||||
}
|
||||
|
||||
impl FromStr for CodegenType {
|
||||
type Err = String;
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"all" => Ok(Self::All),
|
||||
"grammar" => Ok(Self::Grammar),
|
||||
"assists-doc-tests" => Ok(Self::AssistsDocTests),
|
||||
"diagnostics-docs" => Ok(Self::DiagnosticsDocs),
|
||||
"lints-definitions" => Ok(Self::LintDefinitions),
|
||||
_ => Err("Invalid option".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum MeasurementType {
|
||||
Build,
|
||||
@ -185,33 +221,22 @@ fn as_ref(&self) -> &str {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Metrics {
|
||||
pub measurement_type: Option<MeasurementType>,
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) enum Malloc {
|
||||
System,
|
||||
Mimalloc,
|
||||
Jemalloc,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Bb {
|
||||
pub suffix: String,
|
||||
}
|
||||
|
||||
impl Xtask {
|
||||
#[allow(dead_code)]
|
||||
pub fn from_env_or_exit() -> Self {
|
||||
Self::from_env_or_exit_()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_env() -> xflags::Result<Self> {
|
||||
Self::from_env_()
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn from_vec(args: Vec<std::ffi::OsString>) -> xflags::Result<Self> {
|
||||
Self::from_vec_(args)
|
||||
impl Malloc {
|
||||
pub(crate) fn to_features(self) -> &'static [&'static str] {
|
||||
match self {
|
||||
Malloc::System => &[][..],
|
||||
Malloc::Mimalloc => &["--features", "mimalloc"],
|
||||
Malloc::Jemalloc => &["--features", "jemalloc"],
|
||||
}
|
||||
}
|
||||
}
|
||||
// generated end
|
||||
|
||||
impl Install {
|
||||
pub(crate) fn server(&self) -> Option<ServerOpt> {
|
||||
@ -234,3 +259,15 @@ pub(crate) fn client(&self) -> Option<ClientOpt> {
|
||||
Some(ClientOpt { code_bin: self.code_bin.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
impl Dist {
|
||||
pub(crate) fn allocator(&self) -> Malloc {
|
||||
if self.mimalloc {
|
||||
Malloc::Mimalloc
|
||||
} else if self.jemalloc {
|
||||
Malloc::Jemalloc
|
||||
} else {
|
||||
Malloc::System
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
use anyhow::{bail, format_err, Context};
|
||||
use xshell::{cmd, Shell};
|
||||
|
||||
use crate::flags;
|
||||
use crate::flags::{self, Malloc};
|
||||
|
||||
impl flags::Install {
|
||||
pub(crate) fn run(self, sh: &Shell) -> anyhow::Result<()> {
|
||||
@ -34,12 +34,6 @@ pub(crate) struct ServerOpt {
|
||||
pub(crate) dev_rel: bool,
|
||||
}
|
||||
|
||||
pub(crate) enum Malloc {
|
||||
System,
|
||||
Mimalloc,
|
||||
Jemalloc,
|
||||
}
|
||||
|
||||
fn fix_path_for_mac(sh: &Shell) -> anyhow::Result<()> {
|
||||
let mut vscode_path: Vec<PathBuf> = {
|
||||
const COMMON_APP_PATH: &str =
|
||||
@ -122,7 +116,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> {
|
||||
if !installed_extensions.contains("rust-analyzer") {
|
||||
bail!(
|
||||
"Could not install the Visual Studio Code extension. \
|
||||
Please make sure you have at least NodeJS 12.x together with the latest version of VS Code installed and try again. \
|
||||
Please make sure you have at least NodeJS 16.x together with the latest version of VS Code installed and try again. \
|
||||
Note that installing via xtask install does not work for VS Code Remote, instead you’ll need to install the .vsix manually."
|
||||
);
|
||||
}
|
||||
@ -131,11 +125,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> {
|
||||
let features = match opts.malloc {
|
||||
Malloc::System => &[][..],
|
||||
Malloc::Mimalloc => &["--features", "mimalloc"],
|
||||
Malloc::Jemalloc => &["--features", "jemalloc"],
|
||||
};
|
||||
let features = opts.malloc.to_features();
|
||||
let profile = if opts.dev_rel { "dev-rel" } else { "release" };
|
||||
|
||||
let cmd = cmd!(sh, "cargo install --path crates/rust-analyzer --profile={profile} --locked --force --features force-always-assert {features...}");
|
||||
|
Loading…
Reference in New Issue
Block a user