Skip to content

Commit 522e47f

Browse files
committed
miri: use tikv-jemalloc-sys from sysroot
This allows LTO to work when compiling jemalloc, which should yield a small performance boost, and makes miri's behaviour here match clippy and rustdoc.
1 parent c23ed3e commit 522e47f

File tree

4 files changed

+13
-11
lines changed

4 files changed

+13
-11
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,6 @@ dependencies = [
24862486
"serde_json",
24872487
"smallvec",
24882488
"tempfile",
2489-
"tikv-jemalloc-sys",
24902489
"ui_test",
24912490
]
24922491

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,11 @@ tool_rustc_extended!(Miri {
15671567
tool_name: "miri",
15681568
stable: false,
15691569
add_bins_to_sysroot: ["miri"],
1570+
add_features: |builder, target, features| {
1571+
if builder.config.jemalloc(target) {
1572+
features.push("jemalloc".to_string());
1573+
}
1574+
},
15701575
// Always compile also tests when building miri. Otherwise feature unification can cause rebuilds between building and testing miri.
15711576
cargo_args: &["--all-targets"],
15721577
});

src/tools/miri/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@ directories = "6"
2929
bitflags = "2.6"
3030
serde_json = { version = "1.0", optional = true }
3131

32-
# Copied from `compiler/rustc/Cargo.toml`.
33-
# But only for some targets, it fails for others. Rustc configures this in its CI, but we can't
34-
# easily use that since we support of-tree builds.
35-
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys]
36-
version = "0.6.1"
37-
features = ['override_allocator_on_supported_platforms']
38-
3932
[target.'cfg(unix)'.dependencies]
4033
libc = "0.2"
4134
# native-lib dependencies
@@ -75,6 +68,7 @@ stack-cache = []
7568
expensive-consistency-checks = ["stack-cache"]
7669
tracing = ["serde_json"]
7770
native-lib = ["dep:libffi", "dep:libloading", "dep:capstone", "dep:ipc-channel", "dep:nix", "dep:serde"]
71+
jemalloc = []
7872

7973
[lints.rust.unexpected_cfgs]
8074
level = "warn"

src/tools/miri/src/bin/miri.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ extern crate rustc_session;
2121
extern crate rustc_span;
2222

2323
/// See docs in https://github.com/rust-lang/rust/blob/HEAD/compiler/rustc/src/main.rs
24-
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this `use` statement.
25-
#[cfg(any(target_os = "linux", target_os = "macos"))]
26-
use tikv_jemalloc_sys as _;
24+
/// and https://github.com/rust-lang/rust/pull/146627 for why we need this.
25+
///
26+
/// FIXME(madsmtm): This is loaded from the sysroot that was built with the other `rustc` crates
27+
/// above, instead of via Cargo as you'd normally do. This is currently needed for LTO due to
28+
/// https://github.com/rust-lang/cc-rs/issues/1613.
29+
#[cfg(feature = "jemalloc")]
30+
extern crate tikv_jemalloc_sys as _;
2731

2832
mod log;
2933

0 commit comments

Comments
 (0)