From f064f6c57e55a889c8b4f6b3170e3e6ae0744e73 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender Date: Wed, 12 Nov 2025 17:10:03 +0100 Subject: [PATCH] Provide the include directory to consumers For users using both C/C++ and Rust, it's useful to have access to the mimalloc include directory in the build-script (of crates directly depending on `libmimalloc-sys`). This allows using the header in user build-scripts, without needing to vendor the mimalloc header. This mechanism is also already used in crates like libz-sys, see https://github.com/rust-lang/libz-sys/blob/80c597a07f5e5f0dff0e98c03d48a77845de9f6e/build.rs#L171 See for documentation. --- libmimalloc-sys/build.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libmimalloc-sys/build.rs b/libmimalloc-sys/build.rs index 0a05784..c67e6d6 100644 --- a/libmimalloc-sys/build.rs +++ b/libmimalloc-sys/build.rs @@ -1,4 +1,5 @@ use std::env; +use std::path::Path; fn main() { let mut build = cc::Build::new(); @@ -9,6 +10,18 @@ fn main() { "v2" }; + let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + let include_dir = Path::new(&cargo_manifest_dir) + .join("c_src/mimalloc/") + .join(version) + .join("include") + .to_str() + .expect("include path is not valid UTF-8") + .to_string(); + // Make the include directory available to consumers via the `DEP_MIMALLOC_INCLUDE_DIR` + // environment variable. + println!("cargo:INCLUDE_DIR={include_dir}"); + build.include(format!("c_src/mimalloc/{version}/include")); build.include(format!("c_src/mimalloc/{version}/src")); build.file(format!("c_src/mimalloc/{version}/src/static.c"));