Skip to content

Commit df95167

Browse files
committed
[msvc] Don't use -M* flags.
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 by relying on default MSVC behaviour that allows linking with either VCCRT version, static or dynamic...
1 parent daa41b9 commit df95167

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

src/lib.rs

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -976,9 +976,20 @@ impl Build {
976976
self
977977
}
978978

979-
/// Configures whether the /MT flag or the /MD flag will be passed to msvc build tools.
980-
///
981-
/// This option defaults to `false`, and affect only msvc targets.
979+
/// No-op option retained for backward compatibility.
980+
///
981+
/// Originally the method was introduced to harmonize with externally
982+
/// enforced `-MT` flag and resolve warnings in Rust bootstrap procedure
983+
/// on `*-windows-msvc` targets. It's argued that a more versatile approach
984+
/// is to **not** specify any of the `-M*` flags in cc-rs, but rely on
985+
/// the default MSVC compiler behaviour or externally enforced flag[s].
986+
/// The default behaviour allows forced linking with either VCCRT library,
987+
/// static or dynamic, whichever chosen by rustc at link time.
988+
///
989+
/// On a related note, if you compile Rust static library for use with an
990+
/// external application, it's likely to be appropriate to pass `-Zl` flag
991+
/// in order to not interfere with the target application's linking
992+
/// procedure.
982993
pub fn static_crt(&mut self, static_crt: bool) -> &mut Build {
983994
self.static_crt = Some(static_crt);
984995
self
@@ -1549,22 +1560,6 @@ impl Build {
15491560
ToolFamily::Msvc { .. } => {
15501561
cmd.push_cc_arg("-nologo".into());
15511562

1552-
let crt_flag = match self.static_crt {
1553-
Some(true) => "-MT",
1554-
Some(false) => "-MD",
1555-
None => {
1556-
let features = self
1557-
.getenv("CARGO_CFG_TARGET_FEATURE")
1558-
.unwrap_or(String::new());
1559-
if features.contains("crt-static") {
1560-
"-MT"
1561-
} else {
1562-
"-MD"
1563-
}
1564-
}
1565-
};
1566-
cmd.push_cc_arg(crt_flag.into());
1567-
15681563
match &opt_level[..] {
15691564
// Msvc uses /O1 to enable all optimizations that minimize code size.
15701565
"z" | "s" | "1" => cmd.push_opt_unless_duplicate("-O1".into()),

tests/test.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,7 @@ fn msvc_smoke() {
377377
.must_have("-O2")
378378
.must_have("foo.c")
379379
.must_not_have("-Z7")
380-
.must_have("-c")
381-
.must_have("-MD");
380+
.must_have("-c");
382381
test.cmd(1).must_have(test.td.path().join("foo.o"));
383382
}
384383

@@ -419,22 +418,6 @@ fn msvc_define() {
419418
test.cmd(0).must_have("-DFOO=bar").must_have("-DBAR");
420419
}
421420

422-
#[test]
423-
fn msvc_static_crt() {
424-
let test = Test::msvc();
425-
test.gcc().static_crt(true).file("foo.c").compile("foo");
426-
427-
test.cmd(0).must_have("-MT");
428-
}
429-
430-
#[test]
431-
fn msvc_no_static_crt() {
432-
let test = Test::msvc();
433-
test.gcc().static_crt(false).file("foo.c").compile("foo");
434-
435-
test.cmd(0).must_have("-MD");
436-
}
437-
438421
#[test]
439422
fn msvc_no_dash_dash() {
440423
let test = Test::msvc();

0 commit comments

Comments
 (0)