Skip to content

Commit 83a602a

Browse files
committed
Possible fix to Windows build with MSVC.
1 parent 93771e7 commit 83a602a

File tree

1 file changed

+23
-24
lines changed

1 file changed

+23
-24
lines changed

snmalloc-rs/snmalloc-sys/build.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,29 @@ fn configure_platform(config: &mut BuildConfig) {
308308
for flag in common_flags {
309309
config.builder.flag_if_supported(flag);
310310
}
311-
312-
if let Some(msystem) = &config.msystem {
311+
if config.is_msvc() {
312+
let msvc_flags = vec![
313+
"/nologo", "/W4", "/WX", "/wd4127", "/wd4324", "/wd4201",
314+
"/Ob2", "/DNDEBUG", "/EHsc", "/Gd", "/TP", "/Gm-", "/GS",
315+
"/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline"
316+
];
317+
for flag in msvc_flags {
318+
config.builder.flag_if_supported(flag);
319+
}
320+
321+
if config.features.lto {
322+
config.builder
323+
.flag_if_supported("/GL")
324+
.define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "TRUE")
325+
.define("SNMALLOC_IPO", "ON");
326+
println!("cargo:rustc-link-arg=/LTCG");
327+
}
328+
329+
config.builder
330+
.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc")
331+
.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc");
332+
}
333+
else if let Some(msystem) = &config.msystem {
313334
match msystem.as_str() {
314335
"CLANG64" | "CLANGARM64" => {
315336
let defines = vec![
@@ -339,28 +360,6 @@ fn configure_platform(config: &mut BuildConfig) {
339360
}
340361
}
341362
}
342-
_ if config.is_msvc() => {
343-
let msvc_flags = vec![
344-
"/nologo", "/W4", "/WX", "/wd4127", "/wd4324", "/wd4201",
345-
"/Ob2", "/DNDEBUG", "/EHsc", "/Gd", "/TP", "/Gm-", "/GS",
346-
"/fp:precise", "/Zc:wchar_t", "/Zc:forScope", "/Zc:inline"
347-
];
348-
for flag in msvc_flags {
349-
config.builder.flag_if_supported(flag);
350-
}
351-
352-
if config.features.lto {
353-
config.builder
354-
.flag_if_supported("/GL")
355-
.define("CMAKE_INTERPROCEDURAL_OPTIMIZATION", "TRUE")
356-
.define("SNMALLOC_IPO", "ON");
357-
println!("cargo:rustc-link-arg=/LTCG");
358-
}
359-
360-
config.builder
361-
.define("CMAKE_CXX_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc")
362-
.define("CMAKE_C_FLAGS_RELEASE", "/O2 /Ob2 /DNDEBUG /EHsc");
363-
}
364363
_ if config.is_unix() => {
365364
let unix_flags = vec!["-fPIC", "-pthread", "-fno-exceptions", "-fno-rtti", "-mcx16", "-Wno-unused-parameter"];
366365
for flag in unix_flags {

0 commit comments

Comments
 (0)