From 160ccd8192a8535d23ae402c34ded4c391bf3b47 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 26 Dec 2022 22:26:47 +0800 Subject: [PATCH 1/4] fix: handle -Xclang args when invoking clang/clang++ on windows cmake close #955 --- src/compiler/clang.rs | 23 ++++++++++++++++++++++- src/compiler/gcc.rs | 4 ++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index d5cd32259..e909d9ebc 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", PreprocessorArgumentFlag), take_arg!("-include-pch", PathBuf, CanBeSeparated, PreprocessorArgumentPath), take_arg!("-load", PathBuf, Separated, ExtraHashFile), take_arg!("-mllvm", OsString, Separated, PassThrough), @@ -297,6 +299,25 @@ 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); + // assert!(a.common_args.is_empty()); + } + #[test] fn test_parse_arguments_others() { parses!("-c", "foo.c", "-B", "somewhere", "-o", "foo.o"); @@ -352,7 +373,7 @@ 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..71aa5606f 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -436,8 +436,8 @@ 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!(), }, From dfa11c96a8b75b8b225766f3bd27c263c77509fa Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 26 Dec 2022 22:52:22 +0800 Subject: [PATCH 2/4] test: add test for -gcodeview --- src/compiler/clang.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index e909d9ebc..11b62c140 100644 --- a/src/compiler/clang.rs +++ b/src/compiler/clang.rs @@ -315,7 +315,6 @@ mod test { ) ); assert_eq!(ovec!["-Xclang", "--dependent-lib=msvcrt"], a.common_args); - // assert!(a.common_args.is_empty()); } #[test] @@ -332,6 +331,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"]; From 6618b2d0bf0435890209905835e9702c5834a0ca Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 28 Dec 2022 16:52:03 +0800 Subject: [PATCH 3/4] fix: identify gcodeview as PassThroughFlag --- src/compiler/clang.rs | 2 +- src/compiler/gcc.rs | 4 ++++ src/compiler/msvc.rs | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index 11b62c140..0d0206871 100644 --- a/src/compiler/clang.rs +++ b/src/compiler/clang.rs @@ -185,7 +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", PreprocessorArgumentFlag), + flag!("-gcodeview", PassThroughFlag), take_arg!("-include-pch", PathBuf, CanBeSeparated, PreprocessorArgumentPath), take_arg!("-load", PathBuf, Separated, ExtraHashFile), take_arg!("-mllvm", OsString, Separated, PassThrough), diff --git a/src/compiler/gcc.rs b/src/compiler/gcc.rs index 71aa5606f..51f323359 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, @@ -446,6 +449,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..5ed1ba117 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -700,7 +700,8 @@ pub fn parse_arguments( | Some(DiagnosticsColorFlag) | Some(NoDiagnosticsColorFlag) | Some(Arch(_)) - | Some(PassThrough(_)) + | Some(PassThroughFlag) + | Some(PassThrough(_)) | Some(PassThroughPath(_)) | Some(PedanticFlag) | Some(Standard(_)) => &mut common_args, From e574490fee246c969064dc79b53da9f7e1586bc4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 28 Dec 2022 18:11:17 +0800 Subject: [PATCH 4/4] style: format code --- src/compiler/clang.rs | 14 ++++++++++++-- src/compiler/gcc.rs | 5 ++++- src/compiler/msvc.rs | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/compiler/clang.rs b/src/compiler/clang.rs index 0d0206871..268f3f456 100644 --- a/src/compiler/clang.rs +++ b/src/compiler/clang.rs @@ -301,7 +301,14 @@ mod test { #[test] fn test_dependent_lib() { - let a = parses!("-c", "foo.c", "-o", "foo.o", "-Xclang", "--dependent-lib=msvcrt"); + 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!( @@ -377,7 +384,10 @@ mod test { ]) ); assert_eq!( - CompilerArguments::CannotCache("Can't handle UnknownFlag arguments with -Xclang", Some("-broken".to_string())), + 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 51f323359..218b8d364 100644 --- a/src/compiler/gcc.rs +++ b/src/compiler/gcc.rs @@ -440,7 +440,10 @@ where Argument::Raw(_) if follows_plugin_arg => &mut common_args, Argument::Raw(_) => cannot_cache!("Can't handle Raw arguments with -Xclang"), Argument::UnknownFlag(flag) => { - cannot_cache!("Can't handle UnknownFlag arguments with -Xclang", flag.to_str().unwrap_or("").to_string()) + cannot_cache!( + "Can't handle UnknownFlag arguments with -Xclang", + flag.to_str().unwrap_or("").to_string() + ) } _ => unreachable!(), }, diff --git a/src/compiler/msvc.rs b/src/compiler/msvc.rs index 5ed1ba117..c973861f5 100644 --- a/src/compiler/msvc.rs +++ b/src/compiler/msvc.rs @@ -701,7 +701,7 @@ pub fn parse_arguments( | Some(NoDiagnosticsColorFlag) | Some(Arch(_)) | Some(PassThroughFlag) - | Some(PassThrough(_)) + | Some(PassThrough(_)) | Some(PassThroughPath(_)) | Some(PedanticFlag) | Some(Standard(_)) => &mut common_args,