Skip to content

Commit

Permalink
fix: handle -Xclang args when invoking clang/clang++ on windows cmake (
Browse files Browse the repository at this point in the history
…#1500)

* fix: handle -Xclang args when invoking clang/clang++ on windows cmake
close #955
  • Loading branch information
Danielmelody authored Jan 8, 2023
1 parent 92a5678 commit 45d4783
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
37 changes: 36 additions & 1 deletion src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ impl CCompilerImpl for Clang {
}

counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
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`.
Expand All @@ -184,6 +185,7 @@ counted_array!(pub static ARGS: [ArgInfo<gcc::ArgData>; _] = [
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),
Expand Down Expand Up @@ -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");
Expand All @@ -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"];
Expand Down Expand Up @@ -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"
])
Expand Down
11 changes: 9 additions & 2 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -342,6 +343,7 @@ where
need_explicit_dep_argument_path = DepArgumentRequirePath::Provided
}
Some(ExtraHashFile(_))
| Some(PassThroughFlag)
| Some(PreprocessorArgumentFlag)
| Some(PreprocessorArgument(_))
| Some(PreprocessorArgumentPath(_))
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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!(),
},
Expand All @@ -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));
Expand Down
1 change: 1 addition & 0 deletions src/compiler/msvc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ pub fn parse_arguments(
| Some(DiagnosticsColorFlag)
| Some(NoDiagnosticsColorFlag)
| Some(Arch(_))
| Some(PassThroughFlag)
| Some(PassThrough(_))
| Some(PassThroughPath(_))
| Some(PedanticFlag)
Expand Down

0 comments on commit 45d4783

Please sign in to comment.