Skip to content

Commit 9a8d1f9

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 53fb72c commit 9a8d1f9

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
@@ -922,9 +922,9 @@ impl Build {
922922
self
923923
}
924924

925-
/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
925+
/// No-op option retained for backward compatibility.
926926
///
927-
/// This option defaults to `false`, and affect only msvc targets.
927+
/// Used to configure whether the /MT flag or the /MD flag will be passed to msvc build tools.
928928
pub fn static_crt(&mut self, static_crt: bool) -> &mut Build {
929929
self.static_crt = Some(static_crt);
930930
self
@@ -1487,21 +1487,14 @@ impl Build {
14871487
ToolFamily::Msvc { .. } => {
14881488
cmd.push_cc_arg("-nologo".into());
14891489

1490-
let crt_flag = match self.static_crt {
1491-
Some(true) => "-MT",
1492-
Some(false) => "-MD",
1493-
None => {
1494-
let features = self
1495-
.getenv("CARGO_CFG_TARGET_FEATURE")
1496-
.unwrap_or(String::new());
1497-
if features.contains("crt-static") {
1498-
"-MT"
1499-
} else {
1500-
"-MD"
1501-
}
1502-
}
1503-
};
1504-
cmd.push_cc_arg(crt_flag.into());
1490+
// Since this crate doesn't actually make decisions about
1491+
// final application linking, it's only appropriate to not
1492+
// interfere with the process. This can be achieved with
1493+
// -MT -Zl, because object modules compiled with these flags
1494+
// can be linked with either VCCRT version, static or dynamic,
1495+
// debug or release...
1496+
cmd.push_cc_arg("-MT".into());
1497+
cmd.push_cc_arg("-Zl".into());
15051498

15061499
match &opt_level[..] {
15071500
// 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)