Skip to content

Commit

Permalink
Refine CUDA documentation.
Browse files Browse the repository at this point in the history
Original wording gives an impression that user-provided flags are
prefixed with -Xcompiler, which is not the case. -Xcompiler is
added only to internally generated flags.
  • Loading branch information
dot-asm committed Apr 24, 2023
1 parent 52a7cb7 commit ecc60ba
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,12 @@ impl Build {

/// Set CUDA C++ support.
///
/// Enabling CUDA will pass the detected C/C++ toolchain as an argument to
/// the CUDA compiler, NVCC. NVCC itself accepts some limited GNU-like args;
/// any other arguments for the C/C++ toolchain will be redirected using
/// "-Xcompiler" flags.
/// Enabling CUDA will invoke the CUDA compiler, NVCC. While NVCC accepts
/// the most common compiler flags, e.g. `-std=c++17`, some project-specific
/// flags might have to be prefixed with "-Xcompiler" flag, for example as
/// `.flag("-Xcompiler").flag("-fpermissive")`. See the documentation for
/// `nvcc`, the CUDA compiler driver, at https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/
/// for more information.
///
/// If enabled, this also implicitly enables C++ support.
pub fn cuda(&mut self, cuda: bool) -> &mut Build {
Expand Down Expand Up @@ -3297,12 +3299,14 @@ impl Tool {
self.removed_args.push(flag);
}

/// Push a flag to the end of the compiler's arguments list.
/// Push an "exotic" flag to the end of the compiler's arguments list.
///
/// Currently `-Xcompiler` is inserted before the passed flag when compiling
/// CUDA sources since NVCC only accepts a limited set of GNU-like flags,
/// while the rest must be prefixed with the `-Xcompiler` flag to get passed
/// to the underlying C++ compiler.
/// Nvidia compiler accepts only the most common compiler flags like `-D`,
/// `-I`, `-c`, etc. Options meant specifically for the underlying
/// host C++ compiler have to be prefixed with '-Xcompiler`.
/// [Another possible future application for this function is passing
/// clang-specific flags to clang-cl, which otherwise accepts only
/// MSVC-specific options.]
fn push_cc_arg(&mut self, flag: OsString) {
if self.cuda {
self.args.push("-Xcompiler".into());
Expand Down

0 comments on commit ecc60ba

Please sign in to comment.