Skip to content
Closed
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
19 changes: 18 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,12 @@ dependencies = [
"windows-sys 0.59.0",
]

[[package]]
name = "cty"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"

[[package]]
name = "curl"
version = "0.4.49"
Expand Down Expand Up @@ -2152,6 +2158,17 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"

[[package]]
name = "libmimalloc-sys"
version = "0.1.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "667f4fec20f29dfc6bc7357c582d91796c169ad7e2fce709468aefeb2c099870"
dependencies = [
"cc",
"cty",
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this dependency is used for c_char, c_int, c_long and c_ulonglong, which are all provided by core::ffi nowadays.

Copy link
Author

Choose a reason for hiding this comment

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

@bjorn3 as this is a test, im js gonna allow the dep

"libc",
]

[[package]]
name = "libredox"
version = "0.1.9"
Expand Down Expand Up @@ -3287,13 +3304,13 @@ checksum = "e4ee29da77c5a54f42697493cd4c9b9f31b74df666a6c04dfc4fde77abe0438b"
name = "rustc-main"
version = "0.0.0"
dependencies = [
"libmimalloc-sys",
"rustc_codegen_ssa",
"rustc_driver",
"rustc_driver_impl",
"rustc_public",
"rustc_public_bridge",
"rustc_windows_rc",
"tikv-jemalloc-sys",
]

[[package]]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ rustc_public = { path = "../rustc_public" }
rustc_public_bridge = { path = "../rustc_public_bridge" }
# tidy-alphabetical-end

[dependencies.tikv-jemalloc-sys]
version = "0.6.0"
[dependencies.libmimalloc-sys]
version = "0.1.44"
optional = true
features = ['unprefixed_malloc_on_supported_platforms']
features = ["v3", "local_dynamic_tls", "arena", "extended", "override"]

[features]
# tidy-alphabetical-start
check_only = ['rustc_driver_impl/check_only']
jemalloc = ['dep:tikv-jemalloc-sys']
jemalloc = ['dep:libmimalloc-sys']
llvm = ['rustc_driver_impl/llvm']
llvm_enzyme = ['rustc_driver_impl/llvm_enzyme']
max_level_info = ['rustc_driver_impl/max_level_info']
Expand Down
20 changes: 11 additions & 9 deletions compiler/rustc/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,23 @@ fn main() {
{
use std::os::raw::{c_int, c_void};

use tikv_jemalloc_sys as jemalloc_sys;
use libmimalloc_sys as mimalloc_sys;

#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = mimalloc_sys::mi_calloc;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
mimalloc_sys::mi_posix_memalign;
#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void =
mimalloc_sys::mi_aligned_alloc;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = mimalloc_sys::mi_malloc;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void =
mimalloc_sys::mi_realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
static _F6: unsafe extern "C" fn(*mut c_void) = mimalloc_sys::mi_free;

// On OSX, jemalloc doesn't directly override malloc/free, but instead
// registers itself with the allocator's zone APIs in a ctor. However,
Expand All @@ -66,11 +68,11 @@ fn main() {
#[cfg(target_os = "macos")]
{
unsafe extern "C" {
fn _rjem_je_zone_register();
fn _mi_macos_override_malloc();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
static _F7: unsafe extern "C" fn() = _mi_macos_override_malloc;
}
}

Expand Down
20 changes: 11 additions & 9 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extern crate test;
// See docs in https://github.com/rust-lang/rust/blob/master/compiler/rustc/src/main.rs
// about jemalloc.
#[cfg(feature = "jemalloc")]
extern crate tikv_jemalloc_sys as jemalloc_sys;
extern crate libmimalloc_sys as mimalloc_sys;

use std::env::{self, VarError};
use std::io::{self, IsTerminal};
Expand Down Expand Up @@ -132,27 +132,29 @@ pub fn main() {
use std::os::raw::{c_int, c_void};

#[used]
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::calloc;
static _F1: unsafe extern "C" fn(usize, usize) -> *mut c_void = mimalloc_sys::mi_calloc;
#[used]
static _F2: unsafe extern "C" fn(*mut *mut c_void, usize, usize) -> c_int =
jemalloc_sys::posix_memalign;
mimalloc_sys::mi_posix_memalign;
#[used]
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void = jemalloc_sys::aligned_alloc;
static _F3: unsafe extern "C" fn(usize, usize) -> *mut c_void =
mimalloc_sys::mi_aligned_alloc;
#[used]
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = jemalloc_sys::malloc;
static _F4: unsafe extern "C" fn(usize) -> *mut c_void = mimalloc_sys::mi_malloc;
#[used]
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void = jemalloc_sys::realloc;
static _F5: unsafe extern "C" fn(*mut c_void, usize) -> *mut c_void =
mimalloc_sys::mi_realloc;
#[used]
static _F6: unsafe extern "C" fn(*mut c_void) = jemalloc_sys::free;
static _F6: unsafe extern "C" fn(*mut c_void) = mimalloc_sys::mi_free;

#[cfg(target_os = "macos")]
{
unsafe extern "C" {
fn _rjem_je_zone_register();
fn _mi_macos_override_malloc();
}

#[used]
static _F7: unsafe extern "C" fn() = _rjem_je_zone_register;
static _F7: unsafe extern "C" fn() = _mi_macos_override_malloc;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/tools/tidy/src/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"crossbeam-utils",
"crypto-common",
"ctrlc",
"cty", // Ideally removed.
"darling",
"darling_core",
"darling_macro",
Expand Down Expand Up @@ -399,6 +400,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"leb128",
"libc",
"libloading",
"libmimalloc-sys",
"linux-raw-sys",
"litemap",
"lock_api",
Expand Down Expand Up @@ -482,7 +484,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
"thiserror-impl",
"thorin-dwp",
"thread_local",
"tikv-jemalloc-sys",
"tinystr",
"tinyvec",
"tinyvec_macros",
Expand Down
Loading