diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d6b33b..a6765006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +- Include compiler wrapper arguments (i.e., `CC=compiler arg1 arg2`) in the classification of compilers' tool family. This fixes cases like `clang --driver-mode=cl` being incorrectly detected as needing `clang`-like arguments, rather than `cl`-like arguments. [#????](https://github.com/rust-lang/cc-rs/????). + ## [1.2.10](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.9...cc-v1.2.10) - 2025-01-17 ### Other diff --git a/src/tool.rs b/src/tool.rs index 953e082c..f1126461 100644 --- a/src/tool.rs +++ b/src/tool.rs @@ -16,7 +16,7 @@ use crate::{ Error, ErrorKind, OutputKind, }; -pub(crate) type CompilerFamilyLookupCache = HashMap, ToolFamily>; +pub(crate) type CompilerFamilyLookupCache = HashMap, ToolFamily>; /// Configuration used to represent an invocation of a C compiler. /// @@ -116,21 +116,25 @@ impl Tool { fn guess_family_from_stdout( stdout: &str, path: &Path, + args: &[String], cargo_output: &CargoOutput, ) -> Result { cargo_output.print_debug(&stdout); // https://gitlab.kitware.com/cmake/cmake/-/blob/69a2eeb9dff5b60f2f1e5b425002a0fd45b7cadb/Modules/CMakeDetermineCompilerId.cmake#L267-271 // stdin is set to null to ensure that the help output is never paginated. - let accepts_cl_style_flags = - run(Command::new(path).arg("-?").stdin(Stdio::null()), path, &{ + let accepts_cl_style_flags = run( + Command::new(path).args(args).arg("-?").stdin(Stdio::null()), + path, + &{ // the errors are not errors! let mut cargo_output = cargo_output.clone(); cargo_output.warnings = cargo_output.debug; cargo_output.output = OutputKind::Discard; cargo_output - }) - .is_ok(); + }, + ) + .is_ok(); let clang = stdout.contains(r#""clang""#); let gcc = stdout.contains(r#""gcc""#); @@ -155,6 +159,7 @@ impl Tool { fn detect_family_inner( path: &Path, + args: &[String], cargo_output: &CargoOutput, out_dir: Option<&Path>, ) -> Result { @@ -209,25 +214,30 @@ impl Tool { &compiler_detect_output, )?; let stdout = String::from_utf8_lossy(&stdout); - guess_family_from_stdout(&stdout, path, cargo_output) + guess_family_from_stdout(&stdout, path, args, cargo_output) } else { - guess_family_from_stdout(&stdout, path, cargo_output) + guess_family_from_stdout(&stdout, path, args, cargo_output) } } - let detect_family = |path: &Path| -> Result { - if let Some(family) = cached_compiler_family.read().unwrap().get(path) { + let detect_family = |path: &Path, args: &[String]| -> Result { + let cache_key = [path] + .iter() + .map(|p| p.as_os_str().to_owned()) + .chain(args.iter().map(|a| OsStr::new(a).to_owned())) + .collect(); + if let Some(family) = cached_compiler_family.read().unwrap().get(&cache_key) { return Ok(*family); } - let family = detect_family_inner(path, cargo_output, out_dir)?; + let family = { detect_family_inner(path, args, cargo_output, out_dir)? }; cached_compiler_family .write() .unwrap() - .insert(path.into(), family); + .insert(cache_key, family); Ok(family) }; - let family = detect_family(&path).unwrap_or_else(|e| { + let family = detect_family(&path, &args).unwrap_or_else(|e| { cargo_output.print_warning(&format_args!( "Compiler family detection failed due to error: {}", e