Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nvc++ and msvc as nvcc host compilers #1889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 86 additions & 33 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::compiler::gcc::Gcc;
use crate::compiler::msvc;
use crate::compiler::msvc::Msvc;
use crate::compiler::nvcc::Nvcc;
use crate::compiler::nvcc::NvccHostCompiler;
use crate::compiler::rust::{Rust, RustupProxy};
use crate::compiler::tasking_vx::TaskingVX;
#[cfg(feature = "dist-client")]
Expand Down Expand Up @@ -1082,32 +1083,40 @@ where
// Both clang and clang-cl define _MSC_VER on Windows, so we first
// check for MSVC, then check whether _MT is defined, which is the
// difference between clang and clang-cl.
let test = b"#if defined(__NVCC__)
nvcc
//
// 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)
compiler_id=nvcc-nvhpc
#elif defined(__NVCC__) && defined(_MSC_VER)
compiler_id=nvcc-msvc
#elif defined(__NVCC__)
compiler_id=nvcc
#elif defined(_MSC_VER) && !defined(__clang__)
msvc
compiler_id=msvc
#elif defined(_MSC_VER) && defined(_MT)
msvc-clang
compiler_id=msvc-clang
#elif defined(__clang__) && defined(__cplusplus) && defined(__apple_build_version__)
apple-clang++
compiler_id=apple-clang++
#elif defined(__clang__) && defined(__cplusplus)
clang++
compiler_id=clang++
#elif defined(__clang__) && defined(__apple_build_version__)
apple-clang
compiler_id=apple-clang
#elif defined(__clang__)
clang
compiler_id=clang
#elif defined(__GNUC__) && defined(__cplusplus)
g++
compiler_id=g++
#elif defined(__GNUC__)
gcc
compiler_id=gcc
#elif defined(__DCC__)
diab
compiler_id=diab
#elif defined(__CTC__)
tasking_vx
compiler_id=tasking_vx
#else
unknown
compiler_id=unknown
#endif
__VERSION__
compiler_version=__VERSION__
"
.to_vec();
let (tempdir, src) = write_temp_file(&pool, "testfile.c".as_ref(), test).await?;
Expand Down Expand Up @@ -1144,10 +1153,12 @@ __VERSION__
};
let mut lines = stdout.lines().filter_map(|line| {
let line = line.trim();
if line.is_empty() || line.starts_with('#') {
None
if line.starts_with("compiler_id=") {
Some(line.strip_prefix("compiler_id=").unwrap())
} else if line.starts_with("compiler_version=") {
Some(line.strip_prefix("compiler_version=").unwrap())
} else {
Some(line)
None
}
});
if let Some(kind) = lines.next() {
Expand Down Expand Up @@ -1221,10 +1232,16 @@ __VERSION__
.await
.map(|c| Box::new(c) as Box<dyn Compiler<T>>);
}
"nvcc" => {
debug!("Found NVCC");
"nvcc" | "nvcc-msvc" | "nvcc-nvhpc" => {
let host_compiler = match kind {
"nvcc-nvhpc" => NvccHostCompiler::Nvhpc,
"nvcc-msvc" => NvccHostCompiler::Msvc,
"nvcc" => NvccHostCompiler::Gcc,
&_ => NvccHostCompiler::Gcc,
};
return CCompiler::new(
Nvcc {
host_compiler,
version: version.clone(),
},
executable,
Expand Down Expand Up @@ -1289,7 +1306,10 @@ mod test {
let creator = new_creator();
let runtime = single_threaded_runtime();
let pool = runtime.handle();
next_command(&creator, Ok(MockChild::new(exit_status(0), "\n\ngcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "\n\ncompiler_id=gcc", "")),
);
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
.unwrap()
Expand All @@ -1303,7 +1323,10 @@ mod test {
let creator = new_creator();
let runtime = single_threaded_runtime();
let pool = runtime.handle();
next_command(&creator, Ok(MockChild::new(exit_status(0), "clang\n", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=clang\n", "")),
);
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
.unwrap()
Expand All @@ -1326,7 +1349,10 @@ mod test {
let prefix = String::from("blah: ");
let stdout = format!("{}{}\r\n", prefix, s);
// Compiler detection output
next_command(&creator, Ok(MockChild::new(exit_status(0), "\nmsvc\n", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "\ncompiler_id=msvc\n", "")),
);
// showincludes prefix detection output
next_command(
&creator,
Expand All @@ -1345,7 +1371,10 @@ mod test {
let creator = new_creator();
let runtime = single_threaded_runtime();
let pool = runtime.handle();
next_command(&creator, Ok(MockChild::new(exit_status(0), "nvcc\n", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=nvcc\n", "")),
);
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
.unwrap()
Expand Down Expand Up @@ -1477,7 +1506,10 @@ LLVM version: 6.0",
let creator = new_creator();
let runtime = single_threaded_runtime();
let pool = runtime.handle();
next_command(&creator, Ok(MockChild::new(exit_status(0), "\ndiab\n", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "\ncompiler_id=diab\n", "")),
);
let c = detect_compiler(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
.unwrap()
Expand Down Expand Up @@ -1540,7 +1572,7 @@ LLVM version: 6.0",
let results: Vec<_> = [11, 12]
.iter()
.map(|version| {
let output = format!("clang\n\"{}.0.0\"", version);
let output = format!("compiler_id=clang\ncompiler_version=\"{}.0.0\"", version);
next_command(&creator, Ok(MockChild::new(exit_status(0), output, "")));
let c = detect_compiler(
creator.clone(),
Expand Down Expand Up @@ -1579,7 +1611,10 @@ LLVM version: 6.0",
let pool = runtime.handle();
let f = TestFixture::new();
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(creator, &f.bins[0], f.tempdir.path(), &[], &[], pool, None)
.wait()
.unwrap()
Expand All @@ -1598,7 +1633,10 @@ LLVM version: 6.0",
let storage = DiskCache::new(f.tempdir.path().join("cache"), u64::MAX, &pool);
let storage = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down Expand Up @@ -1709,7 +1747,10 @@ LLVM version: 6.0",
let storage = DiskCache::new(f.tempdir.path().join("cache"), u64::MAX, &pool);
let storage = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down Expand Up @@ -1816,7 +1857,10 @@ LLVM version: 6.0",
let storage = MockStorage::new(None);
let storage: Arc<MockStorage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down Expand Up @@ -1897,7 +1941,10 @@ LLVM version: 6.0",
let storage = MockStorage::new(Some(storage_delay));
let storage: Arc<MockStorage> = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down Expand Up @@ -1970,7 +2017,10 @@ LLVM version: 6.0",
let storage = DiskCache::new(f.tempdir.path().join("cache"), u64::MAX, &pool);
let storage = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down Expand Up @@ -2087,7 +2137,7 @@ LLVM version: 6.0",
next_command_calls(&creator, move |_| {
let mut f = File::create(&o)?;
f.write_all(b"file contents")?;
Ok(MockChild::new(exit_status(0), "gcc", ""))
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", ""))
});
let c = get_compiler_info(
creator.clone(),
Expand Down Expand Up @@ -2161,7 +2211,10 @@ LLVM version: 6.0",
let storage = DiskCache::new(f.tempdir.path().join("cache"), u64::MAX, &pool);
let storage = Arc::new(storage);
// Pretend to be GCC.
next_command(&creator, Ok(MockChild::new(exit_status(0), "gcc", "")));
next_command(
&creator,
Ok(MockChild::new(exit_status(0), "compiler_id=gcc", "")),
);
let c = get_compiler_info(
creator.clone(),
&f.bins[0],
Expand Down
Loading
Loading