-
Notifications
You must be signed in to change notification settings - Fork 453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add independent flags to C or C++ files #1019
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that the c_flags
and cpp_flags
are ignored for msvc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to do this in get_base_compiler
, there are some functions which call it directly.
Signed-off-by: Varphone Wong <[email protected]>
…lset Signed-off-by: Varphone Wong <[email protected]>
/// | ||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.src
argument toTool::to_command()
method to auto-detect c/cpp compiler by source file extension for Clang/Gnu toolset.