Skip to content

Commit 31607bf

Browse files
authored
Merge pull request #144 from gschulze/feature/3.x
Introduce feature flag to switch between mimalloc major versions
2 parents 0007097 + aaa0114 commit 31607bf

File tree

12 files changed

+94
-20
lines changed

12 files changed

+94
-20
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
run: cargo test --features secure
4141

4242
- name: Test libmimalloc-sys crate bindings (secure)
43-
run: cargo run --features secure -p libmimalloc-sys-test
43+
run: cargo run --features libmimalloc-sys-test/secure -p libmimalloc-sys-test
4444

4545
- name: Build (no secure)
4646
run: cargo build
@@ -58,7 +58,34 @@ jobs:
5858
run: cargo test --features extended
5959

6060
- name: Test libmimalloc-sys crate bindings (extended)
61-
run: cargo run --features extended -p libmimalloc-sys-test
61+
run: cargo run --features libmimalloc-sys-test/extended -p libmimalloc-sys-test
62+
63+
- name: Build (v3, secure)
64+
run: cargo build --features v3,secure
65+
66+
- name: Test (v3, secure)
67+
run: cargo test --features v3,secure
68+
69+
- name: Test libmimalloc-sys crate bindings (v3, secure)
70+
run: cargo run --features libmimalloc-sys-test/v3,libmimalloc-sys-test/secure -p libmimalloc-sys-test
71+
72+
- name: Build (v3, no secure)
73+
run: cargo build --features v3
74+
75+
- name: Test (v3, no secure)
76+
run: cargo test --features v3
77+
78+
- name: Test libmimalloc-sys crate bindings (v3, no secure)
79+
run: cargo run --features libmimalloc-sys-test/v3 -p libmimalloc-sys-test
80+
81+
- name: Build (v3, extended)
82+
run: cargo build --features v3,extended
83+
84+
- name: Test (v3, extended)
85+
run: cargo test --features v3,extended
86+
87+
- name: Test libmimalloc-sys crate bindings (v3, extended)
88+
run: cargo run --features libmimalloc-sys-test/v3,libmimalloc-sys-test/extended -p libmimalloc-sys-test
6289

6390
lint:
6491
name: Rustfmt / Clippy

.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: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,18 @@ description = "Sys crate wrapping the mimalloc allocator"
1010
license = "MIT"
1111
links = "mimalloc"
1212
exclude = [
13-
"/c_src/mimalloc/bin",
14-
"/c_src/mimalloc/cmake",
15-
"/c_src/mimalloc/doc",
16-
"/c_src/mimalloc/docs",
17-
"/c_src/mimalloc/ide",
18-
"/c_src/mimalloc/test",
13+
"/c_src/mimalloc/v2/bin",
14+
"/c_src/mimalloc/v2/cmake",
15+
"/c_src/mimalloc/v2/doc",
16+
"/c_src/mimalloc/v2/docs",
17+
"/c_src/mimalloc/v2/ide",
18+
"/c_src/mimalloc/v2/test",
19+
"/c_src/mimalloc/v3/bin",
20+
"/c_src/mimalloc/v3/cmake",
21+
"/c_src/mimalloc/v3/doc",
22+
"/c_src/mimalloc/v3/docs",
23+
"/c_src/mimalloc/v3/ide",
24+
"/c_src/mimalloc/v3/test",
1925
]
2026

2127
[dependencies]
@@ -34,6 +40,7 @@ extended = ["cty"]
3440
arena = []
3541
local_dynamic_tls = []
3642
no_thp = []
43+
v3 = []
3744

3845
# Show `extended` on docs.rs since it's the full API surface.
3946
[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/src/extended.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,15 @@ pub const mi_option_max_errors: mi_option_t = 19;
542542
/// Option (experimental)
543543
pub const mi_option_max_warnings: mi_option_t = 20;
544544

545+
#[cfg(not(feature = "v3"))]
545546
/// Option (experimental)
546547
pub const mi_option_max_segment_reclaim: mi_option_t = 21;
547548

548549
/// Last option.
550+
#[cfg(not(feature = "v3"))]
549551
pub const _mi_option_last: mi_option_t = 37;
552+
#[cfg(feature = "v3")]
553+
pub const _mi_option_last: mi_option_t = 43;
550554

551555
extern "C" {
552556
// Note: mi_option_{enable,disable} aren't exposed because they're redundant

libmimalloc-sys/sys-test/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@ license = "MIT"
88
publish = false
99

1010
[dependencies]
11-
libmimalloc-sys = { path = "..", features = ["extended"] }
11+
libmimalloc-sys = { path = ".." }
1212
libc = "0.2"
1313

1414
[build-dependencies]
1515
ctest2 = "0.4"
16+
17+
[features]
18+
secure = ["libmimalloc-sys/secure"]
19+
extended = ["libmimalloc-sys/extended"]
20+
v3 = ["libmimalloc-sys/v3"]

0 commit comments

Comments
 (0)