summaryrefslogtreecommitdiffstats
path: root/rust/libmimalloc-sys-use-system.patch
blob: 1a90974bbe685c9e01d68d4d720f5540228289d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
From 6d46e073040d03be4abffc599e11609febecf9fc Mon Sep 17 00:00:00 2001
From: Michel Alexandre Salim <salimma@fedoraproject.org>
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 <salimma@fedoraproject.org>
---
 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