Rename [default|extra]_cflags -> cc_[|un]handled_clags

Makes it explicit that these are in relation to the cc-rs crate.
This commit is contained in:
Mads Marquart 2025-02-05 13:44:35 +01:00
parent 9fa819ef94
commit d8e93c7e07
6 changed files with 24 additions and 18 deletions

View file

@ -1582,8 +1582,8 @@ pub fn compiler_file(
return PathBuf::new();
}
let mut cmd = command(compiler);
cmd.args(builder.default_cflags(target, c));
cmd.args(builder.extra_cflags(target, GitRepo::Rustc, c));
cmd.args(builder.cc_handled_clags(target, c));
cmd.args(builder.cc_unhandled_cflags(target, GitRepo::Rustc, c));
cmd.arg(format!("-print-file-name={file}"));
let out = cmd.run_capture_stdout(builder).stdout();
PathBuf::from(out.trim())

View file

@ -763,9 +763,9 @@ fn configure_cmake(
// Needs `suppressed_compiler_flag_prefixes` to be gone, and hence
// https://github.com/llvm/llvm-project/issues/88780 to be fixed.
let mut cflags: OsString = builder
.default_cflags(target, CLang::C)
.cc_handled_clags(target, CLang::C)
.into_iter()
.chain(builder.extra_cflags(target, GitRepo::Llvm, CLang::C))
.chain(builder.cc_unhandled_cflags(target, GitRepo::Llvm, CLang::C))
.filter(|flag| {
!suppressed_compiler_flag_prefixes
.iter()
@ -784,9 +784,9 @@ fn configure_cmake(
}
cfg.define("CMAKE_C_FLAGS", cflags);
let mut cxxflags: OsString = builder
.default_cflags(target, CLang::Cxx)
.cc_handled_clags(target, CLang::Cxx)
.into_iter()
.chain(builder.extra_cflags(target, GitRepo::Llvm, CLang::Cxx))
.chain(builder.cc_unhandled_cflags(target, GitRepo::Llvm, CLang::Cxx))
.filter(|flag| {
!suppressed_compiler_flag_prefixes
.iter()

View file

@ -2005,10 +2005,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
// Only pass correct values for these flags for the `run-make` suite as it
// requires that a C++ compiler was configured which isn't always the case.
if !builder.config.dry_run() && mode == "run-make" {
let mut cflags = builder.default_cflags(target, CLang::C);
cflags.extend(builder.extra_cflags(target, GitRepo::Rustc, CLang::C));
let mut cxxflags = builder.default_cflags(target, CLang::Cxx);
cxxflags.extend(builder.extra_cflags(target, GitRepo::Rustc, CLang::Cxx));
let mut cflags = builder.cc_handled_clags(target, CLang::C);
cflags.extend(builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C));
let mut cxxflags = builder.cc_handled_clags(target, CLang::Cxx);
cxxflags.extend(builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx));
cmd.arg("--cc")
.arg(builder.cc(target))
.arg("--cxx")

View file

@ -317,7 +317,7 @@ impl Cargo {
let cc = ccacheify(&builder.cc(target));
self.command.env(format!("CC_{triple_underscored}"), &cc);
let cflags = builder.extra_cflags(target, GitRepo::Rustc, CLang::C).join(" ");
let cflags = builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C).join(" ");
self.command.env(format!("CFLAGS_{triple_underscored}"), &cflags);
if let Some(ar) = builder.ar(target) {
@ -329,7 +329,8 @@ impl Cargo {
if let Ok(cxx) = builder.cxx(target) {
let cxx = ccacheify(&cxx);
let cxxflags = builder.extra_cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
let cxxflags =
builder.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx).join(" ");
self.command
.env(format!("CXX_{triple_underscored}"), &cxx)
.env(format!("CXXFLAGS_{triple_underscored}"), cxxflags);

View file

@ -1142,7 +1142,7 @@ Executed at: {executed_at}"#,
/// Returns C flags that `cc-rs` thinks should be enabled for the
/// specified target by default.
fn default_cflags(&self, target: TargetSelection, c: CLang) -> Vec<String> {
fn cc_handled_clags(&self, target: TargetSelection, c: CLang) -> Vec<String> {
if self.config.dry_run() {
return Vec::new();
}
@ -1161,7 +1161,12 @@ Executed at: {executed_at}"#,
}
/// Returns extra C flags that `cc-rs` doesn't handle.
fn extra_cflags(&self, target: TargetSelection, which: GitRepo, c: CLang) -> Vec<String> {
fn cc_unhandled_cflags(
&self,
target: TargetSelection,
which: GitRepo,
c: CLang,
) -> Vec<String> {
let mut base = Vec::new();
// If we're compiling C++ on macOS then we add a flag indicating that

View file

@ -142,8 +142,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
};
build.cc.borrow_mut().insert(target, compiler.clone());
let mut cflags = build.default_cflags(target, CLang::C);
cflags.extend(build.extra_cflags(target, GitRepo::Rustc, CLang::C));
let mut cflags = build.cc_handled_clags(target, CLang::C);
cflags.extend(build.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::C));
// If we use llvm-libunwind, we will need a C++ compiler as well for all targets
// We'll need one anyways if the target triple is also a host triple
@ -169,8 +169,8 @@ pub fn find_target(build: &Build, target: TargetSelection) {
build.verbose(|| println!("CC_{} = {:?}", target.triple, build.cc(target)));
build.verbose(|| println!("CFLAGS_{} = {cflags:?}", target.triple));
if let Ok(cxx) = build.cxx(target) {
let mut cxxflags = build.default_cflags(target, CLang::Cxx);
cxxflags.extend(build.extra_cflags(target, GitRepo::Rustc, CLang::Cxx));
let mut cxxflags = build.cc_handled_clags(target, CLang::Cxx);
cxxflags.extend(build.cc_unhandled_cflags(target, GitRepo::Rustc, CLang::Cxx));
build.verbose(|| println!("CXX_{} = {cxx:?}", target.triple));
build.verbose(|| println!("CXXFLAGS_{} = {cxxflags:?}", target.triple));
}