Skip to content

Introduce feature flag to switch between mimalloc major versions #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "libmimalloc-sys/c_src/mimalloc"]
path = libmimalloc-sys/c_src/mimalloc
[submodule "libmimalloc-sys/c_src/mimalloc/v2"]
path = libmimalloc-sys/c_src/mimalloc/v2
url = https://github.com/microsoft/mimalloc
[submodule "libmimalloc-sys/c_src/mimalloc/v3"]
path = libmimalloc-sys/c_src/mimalloc/v3
url = https://github.com/microsoft/mimalloc
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ debug_in_debug = ["libmimalloc-sys/debug_in_debug"]
local_dynamic_tls = ["libmimalloc-sys/local_dynamic_tls"]
no_thp = ["libmimalloc-sys/no_thp"]
extended = ["libmimalloc-sys/extended"]
v3 = ["libmimalloc-sys/v3"]
19 changes: 13 additions & 6 deletions libmimalloc-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ description = "Sys crate wrapping the mimalloc allocator"
license = "MIT"
links = "mimalloc"
exclude = [
"/c_src/mimalloc/bin",
"/c_src/mimalloc/cmake",
"/c_src/mimalloc/doc",
"/c_src/mimalloc/docs",
"/c_src/mimalloc/ide",
"/c_src/mimalloc/test",
"/c_src/mimalloc/v2/bin",
"/c_src/mimalloc/v2/cmake",
"/c_src/mimalloc/v2/doc",
"/c_src/mimalloc/v2/docs",
"/c_src/mimalloc/v2/ide",
"/c_src/mimalloc/v2/test",
"/c_src/mimalloc/v3/bin",
"/c_src/mimalloc/v3/cmake",
"/c_src/mimalloc/v3/doc",
"/c_src/mimalloc/v3/docs",
"/c_src/mimalloc/v3/ide",
"/c_src/mimalloc/v3/test",
]

[dependencies]
Expand All @@ -34,6 +40,7 @@ extended = ["cty"]
arena = []
local_dynamic_tls = []
no_thp = []
v3 = []

# Show `extended` on docs.rs since it's the full API surface.
[package.metadata.docs.rs]
Expand Down
12 changes: 9 additions & 3 deletions libmimalloc-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ use std::env;
fn main() {
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");
let version = if env::var("CARGO_FEATURE_V3").is_ok() {
"v3"
} else {
"v2"
};

build.include(format!("c_src/mimalloc/{version}/include"));
build.include(format!("c_src/mimalloc/{version}/src"));
build.file(format!("c_src/mimalloc/{version}/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: 0 additions & 1 deletion libmimalloc-sys/c_src/mimalloc
Submodule mimalloc deleted from 09a270
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc/v2
Submodule v2 added at fbd8b9
1 change: 1 addition & 0 deletions libmimalloc-sys/c_src/mimalloc/v3
Submodule v3 added at dfa50c
14 changes: 11 additions & 3 deletions libmimalloc-sys/sys-test/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
use std::env;

fn main() {
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
let version = if env::var("CARGO_FEATURE_V3").is_ok() {
"v3"
} else {
"v2"
};

let mut cfg = ctest2::TestGenerator::new();
cfg.header("mimalloc.h")
.include(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../c_src/mimalloc/include"
.include(format!(
"{cargo_manifest_dir}/../c_src/mimalloc/{version}/include"
))
.cfg("feature", Some("extended"))
.fn_cname(|rust, link_name| link_name.unwrap_or(rust).to_string())
Expand Down