Skip to content

Commit 880f384

Browse files
committed
Moved ffi code to sys-crate
1 parent 3fd516a commit 880f384

File tree

8 files changed

+31
-18
lines changed

8 files changed

+31
-18
lines changed

.gitmodules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "c_src/mimalloc"]
2-
path = c_src/mimalloc
1+
[submodule "libmimalloc-sys/c_src/mimalloc"]
2+
path = libmimalloc-sys/c_src/mimalloc
33
url = https://github.com/microsoft/mimalloc

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
[package]
22
name = "mimalloc"
3-
links = "libmimalloc"
43
version = "0.1.0"
54
authors = ["Octavian Oncescu <[email protected]>"]
65
edition = "2018"
76

87
[dependencies]
98
libc = "0.2"
10-
11-
[build-dependencies]
12-
cmake = "0.1"
9+
libmimalloc-sys = { path = "libmimalloc-sys" }
1310

1411
[features]
15-
no_secure = []
12+
no_secure = ["libmimalloc-sys/no_secure"]

libmimalloc-sys/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "libmimalloc-sys"
3+
version = "0.1.0"
4+
authors = ["Octavian Oncescu <[email protected]>"]
5+
edition = "2018"
6+
7+
[dependencies]
8+
libc = "0.2"
9+
10+
[build-dependencies]
11+
cmake = "0.1"
12+
13+
[features]
14+
no_secure = []

build.rs renamed to libmimalloc-sys/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ fn main() {
55
let dst = Config::new("c_src/mimalloc")
66
.build();
77
println!("cargo:rustc-link-search=native={}", dst.display());
8+
//println!("cargo:rustc-link-lib=static=libmimalloc");
89
}
910

1011
#[cfg(not(feature = "no_secure"))]
@@ -13,4 +14,5 @@ fn main() {
1314
.define("SECURE", "ON")
1415
.build();
1516
println!("cargo:rustc-link-search=native={}", dst.display());
17+
//println!("cargo:rustc-link-lib=static=libmimalloc");
1618
}

libmimalloc-sys/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2019 Octavian Oncescu
2+
3+
use libc::{c_void, size_t};
4+
5+
extern "C" {
6+
pub fn mi_malloc_aligned(size: size_t, alignment: size_t) -> *const c_void;
7+
pub fn mi_free(p: *const c_void) -> c_void;
8+
}

src/ffi.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
//! mimalloc = { version = "*", features = ["no_secure"] }
2222
//! ```
2323
24+
extern crate libmimalloc_sys as ffi;
25+
2426
use std::alloc::{GlobalAlloc, Layout};
2527
use std::ptr::null_mut;
2628
use libc::c_void;
@@ -46,6 +48,4 @@ unsafe impl GlobalAlloc for MiMalloc {
4648
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
4749
mi_free(ptr as *const c_void);
4850
}
49-
}
50-
51-
mod ffi;
51+
}

0 commit comments

Comments
 (0)