Skip to content

Commit 385228f

Browse files
authored
Avoid recursive calls into try_get_compiler when items are in the cache (#1050)
1 parent d864140 commit 385228f

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

src/lib.rs

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -601,26 +601,17 @@ impl Build {
601601
/// `known_flag_support` field. If `is_flag_supported(flag)`
602602
/// is called again, the result will be read from the hash table.
603603
pub fn is_flag_supported(&self, flag: &str) -> Result<bool, Error> {
604-
let target = self.get_target()?;
605-
606-
let mut compiler = {
607-
let mut cfg = Build::new();
608-
cfg.flag(flag)
609-
.cargo_metadata(self.cargo_output.metadata)
610-
.target(&target)
611-
.opt_level(0)
612-
.host(&self.get_host()?)
613-
.debug(false)
614-
.cpp(self.cpp)
615-
.cuda(self.cuda);
616-
if let Some(ref c) = self.compiler {
617-
cfg.compiler(c.clone());
618-
}
619-
cfg.try_get_compiler()?
620-
};
604+
self.is_flag_supported_inner(flag, self.get_base_compiler()?.path(), &self.get_target()?)
605+
}
621606

607+
fn is_flag_supported_inner(
608+
&self,
609+
flag: &str,
610+
compiler_path: &Path,
611+
target: &str,
612+
) -> Result<bool, Error> {
622613
let compiler_flag = CompilerFlag {
623-
compiler: compiler.path.clone().into(),
614+
compiler: compiler_path.into(),
624615
flag: flag.into(),
625616
};
626617

@@ -638,6 +629,20 @@ impl Build {
638629
let src = self.ensure_check_file()?;
639630
let obj = out_dir.join("flag_check");
640631

632+
let mut compiler = {
633+
let mut cfg = Build::new();
634+
cfg.flag(flag)
635+
.compiler(compiler_path)
636+
.cargo_metadata(self.cargo_output.metadata)
637+
.target(target)
638+
.opt_level(0)
639+
.host(&self.get_host()?)
640+
.debug(false)
641+
.cpp(self.cpp)
642+
.cuda(self.cuda);
643+
cfg.try_get_compiler()?
644+
};
645+
641646
// Clang uses stderr for verbose output, which yields a false positive
642647
// result if the CFLAGS/CXXFLAGS include -v to aid in debugging.
643648
if compiler.family.verbose_stderr() {
@@ -1803,7 +1808,10 @@ impl Build {
18031808
}
18041809

18051810
for flag in self.flags_supported.iter() {
1806-
if self.is_flag_supported(flag).unwrap_or(false) {
1811+
if self
1812+
.is_flag_supported_inner(flag, &cmd.path, &target)
1813+
.unwrap_or(false)
1814+
{
18071815
cmd.push_cc_arg((**flag).into());
18081816
}
18091817
}

0 commit comments

Comments
 (0)