[cxx-interop] start to emitting a unified header file for a Swift module

This change removes the -emit-cxx-header option, and adds a new -emit-clang-header-path option instead. It's aliased to -emit-objc-header-path for now, but in the future, -emit-objc-header-path will alias to it. After this change Swift can start emitting a single header file that can be expose declarations to C, Objective-C, or C++. For now C++ interface is generated (for all public decls) only when -enable-cxx-interop flag is passed, but that behavior will change once  attribute is supported.
This commit is contained in:
Alex Lorenz
2022-03-15 19:26:36 -07:00
parent 683224acd4
commit 9d52099d5b
29 changed files with 163 additions and 218 deletions

View File

@@ -170,36 +170,22 @@ static bool writeSIL(SILModule &SM, const PrimarySpecificPaths &PSPs,
/// Prints the Objective-C "generated header" interface for \p M to \p
/// outputPath.
///
/// ...unless \p outputPath is empty, in which case it does nothing.
///
/// \returns true if there were any errors
///
/// \see swift::printAsObjC
static bool printAsObjCIfNeeded(StringRef outputPath, ModuleDecl *M,
StringRef bridgingHeader) {
if (outputPath.empty())
return false;
return withOutputFile(M->getDiags(), outputPath,
[&](raw_ostream &out) -> bool {
return printAsObjC(out, M, bridgingHeader);
});
}
/// Prints the C++ "generated header" interface for \p M to \p
/// Print the exposed "generated header" interface for \p M to \p
/// outputPath.
///
/// ...unless \p outputPath is empty, in which case it does nothing.
///
/// \returns true if there were any errors
///
/// \see swift::printAsCXX
static bool printAsCxxIfNeeded(StringRef outputPath, ModuleDecl *M) {
/// \see swift::printAsClangHeader
static bool printAsClangHeaderIfNeeded(StringRef outputPath, ModuleDecl *M,
StringRef bridgingHeader) {
if (outputPath.empty())
return false;
return withOutputFile(
M->getDiags(), outputPath,
[&](raw_ostream &os) -> bool { return printAsCXX(os, M); });
return withOutputFile(M->getDiags(), outputPath,
[&](raw_ostream &out) -> bool {
return printAsClangHeader(out, M, bridgingHeader);
});
}
/// Prints the stable module interface for \p M to \p outputPath.
@@ -824,7 +810,7 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
bool hadAnyError = false;
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
opts.InputsAndOutputs.hasObjCHeaderOutputPath()) {
opts.InputsAndOutputs.hasClangHeaderOutputPath()) {
std::string BridgingHeaderPathForPrint;
if (!opts.ImplicitObjCHeaderPath.empty()) {
if (opts.BridgingHeaderDirForPrint.hasValue()) {
@@ -838,16 +824,10 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs(
BridgingHeaderPathForPrint = opts.ImplicitObjCHeaderPath;
}
}
hadAnyError |= printAsObjCIfNeeded(
Invocation.getObjCHeaderOutputPathForAtMostOnePrimary(),
hadAnyError |= printAsClangHeaderIfNeeded(
Invocation.getClangHeaderOutputPathForAtMostOnePrimary(),
Instance.getMainModule(), BridgingHeaderPathForPrint);
}
if ((!Context.hadError() || opts.AllowModuleWithCompilerErrors) &&
opts.InputsAndOutputs.hasCxxHeaderOutputPath()) {
hadAnyError |= printAsCxxIfNeeded(
Invocation.getCxxHeaderOutputPathForAtMostOnePrimary(),
Instance.getMainModule());
}
// Only want the header if there's been any errors, ie. there's not much
// point outputting a swiftinterface for an invalid module