From e9bba4f598c423125d3608effcfd2fd026b460ef Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Thu, 16 Oct 2025 13:08:27 +0300 Subject: [PATCH] Do not use `force-always-assert` in `xtask install` by default But add a flag to do so. --- src/tools/rust-analyzer/xtask/src/flags.rs | 11 ++++++++++- src/tools/rust-analyzer/xtask/src/install.rs | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/tools/rust-analyzer/xtask/src/flags.rs b/src/tools/rust-analyzer/xtask/src/flags.rs index 72f6215d4c3f..8f70a1861893 100644 --- a/src/tools/rust-analyzer/xtask/src/flags.rs +++ b/src/tools/rust-analyzer/xtask/src/flags.rs @@ -49,6 +49,9 @@ xflags::xflags! { /// build in release with debug info set to 2. optional --dev-rel + /// Make `never!()`, `always!()` etc. panic instead of just logging an error. + optional --force-always-assert + /// Apply PGO optimizations optional --pgo pgo: PgoTrainingCrate } @@ -124,6 +127,7 @@ pub struct Install { pub jemalloc: bool, pub proc_macro_server: bool, pub dev_rel: bool, + pub force_always_assert: bool, pub pgo: Option, } @@ -300,7 +304,12 @@ impl Install { } else { Malloc::System }; - Some(ServerOpt { malloc, dev_rel: self.dev_rel, pgo: self.pgo.clone() }) + Some(ServerOpt { + malloc, + dev_rel: self.dev_rel, + pgo: self.pgo.clone(), + force_always_assert: self.force_always_assert, + }) } pub(crate) fn proc_macro_server(&self) -> Option { if !self.proc_macro_server { diff --git a/src/tools/rust-analyzer/xtask/src/install.rs b/src/tools/rust-analyzer/xtask/src/install.rs index b794f53e761e..975e361ba50b 100644 --- a/src/tools/rust-analyzer/xtask/src/install.rs +++ b/src/tools/rust-analyzer/xtask/src/install.rs @@ -39,6 +39,18 @@ pub(crate) struct ServerOpt { pub(crate) malloc: Malloc, pub(crate) dev_rel: bool, pub(crate) pgo: Option, + pub(crate) force_always_assert: bool, +} + +impl ServerOpt { + fn to_features(&self) -> Vec<&'static str> { + let mut features = Vec::new(); + features.extend(self.malloc.to_features()); + if self.force_always_assert { + features.extend(["--features", "force-always-assert"]); + } + features + } } pub(crate) struct ProcMacroServerOpt { @@ -136,7 +148,7 @@ fn install_client(sh: &Shell, client_opt: ClientOpt) -> anyhow::Result<()> { } fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> { - let features = opts.malloc.to_features(); + let features = &opts.to_features(); let profile = if opts.dev_rel { "dev-rel" } else { "release" }; let mut install_cmd = cmd!( @@ -148,7 +160,7 @@ fn install_server(sh: &Shell, opts: ServerOpt) -> anyhow::Result<()> { let target = detect_target(sh); let build_cmd = cmd!( sh, - "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --profile={profile} --locked --features force-always-assert {features...}" + "cargo build --manifest-path ./crates/rust-analyzer/Cargo.toml --bin rust-analyzer --target {target} --profile={profile} --locked {features...}" ); let profile = crate::pgo::gather_pgo_profile(sh, build_cmd, &target, train_crate)?;