mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Caching] Create clang importer from cc1 args directly
When caching build is enabled, teach dependency scanner to report command-lines with `-direct-clang-cc1-module-build` so the later compilation can instantiate clang importer with cc1 args directly. This avoids running clang driver code, which might involve file system lookups, which are the file deps that are not captured and might result in different compilation mode. rdar://119275464
This commit is contained in:
@@ -1675,6 +1675,9 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
||||
Feature::LayoutPrespecialization);
|
||||
}
|
||||
|
||||
genericSubInvocation.getClangImporterOptions().DirectClangCC1ModuleBuild =
|
||||
clangImporterOpts.DirectClangCC1ModuleBuild;
|
||||
|
||||
// Validate Clang modules once per-build session flags must be consistent
|
||||
// across all module sub-invocations
|
||||
if (clangImporterOpts.ValidateModulesOnce) {
|
||||
@@ -1690,6 +1693,8 @@ void InterfaceSubContextDelegateImpl::inheritOptionsForBuildingInterface(
|
||||
genericSubInvocation.getCASOptions().CASOpts = casOpts.CASOpts;
|
||||
casOpts.enumerateCASConfigurationFlags(
|
||||
[&](StringRef Arg) { GenericArgs.push_back(ArgSaver.save(Arg)); });
|
||||
// ClangIncludeTree is default on when caching is enabled.
|
||||
genericSubInvocation.getClangImporterOptions().UseClangIncludeTree = true;
|
||||
}
|
||||
|
||||
if (!clangImporterOpts.UseClangIncludeTree) {
|
||||
@@ -2068,10 +2073,16 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
|
||||
== originalTargetTriple.getEnvironment()) {
|
||||
parsedTargetTriple.setArchName(originalTargetTriple.getArchName());
|
||||
subInvocation.setTargetTriple(parsedTargetTriple.str());
|
||||
}
|
||||
|
||||
// Overload the target in the BuildArgs as well
|
||||
BuildArgs.push_back("-target");
|
||||
BuildArgs.push_back(parsedTargetTriple.str());
|
||||
// Find and overload all "-target" to be parsedTargetTriple. This make sure
|
||||
// the build command for the interface is the same no matter what the parent
|
||||
// triple is so there is no need to spawn identical jobs.
|
||||
assert(llvm::find(BuildArgs, "-target") != BuildArgs.end() &&
|
||||
"missing target option");
|
||||
for (unsigned idx = 0, end = BuildArgs.size(); idx < end; ++idx) {
|
||||
if (BuildArgs[idx] == "-target" && ++idx < end)
|
||||
BuildArgs[idx] = parsedTargetTriple.str();
|
||||
}
|
||||
|
||||
// restore `StrictImplicitModuleContext`
|
||||
@@ -2422,6 +2433,11 @@ struct ExplicitCASModuleLoader::Implementation {
|
||||
|
||||
std::set<std::string> moduleMapsSeen;
|
||||
std::vector<std::string> &extraClangArgs = Ctx.ClangImporterOpts.ExtraArgs;
|
||||
// Append -Xclang if we are not in direct cc1 mode.
|
||||
auto appendXclang = [&]() {
|
||||
if (!Ctx.ClangImporterOpts.DirectClangCC1ModuleBuild)
|
||||
extraClangArgs.push_back("-Xclang");
|
||||
};
|
||||
for (auto &entry : ExplicitClangModuleMap) {
|
||||
const auto &moduleMapPath = entry.getValue().moduleMapPath;
|
||||
if (!moduleMapPath.empty() &&
|
||||
@@ -2440,11 +2456,11 @@ struct ExplicitCASModuleLoader::Implementation {
|
||||
}
|
||||
auto cachePath = entry.getValue().moduleCacheKey;
|
||||
if (cachePath) {
|
||||
extraClangArgs.push_back("-Xclang");
|
||||
appendXclang();
|
||||
extraClangArgs.push_back("-fmodule-file-cache-key");
|
||||
extraClangArgs.push_back("-Xclang");
|
||||
appendXclang();
|
||||
extraClangArgs.push_back(modulePath);
|
||||
extraClangArgs.push_back("-Xclang");
|
||||
appendXclang();
|
||||
extraClangArgs.push_back(*cachePath);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user