Skip to content

Commit

Permalink
Added mimalloc dev and dev-slice support
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
BlackDex committed Jan 16, 2022
1 parent d30e026 commit b812d30
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 3 deletions.
8 changes: 8 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[submodule "libmimalloc-sys/c_src/mimalloc"]
path = libmimalloc-sys/c_src/mimalloc
url = https://github.com/microsoft/mimalloc
[submodule "libmimalloc-sys/c_src/mimalloc_dev"]
path = libmimalloc-sys/c_src/mimalloc_dev
url = https://github.com/microsoft/mimalloc.git
branch = dev
[submodule "libmimalloc-sys/c_src/mimalloc_dev_slice"]
path = libmimalloc-sys/c_src/mimalloc_dev_slice
url = https://github.com/microsoft/mimalloc.git
branch = dev-slice
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ override = ["libmimalloc-sys/override"]
debug = ["libmimalloc-sys/debug"]
debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]

# Allow to select different mimalloc branch
v1_dev = ["libmimalloc-sys/v1_dev"] # v1 dev branch
v2_dev = ["libmimalloc-sys/v2_dev"] # v2 dev-slice branch
# Trigger git submodule update to have the latest upstream commit to be used
# This will be for all submodules, master, dev and dev-slice
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
submodule_update = ["libmimalloc-sys/submodule_update"]
8 changes: 8 additions & 0 deletions libmimalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ override = []
extended = ["cty"]
local_dynamic_tls = []

# Allow to select different mimalloc branch
v1_dev = [] # v1 dev branch
v2_dev = [] # v2 dev-slice branch
# Trigger git submodule update to have the latest upstream commit to be used
# This will be for all submodules, master, dev and dev-slice
# Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
submodule_update = []

# Show `extended` on docs.rs since it's the full API surface.
[package.metadata.docs.rs]
features = ["extended"]
33 changes: 30 additions & 3 deletions libmimalloc-sys/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
use std::env;
use std::process::Command;

fn main() {

// Update the submodule's if the `submodule_update` feature is enabled.
// This ensures the latests commits are used to build this package.
// Since mimalloc isn't fully ABI stable at the moment, it could cause issues.
if cfg!(feature = "submodule_update") {
// Init or update the submodule with libui if needed
Command::new("git")
.args(&["version"])
.status()
.expect("Git does not appear to be installed. Error");
Command::new("git")
.args(&["submodule", "update", "--init", "--recursive", "--remote"])
.status()
.expect("Unable to update mimalloc submodule branches. Error");
}

let mut build = cc::Build::new();

build.include("c_src/mimalloc/include");
build.include("c_src/mimalloc/src");
build.file("c_src/mimalloc/src/static.c");
if cfg!(feature = "v1_dev") {
build.include("c_src/mimalloc_dev/include");
build.include("c_src/mimalloc_dev/src");
build.file("c_src/mimalloc_dev/src/static.c");
} else if cfg!(feature = "v2_dev") {
build.include("c_src/mimalloc_dev_slice/include");
build.include("c_src/mimalloc_dev_slice/src");
build.file("c_src/mimalloc_dev_slice/src/static.c");
} else {
build.include("c_src/mimalloc/include");
build.include("c_src/mimalloc/src");
build.file("c_src/mimalloc/src/static.c");
}

let target_os = env::var("CARGO_CFG_TARGET_OS").expect("target_os not defined!");
let target_family = env::var("CARGO_CFG_TARGET_FAMILY").expect("target_family not defined!");
Expand Down
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc_dev
Submodule mimalloc_dev added at 0c8147
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc_dev_slice
Submodule mimalloc_dev_slice added at 44e7eb

0 comments on commit b812d30

Please sign in to comment.