diff --git a/.gitmodules b/.gitmodules index cf61ca1..a45cf90 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Cargo.toml b/Cargo.toml index f40838a..a5190f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/libmimalloc-sys/Cargo.toml b/libmimalloc-sys/Cargo.toml index 4e2b97e..f8ec18f 100644 --- a/libmimalloc-sys/Cargo.toml +++ b/libmimalloc-sys/Cargo.toml @@ -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"] diff --git a/libmimalloc-sys/build.rs b/libmimalloc-sys/build.rs index 7cc9379..e9b8f50 100644 --- a/libmimalloc-sys/build.rs +++ b/libmimalloc-sys/build.rs @@ -1,11 +1,37 @@ 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!"); diff --git a/libmimalloc-sys/c_src/mimalloc_dev b/libmimalloc-sys/c_src/mimalloc_dev new file mode 160000 index 0000000..ccf117c --- /dev/null +++ b/libmimalloc-sys/c_src/mimalloc_dev @@ -0,0 +1 @@ +Subproject commit ccf117c43d11bce115c9672d50c370c7d35739a7 diff --git a/libmimalloc-sys/c_src/mimalloc_dev_slice b/libmimalloc-sys/c_src/mimalloc_dev_slice new file mode 160000 index 0000000..18c1891 --- /dev/null +++ b/libmimalloc-sys/c_src/mimalloc_dev_slice @@ -0,0 +1 @@ +Subproject commit 18c18917081e10c4a64e76c6b887ca0fa42fd345 diff --git a/libmimalloc-sys/src/extended.rs b/libmimalloc-sys/src/extended.rs index 1647166..a7bedcc 100644 --- a/libmimalloc-sys/src/extended.rs +++ b/libmimalloc-sys/src/extended.rs @@ -512,11 +512,18 @@ pub const mi_option_large_os_pages: mi_option_t = 6; /// allocate just a little to take up space in the huge OS page area (which cannot be reset). pub const mi_option_reserve_huge_os_pages: mi_option_t = 7; -/// TODO: update later -pub const mi_option_reserve_os_memory: mi_option_t = 8; +/// Option (experimental) reserve huge OS pages at a specific NUMA node +/// +/// The huge pages are usually allocated evenly among NUMA nodes. +/// You can use mi_option_reserve_huge_os_pages_at=N where `N` is the numa node (starting at 0) to allocate all +/// the huge pages at a specific numa node instead. +pub const mi_option_reserve_huge_os_pages_at: mi_option_t = 8; + +/// Option (experimental) reserve specified amount of OS memory at startup +pub const mi_option_reserve_os_memory: mi_option_t = 9; /// Option (experimental) specifying number of segments per thread to keep cached. -pub const mi_option_segment_cache: mi_option_t = 9; +pub const mi_option_segment_cache: mi_option_t = 10; /// Option (experimental) to reset page memory after mi_option_reset_delay milliseconds when it becomes free. /// @@ -528,19 +535,19 @@ pub const mi_option_segment_cache: mi_option_t = 9; /// off completely. /// /// Default: 1 (true) -pub const mi_option_page_reset: mi_option_t = 10; +pub const mi_option_page_reset: mi_option_t = 11; /// Experimental -pub const mi_option_abandoned_page_reset: mi_option_t = 11; +pub const mi_option_abandoned_page_reset: mi_option_t = 12; /// Experimental -pub const mi_option_segment_reset: mi_option_t = 12; +pub const mi_option_segment_reset: mi_option_t = 13; /// Experimental -pub const mi_option_eager_commit_delay: mi_option_t = 13; +pub const mi_option_eager_commit_delay: mi_option_t = 14; /// Option (experimental) specifying delay in milli-seconds before resetting a page (100ms by default). -pub const mi_option_reset_delay: mi_option_t = 14; +pub const mi_option_reset_delay: mi_option_t = 15; /// Option (experimental) to pretend there are at most N NUMA nodes. /// @@ -549,19 +556,19 @@ pub const mi_option_reset_delay: mi_option_t = 14; /// actual NUMA nodes is fine and will only cause threads to potentially allocate more /// memory across actual NUMA nodes (but this can happen in any case as NUMA local /// allocation is always a best effort but not guaranteed). -pub const mi_option_use_numa_nodes: mi_option_t = 15; +pub const mi_option_use_numa_nodes: mi_option_t = 16; /// TODO: update later -pub const mi_option_limit_os_alloc: mi_option_t = 16; +pub const mi_option_limit_os_alloc: mi_option_t = 17; /// Option (experimental) specifying OS tag to assign to mimalloc'd memory. -pub const mi_option_os_tag: mi_option_t = 17; +pub const mi_option_os_tag: mi_option_t = 18; /// Experimental -pub const mi_option_max_errors: mi_option_t = 18; +pub const mi_option_max_errors: mi_option_t = 19; /// Experimental -pub const mi_option_max_warnings: mi_option_t = 19; +pub const mi_option_max_warnings: mi_option_t = 20; extern "C" { // Note: mi_option_{enable,disable} aren't exposed because they're redundant diff --git a/libmimalloc-sys/sys-test/Cargo.toml b/libmimalloc-sys/sys-test/Cargo.toml index 19c47a6..89fb748 100644 --- a/libmimalloc-sys/sys-test/Cargo.toml +++ b/libmimalloc-sys/sys-test/Cargo.toml @@ -12,4 +12,4 @@ libmimalloc-sys = { path = "..", features = ["extended"] } libc = "0.2" [build-dependencies] -ctest = "0.2" +ctest2 = "0.4" diff --git a/libmimalloc-sys/sys-test/build.rs b/libmimalloc-sys/sys-test/build.rs index aad27a1..5aabf83 100644 --- a/libmimalloc-sys/sys-test/build.rs +++ b/libmimalloc-sys/sys-test/build.rs @@ -1,5 +1,5 @@ fn main() { - let mut cfg = ctest::TestGenerator::new(); + let mut cfg = ctest2::TestGenerator::new(); cfg.header("mimalloc.h") .include(concat!( env!("CARGO_MANIFEST_DIR"), diff --git a/libmimalloc-sys/sys-test/src/main.rs b/libmimalloc-sys/sys-test/src/main.rs index d637386..01a307b 100644 --- a/libmimalloc-sys/sys-test/src/main.rs +++ b/libmimalloc-sys/sys-test/src/main.rs @@ -1,4 +1,4 @@ -#![allow(bad_style, clippy::all)] +#![allow(bad_style, deprecated, clippy::all)] use libmimalloc_sys::*;