Skip to content

Commit 940479c

Browse files
committed
fix build on windows and use travis right
1 parent 98273b2 commit 940479c

File tree

4 files changed

+63
-40
lines changed

4 files changed

+63
-40
lines changed

.travis.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
dist: trusty
2-
sudo: require
3-
4-
addons:
5-
apt:
6-
sources:
7-
- ubuntu-toolchain-r-test
8-
packages:
9-
- gcc-6
10-
- g++-6
11-
- cmake
12-
131
language: rust
142

15-
cache: cargo
3+
sudo: required
164

175
rust:
186
- stable
7+
- beta
198
- nightly
209

10+
os:
11+
- windows
12+
- linux
13+
- osx
14+
2115
matrix:
2216
allow_failures:
2317
- rust: nightly
24-
fast_finish: true
18+
19+
addons:
20+
apt:
21+
packages:
22+
- cmake
23+
- gcc
24+
25+
language: rust
26+
27+
cache: cargo
2528

2629
script:
27-
- cargo test --all
28-
- cargo test --all --features no_secure
30+
- cargo test --verbose --all
31+
- cargo test --verbose --all --no-default-features
32+
- cargo test --release --verbose --all
33+
- cargo test --release --verbose --all --no-default-features

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ description = "Performance and security oriented drop-in allocator"
1010
license = "MIT"
1111
readme = "README.md"
1212

13+
[workspace]
14+
members = ["libmimalloc-sys" ]
15+
1316
[badges]
1417
travis-ci = { repository = "purpleprotocol/mimalloc_rust" }
1518

libmimalloc-sys/build.rs

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
use cmake::Config;
22

3-
#[cfg(not(feature = "secure"))]
43
fn main() {
5-
let mut dst = Config::new("c_src/mimalloc")
6-
.build();
4+
let mut cfg = &mut Config::new("c_src/mimalloc");
75

8-
dst.push("build");
6+
cfg = cfg.define("MI_OVERRIDE", "OFF");
97

10-
println!("cargo:rustc-link-search=native={}", dst.display());
11-
if cfg!(debug_assertions) {
12-
println!("cargo:rustc-link-lib=static=mimalloc-debug");
13-
} else {
14-
println!("cargo:rustc-link-lib=static=mimalloc");
8+
if cfg!(feature = "secure") {
9+
cfg = cfg.define("MI_SECURE", "OFF");
1510
}
16-
}
1711

18-
#[cfg(feature = "secure")]
19-
fn main() {
20-
let mut dst = Config::new("c_src/mimalloc")
21-
.define("SECURE", "ON")
22-
.build();
12+
if cfg!(all(windows, target_env = "msvc")) {
13+
// cc::get_compiler have /nologo /MD default flags that are cmake::Config
14+
// defaults to. Those flags prevents mimalloc from building on windows
15+
// extracted from default cmake configuration on windows
16+
if cfg!(debug_assertions) {
17+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_DEBUG
18+
cfg = cfg.cflag("/DWIN32 /D_WINDOWS /W3 /MDd /Zi /Ob0 /Od /RTC1");
19+
} else {
20+
// CMAKE_C_FLAGS + CMAKE_C_FLAGS_RELEASE
21+
cfg = cfg.cflag("/DWIN32 /D_WINDOWS /W3 /MD /O2 /Ob2 /DNDEBUG");
22+
}
23+
}
2324

24-
dst.push("build");
25-
26-
println!("cargo:rustc-link-search=native={}", dst.display());
27-
if cfg!(debug_assertions) {
28-
println!("cargo:rustc-link-lib=static=mimalloc-debug");
25+
let (out_dir, out_name) = if cfg!(all(windows, target_env = "msvc")) {
26+
if cfg!(debug_assertions) {
27+
("./build/Debug", "mimalloc-static-debug")
28+
} else {
29+
("./build/Release", "mimalloc-static")
30+
}
2931
} else {
30-
println!("cargo:rustc-link-lib=static=mimalloc-secure");
31-
}
32-
}
32+
if cfg!(debug_assertions) {
33+
("./build", "mimalloc-debug")
34+
} else if cfg!(feature = "secure") {
35+
("./build", "mimalloc")
36+
} else {
37+
("./build", "mimalloc")
38+
}
39+
};
40+
41+
// Build mimalloc-static
42+
let mut dst = cfg.build_target("mimalloc-static").build();
43+
dst.push(out_dir);
44+
45+
println!("cargo:rustc-link-search=native={}", dst.display());
46+
println!("cargo:rustc-link-lib={}", out_name);
47+
}

0 commit comments

Comments
 (0)