-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[interop] add an option to emit C++ header interface for a module #40923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,6 +186,22 @@ static bool printAsObjCIfNeeded(StringRef outputPath, ModuleDecl *M, | |
}); | ||
} | ||
|
||
/// Prints the 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::printAsCxx | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: that function is spelled There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I'll fix it up in the next patch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
static bool printAsCxxIfNeeded(StringRef outputPath, ModuleDecl *M) { | ||
if (outputPath.empty()) | ||
return false; | ||
return withOutputFile( | ||
M->getDiags(), outputPath, | ||
[&](raw_ostream &os) -> bool { return printAsCXX(os, M); }); | ||
} | ||
|
||
/// Prints the stable module interface for \p M to \p outputPath. | ||
/// | ||
/// ...unless \p outputPath is empty, in which case it does nothing. | ||
|
@@ -826,6 +842,12 @@ static bool emitAnyWholeModulePostTypeCheckSupplementaryOutputs( | |
Invocation.getObjCHeaderOutputPathForAtMostOnePrimary(), | ||
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a problem, because we have two different outputs associated with the same entry in the output file map, so we'll end up writing both the ObjC and C++ header to the same place. I've fixed the issue via #41015, but I think we should reconsider having separate ObjC vs. C++ generated headers. It's a mess for the build system, and what would we do about Objective-C++? Instead, I think we should generate a single header that uses
#ifdefs
to appropriately compile as C/ObjC/C++/ObjC++.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Doug, thanks for fixing this, and sorry about the breakage. I'm not sure if we would like to generate a single header, instead we actually would prefer to generate multiple C++ headers as they will be target-specific, one per target, and then have the build system create a unified C++ header one from them. Do you think that would be a reasonable idea, and should we even support path map in that case? Also, I don't believe we want to emit Objective-C++ headers, as that would be ambiguous - we would either want to emit Objective-C or C++, and then the programmer can import their preferred interface into Objective-C++ as desired.