Skip to content

Commit

Permalink
got it working
Browse files Browse the repository at this point in the history
  • Loading branch information
trxcllnt committed Aug 8, 2024
1 parent ba71715 commit 358c47c
Show file tree
Hide file tree
Showing 16 changed files with 1,019 additions and 301 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ rouille = { version = "3.6", optional = true, default-features = false, features
] }
syslog = { version = "6", optional = true }
version-compare = { version = "0.1.1", optional = true }
shlex = "=1.3.0"

[dev-dependencies]
assert_cmd = "2.0.13"
Expand Down
44 changes: 36 additions & 8 deletions src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,17 @@ pub trait CCompilerImpl: Clone + fmt::Debug + Send + Sync + 'static {
T: CommandCreatorSync;
/// Generate a command that can be used to invoke the C compiler to perform
/// the compilation.
fn generate_compile_commands(
fn generate_compile_commands<T>(
&self,
path_transformer: &mut dist::PathTransformer,
executable: &Path,
parsed_args: &ParsedArguments,
cwd: &Path,
env_vars: &[(OsString, OsString)],
rewrite_includes_only: bool,
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)>;
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
where
T: CommandCreatorSync;
}

impl<I> CCompiler<I>
Expand Down Expand Up @@ -362,7 +364,7 @@ where
rewrite_includes_only: bool,
storage: Arc<dyn Storage>,
cache_control: CacheControl,
) -> Result<HashResult> {
) -> Result<HashResult<T>> {
let start_of_compilation = std::time::SystemTime::now();
let CCompilerHasher {
parsed_args,
Expand Down Expand Up @@ -396,10 +398,36 @@ where
arg
);
}

let use_preprocessor_cache_mode = {
let can_use_preprocessor_cache_mode = !may_dist
&& preprocessor_cache_mode_config.use_preprocessor_cache_mode
&& !too_hard_for_preprocessor_cache_mode;

let mut use_preprocessor_cache_mode = can_use_preprocessor_cache_mode;

// Allow overrides from the env
for (key, val) in env_vars.iter() {
if key == "SCCACHE_DIRECT" {
if let Some(val) = val.to_str() {
use_preprocessor_cache_mode = match val.to_lowercase().as_str() {
"false" | "off" | "0" => false,
_ => can_use_preprocessor_cache_mode,
};
}
break;
}
}

if can_use_preprocessor_cache_mode && !use_preprocessor_cache_mode {
debug!("parse_arguments: Disabling preprocessor cache because SCCACHE_DIRECT=false");
}

use_preprocessor_cache_mode
};

// Disable preprocessor cache when doing distributed compilation
let mut preprocessor_key = if !may_dist
&& preprocessor_cache_mode_config.use_preprocessor_cache_mode
&& !too_hard_for_preprocessor_cache_mode
let mut preprocessor_key = if use_preprocessor_cache_mode
{
preprocessor_cache_entry_hash_key(
&executable_digest,
Expand Down Expand Up @@ -1113,12 +1141,12 @@ fn include_is_too_new(
false
}

impl<I: CCompilerImpl> Compilation for CCompilation<I> {
impl<T: CommandCreatorSync, I: CCompilerImpl> Compilation<T> for CCompilation<I> {
fn generate_compile_commands(
&self,
path_transformer: &mut dist::PathTransformer,
rewrite_includes_only: bool,
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)> {
let CCompilation {
ref parsed_args,
ref executable,
Expand Down
18 changes: 13 additions & 5 deletions src/compiler/cicc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#![allow(unused_imports, dead_code, unused_variables)]

use crate::compiler::args::*;
use crate::compiler::{Cacheable, ColorMode, CompileCommand, CompilerArguments, Language};
use crate::compiler::{Cacheable, ColorMode, CompileCommand, CCompileCommand, CompilerArguments, Language, SingleCompileCommand};
use crate::compiler::c::{ArtifactDescriptor, CCompilerImpl, CCompilerKind, ParsedArguments};
use crate::{counted_array, dist};

Expand Down Expand Up @@ -68,22 +68,30 @@ impl CCompilerImpl for Cicc {
trace!("cicc preprocessed input file: cwd={:?} path={:?}", cwd, &parsed_args.input);
preprocess(cwd, parsed_args).await
}
fn generate_compile_commands(
fn generate_compile_commands<T>(
&self,
path_transformer: &mut dist::PathTransformer,
executable: &Path,
parsed_args: &ParsedArguments,
cwd: &Path,
env_vars: &[(OsString, OsString)],
_rewrite_includes_only: bool,
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
where
T: CommandCreatorSync,
{
generate_compile_commands(
path_transformer,
executable,
parsed_args,
cwd,
env_vars
)
.map(|(command, dist_command, cacheable)| (
CCompileCommand::new(command),
dist_command,
cacheable
))
}
}

Expand Down Expand Up @@ -204,7 +212,7 @@ pub fn generate_compile_commands(
parsed_args: &ParsedArguments,
cwd: &Path,
env_vars: &[(OsString, OsString)],
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(SingleCompileCommand, Option<dist::CompileCommand>, Cacheable)> {
// Unused arguments
#[cfg(not(feature = "dist-client"))]
{
Expand All @@ -228,7 +236,7 @@ pub fn generate_compile_commands(
out_file.into()
]);

let command = CompileCommand {
let command = SingleCompileCommand {
executable: executable.to_owned(),
arguments,
env_vars: env_vars.to_owned(),
Expand Down
14 changes: 11 additions & 3 deletions src/compiler/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::compiler::args::*;
use crate::compiler::c::{ArtifactDescriptor, CCompilerImpl, CCompilerKind, ParsedArguments};
use crate::compiler::gcc::ArgData::*;
use crate::compiler::{
gcc, write_temp_file, Cacheable, CompileCommand, CompilerArguments, Language,
gcc, write_temp_file, Cacheable, CompileCommand, CCompileCommand, CompilerArguments, Language
};
use crate::mock_command::{CommandCreator, CommandCreatorSync, RunCommand};
use crate::util::{run_input_output, OsStrExt};
Expand Down Expand Up @@ -144,15 +144,18 @@ impl CCompilerImpl for Clang {
.await
}

fn generate_compile_commands(
fn generate_compile_commands<T>(
&self,
path_transformer: &mut dist::PathTransformer,
executable: &Path,
parsed_args: &ParsedArguments,
cwd: &Path,
env_vars: &[(OsString, OsString)],
rewrite_includes_only: bool,
) -> Result<(CompileCommand, Option<dist::CompileCommand>, Cacheable)> {
) -> Result<(Box<dyn CompileCommand<T>>, Option<dist::CompileCommand>, Cacheable)>
where
T: CommandCreatorSync
{
gcc::generate_compile_commands(
path_transformer,
executable,
Expand All @@ -162,6 +165,11 @@ impl CCompilerImpl for Clang {
self.kind(),
rewrite_includes_only,
)
.map(|(command, dist_command, cacheable)| (
CCompileCommand::new(command),
dist_command,
cacheable
))
}
}

Expand Down
Loading

0 comments on commit 358c47c

Please sign in to comment.