-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add cxx interop support to symbolgraph-extract #7610
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 | ||||
---|---|---|---|---|---|---|
|
@@ -547,26 +547,8 @@ public final class SwiftTargetBuildDescription { | |||||
args += ["-color-diagnostics"] | ||||||
} | ||||||
|
||||||
// If this is a generated test discovery target or a test entry point, it might import a test | ||||||
// target that is built with C++ interop enabled. In that case, the test | ||||||
// discovery target must enable C++ interop as well | ||||||
switch testTargetRole { | ||||||
case .discovery, .entryPoint: | ||||||
for dependency in try self.target.recursiveTargetDependencies() { | ||||||
let dependencyScope = self.buildParameters.createScope(for: dependency) | ||||||
let dependencySwiftFlags = dependencyScope.evaluate(.OTHER_SWIFT_FLAGS) | ||||||
if let interopModeFlag = dependencySwiftFlags.first(where: { $0.hasPrefix("-cxx-interoperability-mode=") }) { | ||||||
args += [interopModeFlag] | ||||||
if interopModeFlag != "-cxx-interoperability-mode=off" { | ||||||
if let cxxStandard = self.package.manifest.cxxLanguageStandard { | ||||||
args += ["-Xcc", "-std=\(cxxStandard)"] | ||||||
} | ||||||
} | ||||||
break | ||||||
} | ||||||
} | ||||||
default: break | ||||||
} | ||||||
args += try self.cxxInteroperabilityModeArguments( | ||||||
propagateFromCurrentModuleOtherSwiftFlags: false) | ||||||
|
||||||
// Add arguments from declared build settings. | ||||||
args += try self.buildSettingsFlags() | ||||||
|
@@ -644,6 +626,67 @@ public final class SwiftTargetBuildDescription { | |||||
|
||||||
return args | ||||||
} | ||||||
|
||||||
/// Determines the arguments needed to run `swift-symbolgraph-extract` for | ||||||
/// this module. | ||||||
public func symbolGraphExtractArguments() throws -> [String] { | ||||||
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.
Suggested change
|
||||||
var args = [String]() | ||||||
args += try self.cxxInteroperabilityModeArguments( | ||||||
propagateFromCurrentModuleOtherSwiftFlags: true) | ||||||
return args | ||||||
Comment on lines
+633
to
+636
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. Can this be simplified to just 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. A follow up PR adds to args so I'd like to leave this as is |
||||||
} | ||||||
|
||||||
// FIXME: this function should operation on a strongly typed buildSetting | ||||||
// Move logic from PackageBuilder here. | ||||||
/// Determines the arguments needed for cxx interop for this module. | ||||||
func cxxInteroperabilityModeArguments( | ||||||
// FIXME: Remove argument | ||||||
// This argument is added as a stop gap to support generating arguments | ||||||
// for tools which currently don't leverage "OTHER_SWIFT_FLAGS". In the | ||||||
// fullness of time this function should operate on a strongly typed | ||||||
// "interopMode" property of SwiftTargetBuildDescription instead of | ||||||
// digging through "OTHER_SWIFT_FLAGS" manually. | ||||||
propagateFromCurrentModuleOtherSwiftFlags: Bool | ||||||
) throws -> [String] { | ||||||
func cxxInteroperabilityModeAndStandard( | ||||||
for module: ResolvedModule | ||||||
) -> [String]? { | ||||||
let scope = self.buildParameters.createScope(for: module) | ||||||
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. Is this correct to use It seems like we need to avoid adding new uses of 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. I'd rather not change this logic in this PR, im simply moving the existing code such that symbol graph can use it. 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. Sure, I'm mentioning this because of the comment - 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. I guess the point of that comment is to say, we should not throw away the typed interop information at that layer and try to recover it here by parsing flags, we should instead determine the flags at this layer 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. Maybe you could do the same thing as 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. I don't mean it has to be in this PR, just an idea how to avoid having to prefix match things... |
||||||
let flags = scope.evaluate(.OTHER_SWIFT_FLAGS) | ||||||
let mode = flags.first { $0.hasPrefix("-cxx-interoperability-mode=") } | ||||||
guard let mode else { return nil } | ||||||
// FIXME: Use a stored self.cxxLanguageStandard property | ||||||
// It definitely should _never_ reach back into the manifest | ||||||
if let cxxStandard = self.package.manifest.cxxLanguageStandard { | ||||||
return [mode, "-Xcc", "-std=\(cxxStandard)"] | ||||||
} else { | ||||||
return [mode] | ||||||
} | ||||||
} | ||||||
|
||||||
if propagateFromCurrentModuleOtherSwiftFlags { | ||||||
// Look for cxx interop mode in the current module, if set exit early, | ||||||
// the flag is already present. | ||||||
if let args = cxxInteroperabilityModeAndStandard(for: self.target) { | ||||||
return args | ||||||
} | ||||||
} | ||||||
|
||||||
// Implicitly propagate cxx interop flags for generated test targets. | ||||||
// If the current module doesn't have cxx interop mode set, search | ||||||
// through the module's dependencies looking for the a module that | ||||||
// enables cxx interop and copy it's flag. | ||||||
switch self.testTargetRole { | ||||||
case .discovery, .entryPoint: | ||||||
for module in try self.target.recursiveTargetDependencies() { | ||||||
if let args = cxxInteroperabilityModeAndStandard(for: module) { | ||||||
return args | ||||||
} | ||||||
} | ||||||
default: break | ||||||
} | ||||||
return [] | ||||||
} | ||||||
|
||||||
/// When `scanInvocation` argument is set to `true`, omit the side-effect producing arguments | ||||||
/// such as emitting a module or supplementary outputs. | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -115,4 +115,13 @@ public enum TargetBuildDescription { | |||||
return clangTargetBuildDescription.toolsVersion | ||||||
} | ||||||
} | ||||||
|
||||||
/// Determines the arguments needed to run `swift-symbolgraph-extract` for | ||||||
/// this module. | ||||||
public func symbolGraphExtractArguments() throws -> [String] { | ||||||
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.
Suggested change
|
||||||
switch self { | ||||||
case .swift(let target): try target.symbolGraphExtractArguments() | ||||||
case .clang(let target): try target.symbolGraphExtractArguments() | ||||||
} | ||||||
} | ||||||
} |
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.