Skip to content

Commit df45868

Browse files
Auto merge of #142286 - Kobzol:clippy-jemalloc, r=<try>
[experiment] Use jemalloc for Clippy The tool macros are annoying, we should IMO just get rid of them, create separate steps for each tool and (re)use some builders in them to share the build code. r? `@ghost`
2 parents 40daf23 + 0c6bbfb commit df45868

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,6 +1117,7 @@ macro_rules! tool_extended {
11171117
tool_name: $tool_name:expr,
11181118
stable: $stable:expr
11191119
$( , add_bins_to_sysroot: $add_bins_to_sysroot:expr )?
1120+
$( , add_features: $add_features:expr )?
11201121
$( , )?
11211122
}
11221123
) => {
@@ -1156,6 +1157,7 @@ macro_rules! tool_extended {
11561157
$tool_name,
11571158
$path,
11581159
None $( .or(Some(&$add_bins_to_sysroot)) )?,
1160+
None $( .or(Some($add_features)) )?,
11591161
)
11601162
}
11611163
}
@@ -1193,15 +1195,21 @@ fn run_tool_build_step(
11931195
tool_name: &'static str,
11941196
path: &'static str,
11951197
add_bins_to_sysroot: Option<&[&str]>,
1198+
add_features: Option<fn(&Builder<'_>, TargetSelection, &mut Vec<String>)>,
11961199
) -> ToolBuildResult {
1200+
let mut extra_features = Vec::new();
1201+
if let Some(func) = add_features {
1202+
func(builder, target, &mut extra_features);
1203+
}
1204+
11971205
let ToolBuildResult { tool_path, build_compiler, target_compiler } =
11981206
builder.ensure(ToolBuild {
11991207
compiler,
12001208
target,
12011209
tool: tool_name,
12021210
mode: Mode::ToolRustc,
12031211
path,
1204-
extra_features: vec![],
1212+
extra_features,
12051213
source_type: SourceType::InTree,
12061214
allow_features: "",
12071215
cargo_args: vec![],
@@ -1244,7 +1252,12 @@ tool_extended!(Clippy {
12441252
path: "src/tools/clippy",
12451253
tool_name: "clippy-driver",
12461254
stable: true,
1247-
add_bins_to_sysroot: ["clippy-driver"]
1255+
add_bins_to_sysroot: ["clippy-driver"],
1256+
add_features: |builder, target, features| {
1257+
if builder.config.jemalloc(target) {
1258+
features.push("jemalloc".to_string());
1259+
}
1260+
}
12481261
});
12491262
tool_extended!(Miri {
12501263
path: "src/tools/miri",

src/tools/clippy/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5858
[features]
5959
integration = ["dep:tempfile"]
6060
internal = ["dep:clippy_lints_internal", "dep:tempfile"]
61+
jemalloc = []
6162

6263
[package.metadata.rust-analyzer]
6364
# This package uses #[feature(rustc_private)]

src/tools/clippy/src/driver.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ extern crate rustc_interface;
1313
extern crate rustc_session;
1414
extern crate rustc_span;
1515

16+
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
17+
// about jemalloc.
18+
#[cfg(feature = "jemalloc")]
19+
extern crate tikv_jemalloc_sys as jemalloc_sys;
20+
1621
use clippy_utils::sym;
1722
use rustc_interface::interface;
1823
use rustc_session::EarlyDiagCtxt;
@@ -181,6 +186,36 @@ const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/ne
181186
#[allow(clippy::too_many_lines)]
182187
#[allow(clippy::ignored_unit_patterns)]
183188
pub fn main() {
189+
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
190+
// about jemalloc.
191+
#[cfg(feature = "jemalloc")]
192+
{
193+
use std::os::raw::{c_int, c_void};
194+
195+
#[used]
196+
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
197+
#[used]
198+
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int = jemalloc_sys::posix_memalign;
199+
#[used]
200+
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
201+
#[used]
202+
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
203+
#[used]
204+
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
205+
#[used]
206+
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
207+
208+
#[cfg(target_os = "macos")]
209+
{
210+
unsafe extern "C" {
211+
fn _rjem_je_zone_register();
212+
}
213+
214+
#[used]
215+
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
216+
}
217+
}
218+
184219
let early_dcx = EarlyDiagCtxt::new(ErrorOutputType::default());
185220

186221
rustc_driver::init_rustc_env_logger(&early_dcx);

src/tools/opt-dist/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ fn main() -> anyhow::Result<()> {
410410
"rust-docs-json",
411411
"rust-analyzer",
412412
"rustc-src",
413-
"clippy",
413+
// "clippy",
414414
"miri",
415415
"rustfmt",
416416
"gcc",

0 commit comments

Comments
 (0)