Skip to content

Commit cfa61d1

Browse files
authored
Make is_flag_supported_inner take an &Tool (#1337)
1 parent 05a529c commit cfa61d1

File tree

2 files changed

+11
-22
lines changed

2 files changed

+11
-22
lines changed

src/flags.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::target::TargetInfo;
2-
use crate::{Build, Error, ErrorKind, ToolFamily};
2+
use crate::{Build, Error, ErrorKind, Tool, ToolFamily};
33
use std::borrow::Cow;
44
use std::ffi::OsString;
5-
use std::path::Path;
65

76
#[derive(Debug, PartialEq, Default)]
87
pub(crate) struct RustcCodegenFlags<'a> {
@@ -158,21 +157,15 @@ impl<'this> RustcCodegenFlags<'this> {
158157
}
159158

160159
// Rust and clang/cc don't agree on what equivalent flags should look like.
161-
pub(crate) fn cc_flags(
162-
&self,
163-
build: &Build,
164-
path: &Path,
165-
family: ToolFamily,
166-
target: &TargetInfo,
167-
flags: &mut Vec<OsString>,
168-
) {
160+
pub(crate) fn cc_flags(&self, build: &Build, tool: &mut Tool, target: &TargetInfo) {
161+
let family = tool.family;
169162
// Push `flag` to `flags` if it is supported by the currently used CC
170163
let mut push_if_supported = |flag: OsString| {
171164
if build
172-
.is_flag_supported_inner(&flag, path, target)
165+
.is_flag_supported_inner(&flag, tool, target)
173166
.unwrap_or(false)
174167
{
175-
flags.push(flag);
168+
tool.args.push(flag);
176169
} else {
177170
build.cargo_output.print_warning(&format!(
178171
"Inherited flag {:?} is not supported by the currently used CC",

src/lib.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -645,19 +645,19 @@ impl Build {
645645
pub fn is_flag_supported(&self, flag: impl AsRef<OsStr>) -> Result<bool, Error> {
646646
self.is_flag_supported_inner(
647647
flag.as_ref(),
648-
self.get_base_compiler()?.path(),
648+
&self.get_base_compiler()?,
649649
&self.get_target()?,
650650
)
651651
}
652652

653653
fn is_flag_supported_inner(
654654
&self,
655655
flag: &OsStr,
656-
compiler_path: &Path,
656+
tool: &Tool,
657657
target: &TargetInfo<'_>,
658658
) -> Result<bool, Error> {
659659
let compiler_flag = CompilerFlag {
660-
compiler: compiler_path.into(),
660+
compiler: tool.path().into(),
661661
flag: flag.into(),
662662
};
663663

@@ -679,7 +679,7 @@ impl Build {
679679
let mut compiler = {
680680
let mut cfg = Build::new();
681681
cfg.flag(flag)
682-
.compiler(compiler_path)
682+
.compiler(tool.path())
683683
.cargo_metadata(self.cargo_output.metadata)
684684
.opt_level(0)
685685
.debug(false)
@@ -1957,7 +1957,7 @@ impl Build {
19571957

19581958
for flag in self.flags_supported.iter() {
19591959
if self
1960-
.is_flag_supported_inner(flag, &cmd.path, &target)
1960+
.is_flag_supported_inner(flag, &cmd, &target)
19611961
.unwrap_or(false)
19621962
{
19631963
cmd.push_cc_arg((**flag).into());
@@ -2438,13 +2438,9 @@ impl Build {
24382438
None => return Ok(()),
24392439
};
24402440

2441-
let Tool {
2442-
family, path, args, ..
2443-
} = cmd;
2444-
24452441
let env = env_os.to_string_lossy();
24462442
let codegen_flags = RustcCodegenFlags::parse(&env)?;
2447-
codegen_flags.cc_flags(self, path, *family, target, args);
2443+
codegen_flags.cc_flags(self, cmd, target);
24482444
Ok(())
24492445
}
24502446

0 commit comments

Comments
 (0)