Skip to content
Merged
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
31 changes: 29 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: cargo test --features secure

- name: Test libmimalloc-sys crate bindings (secure)
run: cargo run --features secure -p libmimalloc-sys-test
run: cargo run --features libmimalloc-sys-test/secure -p libmimalloc-sys-test

- name: Build (no secure)
run: cargo build
Expand All @@ -58,7 +58,34 @@ jobs:
run: cargo test --features extended

- name: Test libmimalloc-sys crate bindings (extended)
run: cargo run --features extended -p libmimalloc-sys-test
run: cargo run --features libmimalloc-sys-test/extended -p libmimalloc-sys-test

- name: Build (v3, secure)
run: cargo build --features v3,secure

- name: Test (v3, secure)
run: cargo test --features v3,secure

- name: Test libmimalloc-sys crate bindings (v3, secure)
run: cargo run --features libmimalloc-sys-test/v3,libmimalloc-sys-test/secure -p libmimalloc-sys-test

- name: Build (v3, no secure)
run: cargo build --features v3

- name: Test (v3, no secure)
run: cargo test --features v3

- name: Test libmimalloc-sys crate bindings (v3, no secure)
run: cargo run --features libmimalloc-sys-test/v3 -p libmimalloc-sys-test

- name: Build (v3, extended)
run: cargo build --features v3,extended

- name: Test (v3, extended)
run: cargo test --features v3,extended

- name: Test libmimalloc-sys crate bindings (v3, extended)
run: cargo run --features libmimalloc-sys-test/v3,libmimalloc-sys-test/extended -p libmimalloc-sys-test

lint:
name: Rustfmt / Clippy
Expand Down
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
4 changes: 4 additions & 0 deletions libmimalloc-sys/src/extended.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,15 @@ pub const mi_option_max_errors: mi_option_t = 19;
/// Option (experimental)
pub const mi_option_max_warnings: mi_option_t = 20;

#[cfg(not(feature = "v3"))]
/// Option (experimental)
pub const mi_option_max_segment_reclaim: mi_option_t = 21;

/// Last option.
#[cfg(not(feature = "v3"))]
pub const _mi_option_last: mi_option_t = 37;
#[cfg(feature = "v3")]
pub const _mi_option_last: mi_option_t = 43;

extern "C" {
// Note: mi_option_{enable,disable} aren't exposed because they're redundant
Expand Down
7 changes: 6 additions & 1 deletion libmimalloc-sys/sys-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ license = "MIT"
publish = false

[dependencies]
libmimalloc-sys = { path = "..", features = ["extended"] }
libmimalloc-sys = { path = ".." }
libc = "0.2"

[build-dependencies]
ctest2 = "0.4"

[features]
secure = ["libmimalloc-sys/secure"]
extended = ["libmimalloc-sys/extended"]
v3 = ["libmimalloc-sys/v3"]
28 changes: 24 additions & 4 deletions libmimalloc-sys/sys-test/build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
use std::env;

fn main() {
let cargo_manifest_dir = env!("CARGO_MANIFEST_DIR");
let secure = if env::var("CARGO_FEATURE_SECURE").is_ok() {
Some("secure")
} else {
None
};
let extended = if env::var("CARGO_FEATURE_EXTENDED").is_ok() {
Some("extended")
} else {
None
};
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"))
.cfg("feature", secure)
.cfg("feature", extended)
.cfg("feature", (version == "v3").then_some("v3"))
.fn_cname(|rust, link_name| link_name.unwrap_or(rust).to_string())
// ignore whether or not the option enum is signed.
.skip_signededness(|c| c.ends_with("_t") || c.ends_with("_e"))
Expand Down
2 changes: 1 addition & 1 deletion libmimalloc-sys/sys-test/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(bad_style, clippy::all)]
#![allow(bad_style, unused_imports, unused_macros, clippy::all)]

use libmimalloc_sys::*;

Expand Down
Loading