Skip to content

Commit 747b5b1

Browse files
committed
Introduce feature flag to switch between mimalloc major versions
1 parent 0007097 commit 747b5b1

File tree

8 files changed

+29
-9
lines changed

8 files changed

+29
-9
lines changed

.gitmodules

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
[submodule "libmimalloc-sys/c_src/mimalloc"]
2-
path = libmimalloc-sys/c_src/mimalloc
1+
[submodule "libmimalloc-sys/c_src/mimalloc/v2"]
2+
path = libmimalloc-sys/c_src/mimalloc/v2
3+
url = https://github.com/microsoft/mimalloc
4+
[submodule "libmimalloc-sys/c_src/mimalloc/v3"]
5+
path = libmimalloc-sys/c_src/mimalloc/v3
36
url = https://github.com/microsoft/mimalloc

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
3232
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]
3333
no_thp = ["libmimalloc-sys/no_thp"]
3434
extended = ["libmimalloc-sys/extended"]
35+
v3 = ["libmimalloc-sys/v3"]

libmimalloc-sys/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extended = ["cty"]
3434
arena = []
3535
local_dynamic_tls = []
3636
no_thp = []
37+
v3 = []
3738

3839
# Show `extended` on docs.rs since it's the full API surface.
3940
[package.metadata.docs.rs]

libmimalloc-sys/build.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,15 @@ use std::env;
33
fn main() {
44
let mut build = cc::Build::new();
55

6-
build.include("c_src/mimalloc/include");
7-
build.include("c_src/mimalloc/src");
8-
build.file("c_src/mimalloc/src/static.c");
6+
let version = if env::var("CARGO_FEATURE_V3").is_ok() {
7+
"v3"
8+
} else {
9+
"v2"
10+
};
11+
12+
build.include(format!("c_src/mimalloc/{version}/include"));
13+
build.include(format!("c_src/mimalloc/{version}/src"));
14+
build.file(format!("c_src/mimalloc/{version}/src/static.c"));
915

1016
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!");
1117
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!");

libmimalloc-sys/c_src/mimalloc

Lines changed: 0 additions & 1 deletion
This file was deleted.

libmimalloc-sys/c_src/mimalloc/v2

Submodule v2 added at fbd8b99

libmimalloc-sys/c_src/mimalloc/v3

Submodule v3 added at dfa50c3

libmimalloc-sys/sys-test/build.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
use std::env;
2+
13
fn main() {
4+
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
5+
let version = if env::var("CARGO_FEATURE_V3").is_ok() {
6+
"v3"
7+
} else {
8+
"v2"
9+
};
10+
211
let mut cfg = ctest2::TestGenerator::new();
312
cfg.header("mimalloc.h")
4-
.include(concat!(
5-
env!("CARGO_MANIFEST_DIR"),
6-
"/../c_src/mimalloc/include"
13+
.include(format!(
14+
"{cargo_manifest_dir}/../c_src/mimalloc/{version}/include"
715
))
816
.cfg("feature", Some("extended"))
917
.fn_cname(|rust, link_name| link_name.unwrap_or(rust).to_string())

0 commit comments

Comments
 (0)