Skip to content

Commit

Permalink
Add crt flags for windows msvc targets compiled by clang.
Browse files Browse the repository at this point in the history
The msvc runtime library needs to be added for all targets compiled
for the windows-msvc abi, regardless of the compiler.
There are three options to compile code for windows msvc:
- with the official msvc toolchain
- with clang-cl, which has commandline syntax compatible with the
  msvc toolchain
- with clang, which uses the GNU commandline syntax.

In all three cases the -MT or -MD flag must be added.

Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
  • Loading branch information
jschwe committed May 27, 2023
1 parent 57853c4 commit 51e4ba9
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1587,20 +1587,6 @@ impl Build {
ToolFamily::Msvc { .. } => {
cmd.push_cc_arg("-nologo".into());

let crt_flag = match self.static_crt {
Some(true) => "-MT",
Some(false) => "-MD",
None => {
let features = self
.getenv("CARGO_CFG_TARGET_FEATURE")
.unwrap_or(String::new());
if features.contains("crt-static") {
"-MT"
} else {
"-MD"
}
}
};
cmd.push_cc_arg(crt_flag.into());

match &opt_level[..] {
Expand Down Expand Up @@ -1649,6 +1635,23 @@ impl Build {
}
}

if target.contains("msvc") {
let crt_flag = match self.static_crt {
Some(true) => "-MT",
Some(false) => "-MD",
None => {
let features = self
.getenv("CARGO_CFG_TARGET_FEATURE")
.unwrap_or(String::new());
if features.contains("crt-static") {
"-MT"
} else {
"-MD"
}
}
};
}

if self.get_debug() {
if self.cuda {
// NVCC debug flag
Expand Down

0 comments on commit 51e4ba9

Please sign in to comment.