Conversation
NobodyXu
left a comment
There was a problem hiding this comment.
Thank you!
Is it possible to use -Tp instead, to recognise the immediate following .cc as c++ source files?
/TP could potentially break c code as C++ as slightly different rules, sometimes stricter
MSVC only recognizes .c/.cpp/.cxx as source. A .cc file such as mimalloc 0.1.52's generated mimalloc-static.cc is assumed to be an object (D9024), so the -Fo output is never produced. Pass per-file -Tp immediately before each C++ source on MSVC-like compilers. Unlike /TP, -Tp applies only to the following file and does not compile C inputs as C++. Fixes rust-lang#1877 Co-authored-by: Cestercian <yashafaid@gmail.com>
bd4f05a to
de5683e
Compare
|
@NobodyXu Switched to per-file |
| if self.cpp && compiler.is_like_msvc() && !is_assembler_msvc { | ||
| // MSVC recognizes only `.c` / `.cpp` / `.cxx` as source. A `.cc` | ||
| // file (mimalloc 0.1.52 writes `OUT_DIR/mimalloc-static.cc`) is | ||
| // assumed to be an object unless `-Tp` forces C++ compilation | ||
| // (#1877). | ||
| cmd.arg("-Tp"); | ||
| } else if compiler.supports_path_delimiter() && !is_assembler_msvc { | ||
| // #513: For `clang-cl`, separate flags/options from the input file. | ||
| // When cross-compiling macOS -> Windows, this avoids interpreting | ||
| // common `/Users/...` paths as the `/U` flag and triggering | ||
| // `-Wslash-u-filename` warning. | ||
| cmd.arg("--"); | ||
| } |
There was a problem hiding this comment.
Ok there's a few issues we need to solve here
- we shouldn't need to check
!is_assembler_msvcfor/Tp --is used forclang-clto signal end of the options here so we cannot pass/Tpafterwards, however the good news is, we don't need it because clang-cl can recognise.cc- we need to pass
/Tponly for.ccfiles
so we need to do something like this:
| if self.cpp && compiler.is_like_msvc() && !is_assembler_msvc { | |
| // MSVC recognizes only `.c` / `.cpp` / `.cxx` as source. A `.cc` | |
| // file (mimalloc 0.1.52 writes `OUT_DIR/mimalloc-static.cc`) is | |
| // assumed to be an object unless `-Tp` forces C++ compilation | |
| // (#1877). | |
| cmd.arg("-Tp"); | |
| } else if compiler.supports_path_delimiter() && !is_assembler_msvc { | |
| // #513: For `clang-cl`, separate flags/options from the input file. | |
| // When cross-compiling macOS -> Windows, this avoids interpreting | |
| // common `/Users/...` paths as the `/U` flag and triggering | |
| // `-Wslash-u-filename` warning. | |
| cmd.arg("--"); | |
| } | |
| if | |
| self.cpp && | |
| src.extension == Some("cc") && | |
| matches!(compiler.family, ToolFamily::Msvc { clang_cl: false }) | |
| { | |
| // MSVC recognizes only `.c` / `.cpp` / `.cxx` as source. A `.cc` | |
| // file (mimalloc 0.1.52 writes `OUT_DIR/mimalloc-static.cc`) is | |
| // assumed to be an object unless `-Tp` forces C++ compilation | |
| // (#1877). | |
| cmd.arg("-Tp"); | |
| } | |
| if compiler.supports_path_delimiter() && !is_assembler_msvc { | |
| // #513: For `clang-cl`, separate flags/options from the input file. | |
| // When cross-compiling macOS -> Windows, this avoids interpreting | |
| // common `/Users/...` paths as the `/U` flag and triggering | |
| // `-Wslash-u-filename` warning. | |
| cmd.arg("--"); | |
| } |
There was a problem hiding this comment.
makes sense, narrowed it to -Tp only for .cc on MSVC (not clang-cl), and left the -- path alone
| /// On MSVC this also passes `-Tp` immediately before each source file, so | ||
| /// inputs such as `.cc` are compiled as C++ rather than assumed to be |
There was a problem hiding this comment.
| /// On MSVC this also passes `-Tp` immediately before each source file, so | |
| /// inputs such as `.cc` are compiled as C++ rather than assumed to be | |
| /// On MSVC this also passes `-Tp` immediately before each `.cc` source file to ensure that | |
| /// they are compiled as C++ rather than assumed to be |
There was a problem hiding this comment.
updated the cpp() docs to match
Address review: cl.exe needs -Tp only for unrecognized .cc sources. clang-cl already recognizes .cc and uses -- as a path delimiter, so -Tp must not be passed after --. Do not apply -Tp to .c or .cpp. Fixes rust-lang#1877 Co-authored-by: Cestercian <yashafaid@gmail.com>
NobodyXu
left a comment
There was a problem hiding this comment.
Thank you!
A new release is scheduled on next weekend, if you need it early, I can cut an early release
Summary
MSVC does not treat
.ccas C++. Withcpp(true), mimalloc 0.1.52 writesOUT_DIR/mimalloc-static.cc; without/TP,cl.exeassumes that file is an object (D9024) and never produces the-Fooutput (*-mimalloc-static.o).Pass
-TPon MSVC-like compilers whencpp(true).Fixes #1877
Test plan
cargo +stable test --locked --test test— 59 passed (includesmsvc_cpp_cc_source_not_treated_as_object)ccclean