Skip to content

Commit

Permalink
fix: hanlde -Xclang args when invoking clang/clang++ on windows cmake
Browse files Browse the repository at this point in the history
close #955
  • Loading branch information
Danielmelody committed Dec 26, 2022
1 parent 6f1d529 commit 04e55cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
23 changes: 22 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", PreprocessorArgumentFlag),
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,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");
Expand Down Expand Up @@ -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"
])
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
},
Expand Down

0 comments on commit 04e55cb

Please sign in to comment.