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

Make is_flag_supported_inner take an &Tool instead of a &Path #1337

Merged
merged 1 commit into from
Jan 1, 2025
Merged
Show file tree
Hide file tree
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
17 changes: 5 additions & 12 deletions src/flags.rs
Original file line number Diff line number Diff line change
@@ -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> {
Expand Down Expand Up @@ -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<OsString>,
) {
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",
Expand Down
16 changes: 6 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,19 +645,19 @@ impl Build {
pub fn is_flag_supported(&self, flag: impl AsRef<OsStr>) -> Result<bool, Error> {
self.is_flag_supported_inner(
flag.as_ref(),
self.get_base_compiler()?.path(),
&self.get_base_compiler()?,
&self.get_target()?,
)
}

fn is_flag_supported_inner(
&self,
flag: &OsStr,
compiler_path: &Path,
tool: &Tool,
target: &TargetInfo<'_>,
) -> Result<bool, Error> {
let compiler_flag = CompilerFlag {
compiler: compiler_path.into(),
compiler: tool.path().into(),
flag: flag.into(),
};

Expand All @@ -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)
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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(())
}

Expand Down
Loading