Add independent flags to C or C++ files#1019
Add independent flags to C or C++ files#1019varphone wants to merge 2 commits intorust-lang:mainfrom
Conversation
NobodyXu
left a comment
There was a problem hiding this comment.
Thank you!
There are a few things I'd like you to change.
Also, can you add some tests for this functionality in tests/test.rs please?
| extra_args = &self.cpp_args; | ||
| } | ||
| } | ||
| _ => {} |
There was a problem hiding this comment.
It seems that the c_flags and cpp_flags are ignored for msvc?
There was a problem hiding this comment.
MSVC has only one cl.exe and has no special parameters for C or C++, so it can be ignored.
There was a problem hiding this comment.
It doesn't have -std=c11 which is used in example?
| /// .cpp_flag("-std=c++17") | ||
| /// .compile("foo"); | ||
| /// ``` | ||
| pub fn cpp_flag(&mut self, flag: &str) -> &mut Build { |
There was a problem hiding this comment.
I think cxx_flags makes more sense.
cpp could be confused with pre-processors of C/C++ compiler.
| for flag in self.c_flags.iter() { | ||
| cmd.c_args.push((**flag).into()); | ||
| } | ||
|
|
||
| for flag in self.cpp_flags.iter() { | ||
| cmd.cpp_args.push((**flag).into()); | ||
| } | ||
|
|
There was a problem hiding this comment.
I think you need to do this in get_base_compiler, there are some functions which call it directly.
Signed-off-by: Varphone Wong <varphone@qq.com>
…lset Signed-off-by: Varphone Wong <varphone@qq.com>
| /// | ||
| /// The `src` argument is used to determine the preferred compiler for the | ||
| /// source file. If `None`, the default compiler is used. | ||
| pub fn to_command(&self, src: Option<&PathBuf>) -> Command { |
There was a problem hiding this comment.
This is breaking change, please move this to a new function.
This PR introduces a new feature for C/C++ flags, primarily to support the compilation of mixed C/C++ code.
Sometimes we use both C and C++ languages in a single project. However, the compilers for C and C++ are different, so we need to specify different compilers during compilation. This PR adds independent compiler flags for C and C++ files, allowing us to specify different compilers during compilation.
The main changes in this PR are as follows:
Build::c_flag()andBuild::cpp_flag()methods to add independent flags to C or C++ files.srcargument toTool::to_command()method to auto-detect c/cpp compiler by source file extension for Clang/Gnu toolset.