Skip to content

Commit b812d30

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 d30e026 commit b812d30

File tree

6 files changed

+56
-3
lines changed

6 files changed

+56
-3
lines changed

.gitmodules

+8
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

+8
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

+8
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

+30-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
11
use std::env;
2+
use std::process::Command;
23

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

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

1037
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!");
1138
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 0c81477
Submodule mimalloc_dev_slice added at 44e7eb1

0 commit comments

Comments
 (0)