Skip to content

Commit 2cb02f0

Browse files
authored
Merge pull request #48 from ryancinsight/master
Addition of windows gnu and linux cmake
2 parents 525faa1 + b3033ba commit 2cb02f0

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

libmimalloc-sys/build.rs

Lines changed: 26 additions & 23 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,47 +109,50 @@ 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+
// Those flags prevents mimalloc from building on windows
115+
if is_debug {
116+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG
117+
cfg = cfg.cflag("-static -ffunction-sections -fdata-sections -m64 -O2 -fpic");
118+
} else {
119+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
120+
cfg = cfg.cflag("-static -ffunction-sections -fdata-sections -m64 -O3 -fpic");
121+
}
122+
};
113123

114124
let mut out_dir = "./build".to_string();
115-
if cfg!(all(windows, target_env = "msvc")) {
125+
if cfg!(all(windows)) {
116126
out_dir.push('/');
117127
out_dir.push_str(win_folder);
118128
}
119-
let out_name = if cfg!(all(windows, target_env = "msvc")) {
129+
let out_name = if cfg!(all(windows)) {
120130
if is_debug {
121131
if cfg!(feature = "secure") {
122132
"mimalloc-static-secure-debug"
123133
} else {
124134
"mimalloc-static-debug"
125135
}
136+
} else if cfg!(feature = "secure") {
137+
"mimalloc-static-secure"
126138
} else {
127-
if cfg!(feature = "secure") {
128-
"mimalloc-static-secure"
129-
} else {
130-
"mimalloc-static"
131-
}
139+
"mimalloc-static"
132140
}
133-
} else {
134-
if is_debug {
135-
if cfg!(feature = "secure") {
136-
"mimalloc-secure-debug"
137-
} else {
138-
"mimalloc-debug"
139-
}
141+
} else if is_debug {
142+
if cfg!(feature = "secure") {
143+
"mimalloc-secure-debug"
140144
} else {
141-
if cfg!(feature = "secure") {
142-
"mimalloc-secure"
143-
} else {
144-
"mimalloc"
145-
}
145+
"mimalloc-debug"
146146
}
147+
} else if cfg!(feature = "secure") {
148+
"mimalloc-secure"
149+
} else {
150+
"mimalloc"
147151
};
148152

149153
// Build mimalloc-static
150154
let mut dst = cfg.build_target("mimalloc-static").build();
151155
dst.push(out_dir);
152-
153156
println!("cargo:rustc-link-search=native={}", dst.display());
154157
println!("cargo:rustc-link-lib={}", out_name);
155158
}

0 commit comments

Comments
 (0)