Inherit parent's extra Clang arguments when creating an interface build sub-invocation.

We would like to make sure they get propagated to downstream transitive Clang module dependencies also.

Resolves rdar://101923680
This commit is contained in:
Artem Chikin
2022-11-03 14:31:05 -07:00
parent a0cb7a6e30
commit d1cbf9c8d4
9 changed files with 88 additions and 13 deletions

View File

@@ -1597,18 +1597,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");