Skip to content

Commit

Permalink
Address feedback of code-review.
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard authored and sylvestre committed Sep 28, 2023
1 parent 1ac4a0c commit 8253364
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,8 @@ where
//
// We prefix the information we need with `compiler_id` and `compiler_version`
// so that we can support compilers that insert pre-amble code even in `-E` mode
let test = b"#if defined(__NVCC__) && defined(__NVCOMPILER)
let test = b"
#if defined(__NVCC__) && defined(__NVCOMPILER)
compiler_id=nvcc-nvhpc
#elif defined(__NVCC__) && defined(_MSC_VER)
compiler_id=nvcc-msvc
Expand Down
42 changes: 42 additions & 0 deletions src/compiler/nvcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ mod test {
}
.parse_arguments(&arguments, ".".as_ref())
}
fn parse_arguments_msvc(arguments: Vec<String>) -> CompilerArguments<ParsedArguments> {
let arguments = arguments.iter().map(OsString::from).collect::<Vec<_>>();
Nvcc {
host_compiler: NvccHostCompiler::Msvc,
version: None,
}
.parse_arguments(&arguments, ".".as_ref())
}
fn parse_arguments_nvc(arguments: Vec<String>) -> CompilerArguments<ParsedArguments> {
let arguments = arguments.iter().map(OsString::from).collect::<Vec<_>>();
Nvcc {
Expand All @@ -299,6 +307,14 @@ mod test {
}
}
}
macro_rules! parses_msvc {
( $( $s:expr ),* ) => {
match parse_arguments_msvc(vec![ $( $s.to_string(), )* ]) {
CompilerArguments::Ok(a) => a,
o => panic!("Got unexpected parse result: {:?}", o),
}
}
}
macro_rules! parses_nvc {
( $( $s:expr ),* ) => {
match parse_arguments_nvc(vec![ $( $s.to_string(), )* ]) {
Expand Down Expand Up @@ -365,6 +381,24 @@ mod test {
assert!(a.common_args.is_empty());
}

fn test_parse_arguments_simple_cu_msvc() {
let a = parses_msvc!("-c", "foo.cu", "-o", "foo.o");
assert_eq!(Some("foo.cu"), a.input.to_str());
assert_eq!(Language::Cuda, a.language);
assert_map_contains!(
a.outputs,
(
"obj",
ArtifactDescriptor {
path: "foo.o".into(),
optional: false
}
)
);
assert!(a.preprocessor_args.is_empty());
assert!(a.common_args.is_empty());
}

#[test]
fn test_parse_arguments_ccbin_no_path() {
let a = parses!("-ccbin=gcc", "-c", "foo.cu", "-o", "foo.o");
Expand Down Expand Up @@ -737,6 +771,10 @@ mod test {
CompilerArguments::CannotCache("-E", None),
parse_arguments_gcc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-E"])
);
assert_eq!(
CompilerArguments::CannotCache("-E", None),
parse_arguments_msvc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-E"])
);
assert_eq!(
CompilerArguments::CannotCache("-E", None),
parse_arguments_nvc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-E"])
Expand All @@ -746,6 +784,10 @@ mod test {
CompilerArguments::CannotCache("-M", None),
parse_arguments_gcc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-M"])
);
assert_eq!(
CompilerArguments::CannotCache("-M", None),
parse_arguments_msvc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-M"])
);
assert_eq!(
CompilerArguments::CannotCache("-M", None),
parse_arguments_nvc(stringvec!["-x", "cu", "-c", "foo.c", "-o", "foo.o", "-M"])
Expand Down

0 comments on commit 8253364

Please sign in to comment.