Skip to content

Commit 20ac6ff

Browse files
Ryan ClantonRyan Clanton
authored andcommitted
Addition of windows gnu and linux cmake
1 parent 525faa1 commit 20ac6ff

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

libmimalloc-sys/build.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ fn main() {
9595
Ok(CMakeBuildType::MinSizeRel) => (false, "MinSizeRel"),
9696
Err(e) => panic!("Cannot determine CMake build type: {}", e),
9797
};
98-
99-
if cfg!(all(windows, target_env = "msvc")) {
98+
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
99+
if target_env == "msvc" {
100100
cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND");
101101

102102
// cc::get_compiler have /nologo /MD default flags that are cmake::Config
@@ -109,14 +109,31 @@ fn main() {
109109
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
110110
cfg = cfg.cflag("/DWIN32 /D_WINDOWS /W3 /MD /O2 /Ob2 /DNDEBUG");
111111
}
112-
}
112+
} else if target_env == "gnu" {
113+
cfg = cfg.define("CMAKE_SH", "CMAKE_SH-NOTFOUND");
114+
// cc::get_compiler have /nologo /MD default flags that are cmake::Config
115+
// defaults to. Those flags prevents mimalloc from building on windows
116+
// extracted from default cmake configuration on windows
117+
if is_debug {
118+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG
119+
cfg = cfg.cflag("-static -ffunction-sections -fdata-sections -m64 -O3 -fpic");
120+
} else {
121+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
122+
cfg = cfg.cflag("-static -ffunction-sections -fdata-sections -m64 -O3 -fpic");
123+
}
124+
};
113125

114126
let mut out_dir = "./build".to_string();
115127
if cfg!(all(windows, target_env = "msvc")) {
116-
out_dir.push('/');
117-
out_dir.push_str(win_folder);
128+
if target_env == "msvc" {
129+
out_dir.push('/');
130+
out_dir.push_str(win_folder);
131+
} else if target_env == "gnu" {
132+
out_dir.push('/');
133+
out_dir.push_str(win_folder);
134+
}
118135
}
119-
let out_name = if cfg!(all(windows, target_env = "msvc")) {
136+
let out_name = if cfg!(all(windows)) {
120137
if is_debug {
121138
if cfg!(feature = "secure") {
122139
"mimalloc-static-secure-debug"
@@ -149,7 +166,6 @@ fn main() {
149166
// Build mimalloc-static
150167
let mut dst = cfg.build_target("mimalloc-static").build();
151168
dst.push(out_dir);
152-
153169
println!("cargo:rustc-link-search=native={}", dst.display());
154170
println!("cargo:rustc-link-lib={}", out_name);
155171
}

libmimalloc-sys/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ extern "C" {
2020
/// Returns a unique pointer if called with `size` 0.
2121
pub fn mi_malloc(size: usize) -> *mut c_void;
2222

23+
/// Allocate `count` items of `size` length each.
24+
///
25+
/// Returns `null` if `count * size` overflows or on out-of-memory.
26+
///
27+
/// All items are initialized to zero.
28+
pub fn mi_calloc(count: usize, size: usize) -> *mut c_void;
29+
2330
/// Re-allocate memory to `newsize` bytes.
2431
///
2532
/// Return pointer to the allocated memory or null if out of memory. If null

0 commit comments

Comments
 (0)