Skip to content

Commit f064f6c

Browse files
committed
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 <https://doc.rust-lang.org/cargo/reference/build-scripts.html#the-links-manifest-key> for documentation.
1 parent 0a32a38 commit f064f6c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

libmimalloc-sys/build.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::env;
2+
use std::path::Path;
23

34
fn main() {
45
let mut build = cc::Build::new();
@@ -9,6 +10,18 @@ fn main() {
910
"v2"
1011
};
1112

13+
let cargo_manifest_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
14+
let include_dir = Path::new(&cargo_manifest_dir)
15+
.join("c_src/mimalloc/")
16+
.join(version)
17+
.join("include")
18+
.to_str()
19+
.expect("include path is not valid UTF-8")
20+
.to_string();
21+
// Make the include directory available to consumers via the `DEP_MIMALLOC_INCLUDE_DIR`
22+
// environment variable.
23+
println!("cargo:INCLUDE_DIR={include_dir}");
24+
1225
build.include(format!("c_src/mimalloc/{version}/include"));
1326
build.include(format!("c_src/mimalloc/{version}/src"));
1427
build.file(format!("c_src/mimalloc/{version}/src/static.c"));

0 commit comments

Comments
 (0)