Merge pull request #61919 from artemcm/InheritExtraClangStateForInterfaceSubInvocation

Inherit parent's extra Clang arguments when creating an interface build sub-invocation.
This commit is contained in:
Artem Chikin
2022-11-09 09:24:18 -08:00
committed by GitHub
9 changed files with 88 additions and 13 deletions

View File

@@ -1598,18 +1598,11 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
subClangImporterOpts.DetailedPreprocessingRecord =
clangImporterOpts.DetailedPreprocessingRecord;
// We need to add these extra clang flags because explicit module building
// related flags are all there: -fno-implicit-modules, -fmodule-map-file=,
// and -fmodule-file=.
// If we don't add these flags, the interface will be built with implicit
// PCMs.
// FIXME: With Implicit Module Builds, if sub-invocations inherit `-fmodule-map-file=` options,
// those modulemaps become File dependencies of all downstream PCMs and their depending Swift
// modules, triggering unnecessary re-builds. We work around this by only inheriting these options
// when building with explicit modules. While this problem will not manifest with Explicit Modules
// (which do not use the ClangImporter to build PCMs), we may still need a better way to
// decide which options must be inherited here.
if (LoaderOpts.disableImplicitSwiftModule) {
// If the compiler has been asked to be strict with ensuring downstream dependencies
// get the parent invocation's context, or this is an Explicit build, inherit the
// extra Clang arguments also.
if (LoaderOpts.strictImplicitModuleContext || LoaderOpts.disableImplicitSwiftModule) {
// Inherit any clang-specific state of the compilation (macros, clang flags, etc.)
subClangImporterOpts.ExtraArgs = clangImporterOpts.ExtraArgs;
for (auto arg : subClangImporterOpts.ExtraArgs) {
GenericArgs.push_back("-Xcc");