From 45d47834820125d825b2a6abe50c850bbcca2769 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Jan 2023 19:36:55 +0800 Subject: [PATCH] fix: handle -Xclang args when invoking clang/clang++ on windows cmake (#1500) * fix: handle -Xclang args when invoking clang/clang++ on windows cmake close #955 --- src/compiler/clang.rs | 37 ++++++++++++++++++++++++++++++++++++- src/compiler/gcc.rs | 11 +++++++++-- src/compiler/msvc.rs | 1 + 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index d5cd32259..268f3f456 100644 --- a/src/compiler/clang.rs +++ b/src/compiler/clang.rs @@ -159,6 +159,7 @@ impl CCompilerImpl for Clang { } counted_array!(pub static ARGS: [ArgInfo; _] = [ + take_arg!("--dependent-lib", OsString, Concatenated('='), PassThrough), take_arg!("--serialize-diagnostics", OsString, Separated, PassThrough), take_arg!("--target", OsString, Separated, PassThrough), // Note: for clang we must override the dep options from gcc.rs with `CanBeSeparated`. @@ -184,6 +185,7 @@ counted_array!(pub static ARGS: [ArgInfo; _] = [ take_arg!("-fprofile-use", PathBuf, Concatenated('='), ClangProfileUse), take_arg!("-fsanitize-blacklist", PathBuf, Concatenated('='), ExtraHashFile), take_arg!("-gcc-toolchain", OsString, Separated, PassThrough), + flag!("-gcodeview", PassThroughFlag), take_arg!("-include-pch", PathBuf, CanBeSeparated, PreprocessorArgumentPath), take_arg!("-load", PathBuf, Separated, ExtraHashFile), take_arg!("-mllvm", OsString, Separated, PassThrough), @@ -297,6 +299,31 @@ mod test { assert_eq!(ovec!["-arch", "xyz"], a.arch_args); } + #[test] + fn test_dependent_lib() { + let a = parses!( + "-c", + "foo.c", + "-o", + "foo.o", + "-Xclang", + "--dependent-lib=msvcrt" + ); + assert_eq!(Some("foo.c"), a.input.to_str()); + assert_eq!(Language::C, a.language); + assert_map_contains!( + a.outputs, + ( + "obj", + ArtifactDescriptor { + path: PathBuf::from("foo.o"), + optional: false + } + ) + ); + assert_eq!(ovec!["-Xclang", "--dependent-lib=msvcrt"], a.common_args); + } + #[test] fn test_parse_arguments_others() { parses!("-c", "foo.c", "-B", "somewhere", "-o", "foo.o"); @@ -311,6 +338,11 @@ mod test { parses!("-c", "foo.c", "-gcc-toolchain", "somewhere", "-o", "foo.o"); } + #[test] + fn test_gcodeview() { + parses!("-c", "foo.c", "-o", "foo.o", "-Xclang", "-gcodeview"); + } + #[test] fn test_parse_clang_short_dependency_arguments_can_be_separated() { let args = vec!["-MF", "-MT", "-MQ"]; @@ -352,7 +384,10 @@ mod test { ]) ); assert_eq!( - CompilerArguments::CannotCache("Can't handle UnknownFlag arguments with -Xclang", None), + CompilerArguments::CannotCache( + "Can't handle UnknownFlag arguments with -Xclang", + Some("-broken".to_string()) + ), parse_arguments_(stringvec![ "-c", "foo.c", "-o", "foo.o", "-Xclang", "-broken" ]) diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index 23aef9ed1..218b8d364 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -113,6 +113,7 @@ ArgData! { pub NoDiagnosticsColorFlag, // Should only be necessary for -Xclang flags - unknown flags not hidden behind // that are assumed to not affect compilation + PassThroughFlag, PassThrough(OsString), PassThroughPath(PathBuf), PreprocessorArgumentFlag, @@ -342,6 +343,7 @@ where need_explicit_dep_argument_path = DepArgumentRequirePath::Provided } Some(ExtraHashFile(_)) + | Some(PassThroughFlag) | Some(PreprocessorArgumentFlag) | Some(PreprocessorArgument(_)) | Some(PreprocessorArgumentPath(_)) @@ -382,6 +384,7 @@ where | Some(DiagnosticsColor(_)) | Some(DiagnosticsColorFlag) | Some(NoDiagnosticsColorFlag) + | Some(PassThroughFlag) | Some(PassThrough(_)) | Some(PassThroughPath(_)) => &mut common_args, Some(Arch(_)) => &mut arch_args, @@ -436,8 +439,11 @@ where None => match arg { Argument::Raw(_) if follows_plugin_arg => &mut common_args, Argument::Raw(_) => cannot_cache!("Can't handle Raw arguments with -Xclang"), - Argument::UnknownFlag(_) => { - cannot_cache!("Can't handle UnknownFlag arguments with -Xclang") + Argument::UnknownFlag(flag) => { + cannot_cache!( + "Can't handle UnknownFlag arguments with -Xclang", + flag.to_str().unwrap_or("").to_string() + ) } _ => unreachable!(), }, @@ -446,6 +452,7 @@ where | Some(NoDiagnosticsColorFlag) | Some(Arch(_)) | Some(PassThrough(_)) + | Some(PassThroughFlag) | Some(PassThroughPath(_)) => &mut common_args, Some(ExtraHashFile(path)) => { extra_hash_files.push(cwd.join(path)); diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 78d4948a4..c973861f5 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -700,6 +700,7 @@ pub fn parse_arguments( | Some(DiagnosticsColorFlag) | Some(NoDiagnosticsColorFlag) | Some(Arch(_)) + | Some(PassThroughFlag) | Some(PassThrough(_)) | Some(PassThroughPath(_)) | Some(PedanticFlag)