Skip to content

Commit 18491d5

Browse files
committed
Auto merge of #142286 - Kobzol:clippy-jemalloc, r=flip1995,blyxyas
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 5b74275 + 723dae8 commit 18491d5

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ macro_rules! tool_extended {
11291129
tool_name: $tool_name:expr,
11301130
stable: $stable:expr
11311131
$( , add_bins_to_sysroot: $add_bins_to_sysroot:expr )?
1132+
$( , add_features: $add_features:expr )?
11321133
$( , )?
11331134
}
11341135
) => {
@@ -1168,6 +1169,7 @@ macro_rules! tool_extended {
11681169
$tool_name,
11691170
$path,
11701171
None $( .or(Some(&$add_bins_to_sysroot)) )?,
1172+
None $( .or(Some($add_features)) )?,
11711173
)
11721174
}
11731175
}
@@ -1205,15 +1207,21 @@ fn run_tool_build_step(
12051207
tool_name: &'static str,
12061208
path: &'static str,
12071209
add_bins_to_sysroot: Option<&[&str]>,
1210+
add_features: Option<fn(&Builder<'_>, TargetSelection, &mut Vec<String>)>,
12081211
) -> ToolBuildResult {
1212+
let mut extra_features = Vec::new();
1213+
if let Some(func) = add_features {
1214+
func(builder, target, &mut extra_features);
1215+
}
1216+
12091217
let ToolBuildResult { tool_path, build_compiler, target_compiler } =
12101218
builder.ensure(ToolBuild {
12111219
compiler,
12121220
target,
12131221
tool: tool_name,
12141222
mode: Mode::ToolRustc,
12151223
path,
1216-
extra_features: vec![],
1224+
extra_features,
12171225
source_type: SourceType::InTree,
12181226
allow_features: "",
12191227
cargo_args: vec![],
@@ -1256,7 +1264,12 @@ tool_extended!(Clippy {
12561264
path: "src/tools/clippy",
12571265
tool_name: "clippy-driver",
12581266
stable: true,
1259-
add_bins_to_sysroot: ["clippy-driver"]
1267+
add_bins_to_sysroot: ["clippy-driver"],
1268+
add_features: |builder, target, features| {
1269+
if builder.config.jemalloc(target) {
1270+
features.push("jemalloc".to_string());
1271+
}
1272+
}
12601273
});
12611274
tool_extended!(Miri {
12621275
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);

0 commit comments

Comments
 (0)