From 6d46e073040d03be4abffc599e11609febecf9fc Mon Sep 17 00:00:00 2001 From: Michel Alexandre Salim Date: Mon, 4 Apr 2022 11:52:40 -0700 Subject: [PATCH] Use system mimalloc if available When packaging for Fedora, bundled libraries are discouraged: https://docs.fedoraproject.org/en-US/fesco/Bundled_Software_policy/ Build against the system mimalloc if we detect its header. Signed-off-by: Michel Alexandre Salim --- libmimalloc-sys/build.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libmimalloc-sys/build.rs b/libmimalloc-sys/build.rs index 7cc9379..1afdf18 100644 --- a/libmimalloc-sys/build.rs +++ b/libmimalloc-sys/build.rs @@ -1,15 +1,21 @@ use std::env; +use std::path; fn main() { + let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); + let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!"); + + // use system mimalloc if available + if target_family == "unix" && path::Path::new("/usr/include/mimalloc.h").exists() { + return + } + let mut build = cc::Build::new(); build.include("c_src/mimalloc/include"); build.include("c_src/mimalloc/src"); build.file("c_src/mimalloc/src/static.c"); - let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!"); - let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!"); - if env::var_os("CARGO_FEATURE_OVERRIDE").is_some() { // Overriding malloc is only available on windows in shared mode, but we // only ever build a static lib. -- 2.35.1