Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2486,7 +2486,6 @@ dependencies = [
"serde_json",
"smallvec",
"tempfile",
"tikv-jemalloc-sys",
"ui_test",
]

Expand Down
5 changes: 5 additions & 0 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,11 @@ tool_rustc_extended!(Miri {
tool_name: "miri",
stable: false,
add_bins_to_sysroot: ["miri"],
add_features: |builder, target, features| {
if builder.config.jemalloc(target) {
features.push("jemalloc".to_string());
}
},
// Always compile also tests when building miri. Otherwise feature unification can cause rebuilds between building and testing miri.
cargo_args: &["--all-targets"],
});
Expand Down
8 changes: 1 addition & 7 deletions src/tools/miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ directories = "6"
bitflags = "2.6"
serde_json = { version = "1.0", optional = true }

# Copied from `compiler/rustc/Cargo.toml`.
# But only for some targets, it fails for others. Rustc configures this in its CI, but we can't
# easily use that since we support of-tree builds.
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies.tikv-jemalloc-sys]
version = "0.6.1"
features = ['override_allocator_on_supported_platforms']

[target.'cfg(unix)'.dependencies]
libc = "0.2"
# native-lib dependencies
Expand Down Expand Up @@ -75,6 +68,7 @@ stack-cache = []
expensive-consistency-checks = ["stack-cache"]
tracing = ["serde_json"]
native-lib = ["dep:libffi", "dep:libloading", "dep:capstone", "dep:ipc-channel", "dep:nix", "dep:serde"]
jemalloc = []

[lints.rust.unexpected_cfgs]
level = "warn"
Expand Down
10 changes: 7 additions & 3 deletions src/tools/miri/src/bin/miri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ extern crate rustc_session;
extern crate rustc_span;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also saves the time for building jemalloc again so that seems nice 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, though that's also the case for a bunch of other common dependencies like serde, libc, regex etc. If this is actually a concern, we should work on a way to share dependencies across the board instead.

Copy link
Member

@RalfJung RalfJung Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tikv-jemalloc has a build script building C dependencies, making it super slow for check builds. That makes it a more worthwhile goal for this than pure Rust crates. Also the allocator is a global singleton after all so using exactly the rustc setup IMO makes a lot of sense.

#[cfg(feature = "jemalloc")]
extern crate tikv_jemalloc_sys as _;

mod log;

Expand Down
Loading