diff --git a/src/compiler/compiler.rs b/src/compiler/compiler.rs index 7f5e0a0bd..66f902ca2 100644 --- a/src/compiler/compiler.rs +++ b/src/compiler/compiler.rs @@ -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 diff --git a/src/compiler/nvcc.rs b/src/compiler/nvcc.rs index f3e9fdda3..198b7ab29 100644 --- a/src/compiler/nvcc.rs +++ b/src/compiler/nvcc.rs @@ -282,6 +282,14 @@ mod test { } .parse_arguments(&arguments, ".".as_ref()) } + fn parse_arguments_msvc(arguments: Vec) -> CompilerArguments { + let arguments = arguments.iter().map(OsString::from).collect::>(); + Nvcc { + host_compiler: NvccHostCompiler::Msvc, + version: None, + } + .parse_arguments(&arguments, ".".as_ref()) + } fn parse_arguments_nvc(arguments: Vec) -> CompilerArguments { let arguments = arguments.iter().map(OsString::from).collect::>(); Nvcc { @@ -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(), )* ]) { @@ -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"); @@ -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"]) @@ -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"])