Skip to content

Commit 390d5a1

Browse files
committed
[msvc] Use -MT -Zl unconditionally.
Since this crate doesn't actually make decisions about final application linking, it's only appropriate to not interfere with the process. This can be achieved with -MT -Zl, because object modules compiled with these flags can be linked with either VCCRT version, static or dynamic, debug or release... For reference, -Zl doesn't affect linking directives set with in Windows headers to add references to not-so-common libraries like mfc.lib, windowscodecs.lib to name just a pair.
1 parent ad1f00d commit 390d5a1

File tree

2 files changed

+11
-35
lines changed

2 files changed

+11
-35
lines changed

src/lib.rs

+10-17
Original file line numberDiff line numberDiff line change
@@ -951,9 +951,9 @@ impl Build {
951951
self
952952
}
953953

954-
/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
954+
/// No-op option retained for backward compatibility.
955955
///
956-
/// This option defaults to `false`, and affect only msvc targets.
956+
/// Used to configure whether the /MT flag or the /MD flag will be passed to msvc build tools.
957957
pub fn static_crt(&mut self, static_crt: bool) -> &mut Build {
958958
self.static_crt = Some(static_crt);
959959
self
@@ -1521,21 +1521,14 @@ impl Build {
15211521
ToolFamily::Msvc { .. } => {
15221522
cmd.push_cc_arg("-nologo".into());
15231523

1524-
let crt_flag = match self.static_crt {
1525-
Some(true) => "-MT",
1526-
Some(false) => "-MD",
1527-
None => {
1528-
let features = self
1529-
.getenv("CARGO_CFG_TARGET_FEATURE")
1530-
.unwrap_or(String::new());
1531-
if features.contains("crt-static") {
1532-
"-MT"
1533-
} else {
1534-
"-MD"
1535-
}
1536-
}
1537-
};
1538-
cmd.push_cc_arg(crt_flag.into());
1524+
// Since this crate doesn't actually make decisions about
1525+
// final application linking, it's only appropriate to not
1526+
// interfere with the process. This can be achieved with
1527+
// -MT -Zl, because object modules compiled with these flags
1528+
// can be linked with either VCCRT version, static or dynamic,
1529+
// debug or release...
1530+
cmd.push_cc_arg("-MT".into());
1531+
cmd.push_cc_arg("-Zl".into());
15391532

15401533
match &opt_level[..] {
15411534
// Msvc uses /O1 to enable all optimizations that minimize code size.

tests/test.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,7 @@ fn msvc_smoke() {
362362
.must_have("-O2")
363363
.must_have("foo.c")
364364
.must_not_have("-Z7")
365-
.must_have("-c")
366-
.must_have("-MD");
365+
.must_have("-c");
367366
test.cmd(1).must_have(test.td.path().join("foo.o"));
368367
}
369368

@@ -404,22 +403,6 @@ fn msvc_define() {
404403
test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
405404
}
406405

407-
#[test]
408-
fn msvc_static_crt() {
409-
let test = Test::msvc();
410-
test.gcc().static_crt(true).file("foo.c").compile("foo");
411-
412-
test.cmd(0).must_have("-MT");
413-
}
414-
415-
#[test]
416-
fn msvc_no_static_crt() {
417-
let test = Test::msvc();
418-
test.gcc().static_crt(false).file("foo.c").compile("foo");
419-
420-
test.cmd(0).must_have("-MD");
421-
}
422-
423406
#[test]
424407
fn msvc_no_dash_dash() {
425408
let test = Test::msvc();

0 commit comments

Comments
 (0)