Skip to content

Commit

Permalink
Merge branch 'main' into bug/system.rs_test_correctly_id_apple_clang
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Oct 18, 2023
2 parents 480a442 + b28d686 commit 30c576b
Show file tree
Hide file tree
Showing 18 changed files with 777 additions and 127 deletions.
21 changes: 12 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ opendal = { version = "0.40.0", optional = true }
openssl = { version = "0.10.55", optional = true }
rand = "0.8.4"
regex = "1.7.3"
reqsign = { version = "0.14", optional = true }
reqsign = { version = "0.14.1", optional = true }
reqwest = { version = "0.11", features = [
"json",
"blocking",
Expand Down Expand Up @@ -151,7 +151,7 @@ gcs = ["opendal", "reqsign", "url", "reqwest/blocking", "trust-dns-resolver"]
gha = ["opendal"]
memcached = ["opendal/services-memcached"]
native-zlib = []
redis = ["url", "opendal/services-redis"]
redis = ["url", "opendal/services-redis", "opendal/services-redis-rustls"]
s3 = ["opendal", "reqsign"]
webdav = ["opendal"]
# Enable features that will build a vendored version of openssl and
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ sccache - Shared Compilation Cache

sccache is a [ccache](https://ccache.dev/)-like compiler caching tool. It is used as a compiler wrapper and avoids compilation when possible, storing cached results either on [local disk](docs/Local.md) or in one of [several cloud storage backends](#storage-options).

sccache includes support for caching the compilation of C/C++ code, [Rust](docs/Rust.md), as well as NVIDIA's CUDA using [nvcc](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html).
sccache includes support for caching the compilation of C/C++ code, [Rust](docs/Rust.md), as well as NVIDIA's CUDA using [nvcc](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), and [clang](https://llvm.org/docs/CompileCudaWithLLVM.html).

sccache also provides [icecream](https://github.com/icecc/icecream)-style distributed compilation (automatic packaging of local toolchains) for all supported compilers (including Rust). The distributed compilation system includes several security features that icecream lacks such as authentication, transport layer encryption, and sandboxed compiler execution on build servers. See [the distributed quickstart](docs/DistributedQuickstart.md) guide for more information.

Expand Down Expand Up @@ -109,7 +109,7 @@ export RUSTC_WRAPPER=/path/to/sccache
cargo build
```

sccache supports gcc, clang, MSVC, rustc, NVCC, and [Wind River's diab compiler](https://www.windriver.com/products/development-tools/#diab_compiler). Both gcc and msvc support Response Files, read more about their implementation [here](docs/ResponseFiles.md).
sccache supports gcc, clang, MSVC, rustc, [NVCC](https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html), [NVC++](https://docs.nvidia.com/hpc-sdk//compilers/hpc-compilers-user-guide/index.html), and [Wind River's diab compiler](https://www.windriver.com/products/development-tools/#diab_compiler). Both gcc and msvc support Response Files, read more about their implementation [here](docs/ResponseFiles.md).

If you don't [specify otherwise](#storage-options), sccache will use a local disk cache.

Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl Storage for opendal::Operator {
let can_write = match self.write(path, "Hello, World!").await {
Ok(_) => true,
Err(err) if err.kind() == ErrorKind::AlreadyExists => true,
// Toralte all other write errors because we can do read as least.
// Tolerate all other write errors because we can do read at least.
Err(err) => {
eprintln!("storage write check failed: {err:?}");
false
Expand Down
66 changes: 16 additions & 50 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use crate::cache::FileObjectSource;
use crate::compiler::{
Cacheable, ColorMode, Compilation, CompileCommand, Compiler, CompilerArguments, CompilerHasher,
CompilerKind, HashResult,
CompilerKind, HashResult, Language,
};
#[cfg(feature = "dist-client")]
use crate::compiler::{DistPackagers, NoopOutputsRewriter};
Expand Down Expand Up @@ -62,18 +62,6 @@ where
compiler: I,
}

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Language {
C,
Cxx,
GenericHeader,
CHeader,
CxxHeader,
ObjectiveC,
ObjectiveCxx,
Cuda,
}

/// Artifact produced by a C/C++ compiler.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ArtifactDescriptor {
Expand Down Expand Up @@ -129,43 +117,6 @@ impl ParsedArguments {
}
}

impl Language {
pub fn from_file_name(file: &Path) -> Option<Self> {
match file.extension().and_then(|e| e.to_str()) {
// gcc: https://gcc.gnu.org/onlinedocs/gcc/Overall-Options.html
Some("c") => Some(Language::C),
// Could be C or C++
Some("h") => Some(Language::GenericHeader),
// TODO i
Some("C") | Some("cc") | Some("cp") | Some("cpp") | Some("CPP") | Some("cxx")
| Some("c++") => Some(Language::Cxx),
// TODO ii
Some("H") | Some("hh") | Some("hp") | Some("hpp") | Some("HPP") | Some("hxx")
| Some("h++") | Some("tcc") => Some(Language::CxxHeader),
Some("m") => Some(Language::ObjectiveC),
// TODO mi
Some("M") | Some("mm") => Some(Language::ObjectiveCxx),
// TODO mii
Some("cu") => Some(Language::Cuda),
e => {
trace!("Unknown source extension: {}", e.unwrap_or("(None)"));
None
}
}
}

pub fn as_str(self) -> &'static str {
match self {
Language::C | Language::CHeader => "c",
Language::Cxx | Language::CxxHeader => "c++",
Language::GenericHeader => "c/c++",
Language::ObjectiveC => "objc",
Language::ObjectiveCxx => "objc++",
Language::Cuda => "cuda",
}
}
}

/// A generic implementation of the `Compilation` trait for C/C++ compilers.
struct CCompilation<I: CCompilerImpl> {
parsed_args: ParsedArguments,
Expand All @@ -190,6 +141,8 @@ pub enum CCompilerKind {
Msvc,
/// NVIDIA cuda compiler
Nvcc,
/// NVIDIA hpc c, c++ compiler
Nvhpc,
/// Tasking VX
TaskingVX,
}
Expand Down Expand Up @@ -441,6 +394,10 @@ where
fn box_clone(&self) -> Box<dyn CompilerHasher<T>> {
Box::new((*self).clone())
}

fn language(&self) -> Language {
self.parsed_args.language
}
}

impl<I: CCompilerImpl> Compilation for CCompilation<I> {
Expand Down Expand Up @@ -682,6 +639,15 @@ impl pkg::ToolchainPackager for CToolchainPackager {
add_named_prog(&mut package_builder, "ptxas")?;
}

CCompilerKind::Nvhpc => {
// Various programs called by the nvc nvc++ front end.
add_named_file(&mut package_builder, "cpp1")?;
add_named_file(&mut package_builder, "cpp2")?;
add_named_file(&mut package_builder, "opt")?;
add_named_prog(&mut package_builder, "llc")?;
add_named_prog(&mut package_builder, "acclnk")?;
}

_ => unreachable!(),
}

Expand Down
82 changes: 78 additions & 4 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
#![allow(unused_imports, dead_code, unused_variables)]

use crate::compiler::args::*;
use crate::compiler::c::{
ArtifactDescriptor, CCompilerImpl, CCompilerKind, Language, ParsedArguments,
};
use crate::compiler::c::{ArtifactDescriptor, CCompilerImpl, CCompilerKind, ParsedArguments};
use crate::compiler::gcc::ArgData::*;
use crate::compiler::{gcc, write_temp_file, Cacheable, CompileCommand, CompilerArguments};
use crate::compiler::{
gcc, write_temp_file, Cacheable, CompileCommand, CompilerArguments, Language,
};
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
use crate::{counted_array, dist};
Expand Down Expand Up @@ -336,6 +336,80 @@ mod test {
assert_eq!(ovec!["-arch", "xyz"], a.arch_args);
}

#[test]
fn test_parse_arguments_cuda() {
let a = parses!("-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: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(a.preprocessor_args.is_empty());
assert!(a.common_args.is_empty());
}

#[test]
fn test_parse_arguments_cuda_flags() {
let a = parses!(
"-c",
"foo.cpp",
"-x",
"cuda",
"--cuda-gpu-arch=sm_50",
"-o",
"foo.o"
);
assert_eq!(Some("foo.cpp"), a.input.to_str());
assert_eq!(Language::Cuda, a.language);
assert_map_contains!(
a.outputs,
(
"obj",
ArtifactDescriptor {
path: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(a.preprocessor_args.is_empty());
assert_eq!(ovec!["--cuda-gpu-arch=sm_50"], a.common_args);

let b = parses!(
"-c",
"foo.cpp",
"-x",
"cu",
"--cuda-gpu-arch=sm_50",
"--no-cuda-include-ptx=sm_50",
"-o",
"foo.o"
);
assert_eq!(Some("foo.cpp"), b.input.to_str());
assert_eq!(Language::Cuda, b.language);
assert_map_contains!(
b.outputs,
(
"obj",
ArtifactDescriptor {
path: PathBuf::from("foo.o"),
optional: false
}
)
);
assert!(b.preprocessor_args.is_empty());
assert_eq!(
ovec!["--cuda-gpu-arch=sm_50", "--no-cuda-include-ptx=sm_50"],
b.common_args
);
}

#[test]
fn test_dependent_lib() {
let a = parses!(
Expand Down
Loading

0 comments on commit 30c576b

Please sign in to comment.