rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.79k stars 434 forks source link

Add independent flags to C or C++ files #1019

Open varphone opened 4 months ago

varphone commented 4 months ago

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:

  1. Add Build::c_flag() and Build::cpp_flag() methods to add independent flags to C or C++ files.
  2. Add src argument to Tool::to_command() method to auto-detect c/cpp compiler by source file extension for Clang/Gnu toolset.