[cxx-interop] Do not emit C++ interop flag in textual interfaces

This makes sure that the compiler does not emit `-enable-experimental-cxx-interop`/`-cxx-interoperability-mode` flags in `.swiftinterface` files. Those flags were breaking explicit module builds. The module can still be rebuilt from its textual interface if C++ interop was enabled in the current compilation.

rdar://140203932
This commit is contained in:
Egor Zhdan
2024-11-21 00:30:36 +00:00
parent 22741dba06
commit 7ae2bebfe8
4 changed files with 25 additions and 18 deletions

View File

@@ -2014,12 +2014,8 @@ InterfaceSubContextDelegateImpl::InterfaceSubContextDelegateImpl(
GenericArgs.push_back(blocklist);
}
// For now, we only inherit the C++ interoperability mode in
// Explicit Module Builds.
if (langOpts.EnableCXXInterop &&
(frontendOpts.DisableImplicitModules ||
LoaderOpts.requestedAction ==
FrontendOptions::ActionType::ScanDependencies)) {
// Inherit the C++ interoperability mode.
if (langOpts.EnableCXXInterop) {
// Modelled after a reverse of validateCxxInteropCompatibilityMode
genericSubInvocation.getLangOptions().EnableCXXInterop = true;
genericSubInvocation.getLangOptions().cxxInteropCompatVersion =
@@ -2208,6 +2204,19 @@ InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleName,
BuildArgs.push_back("-module-name");
BuildArgs.push_back(moduleName);
// FIXME: Hack for Darwin.swiftmodule, which cannot be rebuilt with C++
// interop enabled by the Swift CI because it uses an old host SDK.
if (moduleName == "Darwin") {
subInvocation.getLangOptions().EnableCXXInterop = false;
subInvocation.getLangOptions().cxxInteropCompatVersion = {};
BuildArgs.erase(llvm::remove_if(BuildArgs,
[](StringRef arg) -> bool {
return arg.starts_with(
"-cxx-interoperability-mode=");
}),
BuildArgs.end());
}
// Calculate output path of the module.
llvm::SmallString<256> buffer;
StringRef CacheHash;