From fe724585ae01abb2f83cdf912b181d562a916bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Tue, 5 Jul 2022 23:10:57 +1200 Subject: [PATCH 1/4] Use mimalloc on windows --- Cargo.toml | 3 +++ src/main.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index a4fe8f59..09282d9c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,9 @@ zstd = { version = "0.10.0", features = ["bindgen", "zstdmt"], default-features [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] guess_host_triple = "0.1.3" +[target.'cfg(windows)'.dependencies] +mimalloc = "0.1.29" + [dev-dependencies] env_logger = "0.9.0" diff --git a/src/main.rs b/src/main.rs index 506cc478..7a02617e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,6 +25,10 @@ use cargo_binstall::{ *, }; +#[cfg(windows)] +#[global_allocator] +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; + #[derive(Debug, Parser)] #[clap(version, about = "Install a Rust binary... from binaries!")] struct Options { From 57c6125fc1008b6fe516ca9ab0de8bb465d3b127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Saparelli?= Date: Tue, 5 Jul 2022 23:56:30 +1200 Subject: [PATCH 2/4] Update Cargo.toml Co-authored-by: Jiahao XU --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 09282d9c..89e2e47b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -69,7 +69,7 @@ zstd = { version = "0.10.0", features = ["bindgen", "zstdmt"], default-features guess_host_triple = "0.1.3" [target.'cfg(windows)'.dependencies] -mimalloc = "0.1.29" +mimalloc = { version = "0.1.29", default-features = false} [dev-dependencies] env_logger = "0.9.0" From e66dc60867758bc7468a9baa001f56b0b663be04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 6 Jul 2022 00:32:13 +1200 Subject: [PATCH 3/4] Also use mimalloc on musl --- Cargo.lock | 19 +++++++++++++++++++ Cargo.toml | 8 ++++++-- src/main.rs | 2 +- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2ac84473..7dfe4034 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -146,6 +146,7 @@ dependencies = [ "home", "log", "miette", + "mimalloc", "once_cell", "reqwest", "scopeguard", @@ -778,6 +779,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "libmimalloc-sys" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11ca136052550448f55df7898c6dbe651c6b574fe38a0d9ea687a9f8088a2e2c" +dependencies = [ + "cc", +] + [[package]] name = "libz-ng-sys" version = "1.1.8" @@ -850,6 +860,15 @@ dependencies = [ "syn", ] +[[package]] +name = "mimalloc" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f64ad83c969af2e732e907564deb0d0ed393cec4af80776f77dd77a1a427698" +dependencies = [ + "libmimalloc-sys", +] + [[package]] name = "mime" version = "0.3.16" diff --git a/Cargo.toml b/Cargo.toml index 89e2e47b..66fb5592 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,8 +68,12 @@ zstd = { version = "0.10.0", features = ["bindgen", "zstdmt"], default-features [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] guess_host_triple = "0.1.3" -[target.'cfg(windows)'.dependencies] -mimalloc = { version = "0.1.29", default-features = false} +[target.'cfg(any(windows, target_env = "musl"))'.dependencies] +mimalloc = { version = "0.1.29", default-features = false, optional = true } + +[features] +default = [] +mimalloc = ["dep:mimalloc"] [dev-dependencies] env_logger = "0.9.0" diff --git a/src/main.rs b/src/main.rs index 7a02617e..882e90f4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use cargo_binstall::{ *, }; -#[cfg(windows)] +#[cfg(all(feature = "mimalloc", any(windows, target_env = "musl")))] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; From 63afa5b7911bbd178e62bc6f2258048ea8087bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Wed, 6 Jul 2022 23:33:51 +1200 Subject: [PATCH 4/4] Just hide mimalloc behind a feature, available for all platforms --- Cargo.toml | 4 +--- src/main.rs | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 66fb5592..3a063dce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,6 +31,7 @@ futures-util = { version = "0.3.21", default-features = false } home = "0.5.3" log = "0.4.14" miette = { version = "5.1.0", features = ["fancy-no-backtrace"] } +mimalloc = { version = "0.1.29", default-features = false, optional = true } once_cell = "1.12.0" reqwest = { version = "0.11.11", features = ["rustls-tls", "stream"], default-features = false } scopeguard = "1.1.0" @@ -68,9 +69,6 @@ zstd = { version = "0.10.0", features = ["bindgen", "zstdmt"], default-features [target.'cfg(any(target_os = "macos", target_os = "windows"))'.dependencies] guess_host_triple = "0.1.3" -[target.'cfg(any(windows, target_env = "musl"))'.dependencies] -mimalloc = { version = "0.1.29", default-features = false, optional = true } - [features] default = [] mimalloc = ["dep:mimalloc"] diff --git a/src/main.rs b/src/main.rs index 882e90f4..75bfc1be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,7 +25,7 @@ use cargo_binstall::{ *, }; -#[cfg(all(feature = "mimalloc", any(windows, target_env = "musl")))] +#[cfg(feature = "mimalloc")] #[global_allocator] static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;