Skip to content

Commit 5a33939

Browse files
committed
Added mimalloc dev and dev-slice support
- Added support to use the v1 dev branch or v2 dev-slice branch - Added option to update the git submodules to be able to use the latest commits from upstream mimalloc.
1 parent 76c4b3d commit 5a33939

File tree

6 files changed

+55
-3
lines changed

6 files changed

+55
-3
lines changed

.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
[submodule "libmimalloc-sys/c_src/mimalloc"]
22
path = libmimalloc-sys/c_src/mimalloc
33
url = https://github.com/microsoft/mimalloc
4+
[submodule "libmimalloc-sys/c_src/mimalloc_dev"]
5+
path = libmimalloc-sys/c_src/mimalloc_dev
6+
url = https://github.com/microsoft/mimalloc.git
7+
branch = dev
8+
[submodule "libmimalloc-sys/c_src/mimalloc_dev_slice"]
9+
path = libmimalloc-sys/c_src/mimalloc_dev_slice
10+
url = https://github.com/microsoft/mimalloc.git
11+
branch = dev-slice

Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,11 @@ override = ["libmimalloc-sys/override"]
3030
debug = ["libmimalloc-sys/debug"]
3131
debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
3232
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]
33+
34+
# Allow to select different mimalloc branch
35+
v1_dev = ["libmimalloc-sys/v1_dev"] # v1 dev branch
36+
v2_dev = ["libmimalloc-sys/v2_dev"] # v2 dev-slice branch
37+
# Trigger git submodule update to have the latest upstream commit to be used
38+
# This will be for all submodules, master, dev and dev-slice
39+
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
40+
submodule_update = ["libmimalloc-sys/submodule_update"]

libmimalloc-sys/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ override = []
2424
extended = ["cty"]
2525
local_dynamic_tls = []
2626

27+
# Allow to select different mimalloc branch
28+
v1_dev = [] # v1 dev branch
29+
v2_dev = [] # v2 dev-slice branch
30+
# Trigger git submodule update to have the latest upstream commit to be used
31+
# This will be for all submodules, master, dev and dev-slice
32+
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
33+
submodule_update = []
34+
2735
# Show `extended` on docs.rs since it's the full API surface.
2836
[package.metadata.docs.rs]
2937
features = ["extended"]

libmimalloc-sys/build.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
11
use std::env;
2+
use std::process::Command;
23

34
fn main() {
5+
// Update the submodule's if the `submodule_update` feature is enabled.
6+
// This ensures the latests commits are used to build this package.
7+
// Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
8+
if cfg!(feature = "submodule_update") {
9+
// Init or update the submodule with libui if needed
10+
Command::new("git")
11+
.args(&["version"])
12+
.status()
13+
.expect("Git does not appear to be installed. Error");
14+
Command::new("git")
15+
.args(&["submodule", "update", "--init", "--recursive", "--remote"])
16+
.status()
17+
.expect("Unable to update mimalloc submodule branches. Error");
18+
}
19+
420
let mut build = cc::Build::new();
521

6-
build.include("c_src/mimalloc/include");
7-
build.include("c_src/mimalloc/src");
8-
build.file("c_src/mimalloc/src/static.c");
22+
if cfg!(feature = "v1_dev") {
23+
build.include("c_src/mimalloc_dev/include");
24+
build.include("c_src/mimalloc_dev/src");
25+
build.file("c_src/mimalloc_dev/src/static.c");
26+
} else if cfg!(feature = "v2_dev") {
27+
build.include("c_src/mimalloc_dev_slice/include");
28+
build.include("c_src/mimalloc_dev_slice/src");
29+
build.file("c_src/mimalloc_dev_slice/src/static.c");
30+
} else {
31+
build.include("c_src/mimalloc/include");
32+
build.include("c_src/mimalloc/src");
33+
build.file("c_src/mimalloc/src/static.c");
34+
}
935

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

libmimalloc-sys/c_src/mimalloc_dev

Submodule mimalloc_dev added at ccf117c
Submodule mimalloc_dev_slice added at 18c1891

0 commit comments

Comments
 (0)