diff --git a/src/flags.rs b/src/flags.rs index 7040a3d8..21a929c9 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -1,8 +1,7 @@ use crate::target::TargetInfo; -use crate::{Build, Error, ErrorKind, ToolFamily}; +use crate::{Build, Error, ErrorKind, Tool, ToolFamily}; use std::borrow::Cow; use std::ffi::OsString; -use std::path::Path; #[derive(Debug, PartialEq, Default)] pub(crate) struct RustcCodegenFlags<'a> { @@ -158,21 +157,15 @@ impl<'this> RustcCodegenFlags<'this> { } // Rust and clang/cc don't agree on what equivalent flags should look like. - pub(crate) fn cc_flags( - &self, - build: &Build, - path: &Path, - family: ToolFamily, - target: &TargetInfo, - flags: &mut Vec, - ) { + pub(crate) fn cc_flags(&self, build: &Build, tool: &mut Tool, target: &TargetInfo) { + let family = tool.family; // Push `flag` to `flags` if it is supported by the currently used CC let mut push_if_supported = |flag: OsString| { if build - .is_flag_supported_inner(&flag, path, target) + .is_flag_supported_inner(&flag, tool, target) .unwrap_or(false) { - flags.push(flag); + tool.args.push(flag); } else { build.cargo_output.print_warning(&format!( "Inherited flag {:?} is not supported by the currently used CC", diff --git a/src/lib.rs b/src/lib.rs index f371770b..4a706817 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -645,7 +645,7 @@ impl Build { pub fn is_flag_supported(&self, flag: impl AsRef) -> Result { self.is_flag_supported_inner( flag.as_ref(), - self.get_base_compiler()?.path(), + &self.get_base_compiler()?, &self.get_target()?, ) } @@ -653,11 +653,11 @@ impl Build { fn is_flag_supported_inner( &self, flag: &OsStr, - compiler_path: &Path, + tool: &Tool, target: &TargetInfo<'_>, ) -> Result { let compiler_flag = CompilerFlag { - compiler: compiler_path.into(), + compiler: tool.path().into(), flag: flag.into(), }; @@ -679,7 +679,7 @@ impl Build { let mut compiler = { let mut cfg = Build::new(); cfg.flag(flag) - .compiler(compiler_path) + .compiler(tool.path()) .cargo_metadata(self.cargo_output.metadata) .opt_level(0) .debug(false) @@ -1957,7 +1957,7 @@ impl Build { for flag in self.flags_supported.iter() { if self - .is_flag_supported_inner(flag, &cmd.path, &target) + .is_flag_supported_inner(flag, &cmd, &target) .unwrap_or(false) { cmd.push_cc_arg((**flag).into()); @@ -2438,13 +2438,9 @@ impl Build { None => return Ok(()), }; - let Tool { - family, path, args, .. - } = cmd; - let env = env_os.to_string_lossy(); let codegen_flags = RustcCodegenFlags::parse(&env)?; - codegen_flags.cc_flags(self, path, *family, target, args); + codegen_flags.cc_flags(self, cmd, target); Ok(()) }