Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid recursive calls into try_get_compiler when items are in the cache #1050

Merged
merged 1 commit into from
May 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,26 +601,17 @@ impl Build {
/// `known_flag_support` field. If `is_flag_supported(flag)`
/// is called again, the result will be read from the hash table.
pub fn is_flag_supported(&self, flag: &str) -> Result<bool, Error> {
let target = self.get_target()?;

let mut compiler = {
let mut cfg = Build::new();
cfg.flag(flag)
.cargo_metadata(self.cargo_output.metadata)
.target(&target)
.opt_level(0)
.host(&self.get_host()?)
.debug(false)
.cpp(self.cpp)
.cuda(self.cuda);
if let Some(ref c) = self.compiler {
cfg.compiler(c.clone());
}
cfg.try_get_compiler()?
};
self.is_flag_supported_inner(flag, self.get_base_compiler()?.path(), &self.get_target()?)
NobodyXu marked this conversation as resolved.
Show resolved Hide resolved
}

fn is_flag_supported_inner(
&self,
flag: &str,
compiler_path: &Path,
target: &str,
) -> Result<bool, Error> {
let compiler_flag = CompilerFlag {
compiler: compiler.path.clone().into(),
compiler: compiler_path.into(),
flag: flag.into(),
};

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

let mut compiler = {
let mut cfg = Build::new();
cfg.flag(flag)
.compiler(compiler_path)
.cargo_metadata(self.cargo_output.metadata)
.target(target)
.opt_level(0)
.host(&self.get_host()?)
.debug(false)
.cpp(self.cpp)
.cuda(self.cuda);
cfg.try_get_compiler()?
};

// Clang uses stderr for verbose output, which yields a false positive
// result if the CFLAGS/CXXFLAGS include -v to aid in debugging.
if compiler.family.verbose_stderr() {
Expand Down Expand Up @@ -1805,7 +1810,10 @@ impl Build {
}

for flag in self.flags_supported.iter() {
if self.is_flag_supported(flag).unwrap_or(false) {
if self
.is_flag_supported_inner(flag, &cmd.path, &target)
.unwrap_or(false)
{
cmd.push_cc_arg((**flag).into());
}
}
Expand Down