Skip to content

Commit 9eda981

Browse files
Fix clang-cl target when cross-compiling (#1670)
Always set `--target`, otherwise it forces the Arch of the host upon the compilation, producing for example `coff arm64` on Darwin aarch64 host for target `x86_64-pc-windows-msvc`
1 parent 0767349 commit 9eda981

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/lib.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2307,10 +2307,15 @@ impl Build {
23072307
cmd.push_cc_arg("-Brepro".into());
23082308

23092309
if clang_cl {
2310-
if target.arch == "x86_64" {
2311-
cmd.push_cc_arg("-m64".into());
2312-
} else if target.arch == "x86" {
2313-
cmd.push_cc_arg("-m32".into());
2310+
cmd.push_cc_arg(
2311+
format!(
2312+
"--target={}",
2313+
target.llvm_target(&self.get_raw_target()?, None)
2314+
)
2315+
.into(),
2316+
);
2317+
2318+
if target.arch == "x86" {
23142319
// See
23152320
// <https://learn.microsoft.com/en-us/cpp/build/reference/arch-x86?view=msvc-170>.
23162321
//
@@ -2321,14 +2326,6 @@ impl Build {
23212326
// <https://github.com/microsoft/STL/issues/3922>, and -
23222327
// <https://github.com/microsoft/STL/pull/4741>.
23232328
cmd.push_cc_arg("-arch:SSE2".into());
2324-
} else {
2325-
cmd.push_cc_arg(
2326-
format!(
2327-
"--target={}",
2328-
target.llvm_target(&self.get_raw_target()?, None)
2329-
)
2330-
.into(),
2331-
);
23322329
}
23332330
} else if target.full_arch == "i586" {
23342331
cmd.push_cc_arg("-arch:IA32".into());
@@ -4466,7 +4463,7 @@ fn check_disabled() -> Result<(), Error> {
44664463
if is_disabled() {
44674464
return Err(Error::new(
44684465
ErrorKind::Disabled,
4469-
"the `cc` crate's functionality has been disabled by the `CC_FORCE_DISABLE` environment variable."
4466+
"the `cc` crate's functionality has been disabled by the `CC_FORCE_DISABLE` environment variable.",
44704467
));
44714468
}
44724469
Ok(())

0 commit comments

Comments
 (0)