Skip to content

Commit 49f3604

Browse files
committed
Add cxx interop support to symbolgraph-extract
In order to extract symbol graphs for modules with transitive imports on cxx modules we need parse headers in cxx mode using the option: `-cxx-interoperability-mode=default`. This commit updates `swift-symbolgraph-extract` to pass the option when there is a Cxx module in the import graph. This option is a new addition to `swift-symbolgraph-extract` added in swiftlang/swift#73963. Prior to this option's introduction, extracting the symbol graph for cxx dependent modules would fail with an error similar to: "unknown type name 'namespace'". With this SwiftPM commit and `swift-symbolgraph-extract` _prior_ to 73963, users will instead see an argument parsing error like: "unknown option -cxx-interoperability-mode". With this change and `swift-symbolgraph-extract` 73963, the symbol graph is extracted properly.
1 parent 1c62623 commit 49f3604

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

Sources/Commands/Utilities/SymbolGraphExtract.swift

+28-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import ArgumentParser
1414
import Basics
1515
import PackageGraph
16-
import PackageModel
16+
@_spi(SwiftPMInternal) import PackageModel
1717
import SPMBuildCore
1818

1919
#if USE_IMPL_ONLY_IMPORTS
@@ -82,7 +82,22 @@ public struct SymbolGraphExtract {
8282
if includeSPISymbols {
8383
commandLine += ["-include-spi-symbols"]
8484
}
85-
85+
86+
// If this target or any dependencies is is built with C++ interop
87+
// enabled then swift-symbolgraph-extract must also enable C++ interop.
88+
var cxxInterop = module.cxxInterop()
89+
if !cxxInterop {
90+
for module in try module.recursiveTargetDependencies() {
91+
if module.cxxInterop() {
92+
cxxInterop = true
93+
break
94+
}
95+
}
96+
}
97+
if cxxInterop {
98+
commandLine += ["-cxx-interoperability-mode=default"]
99+
}
100+
86101
let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols"
87102
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) {
88103
commandLine += [extensionBlockSymbolsFlag]
@@ -107,3 +122,14 @@ public struct SymbolGraphExtract {
107122
return try process.waitUntilExit()
108123
}
109124
}
125+
126+
extension ResolvedModule {
127+
func cxxInterop() -> Bool {
128+
for setting in self.underlying.buildSettingsDescription {
129+
if case .interoperabilityMode(.Cxx) = setting.kind {
130+
return true
131+
}
132+
}
133+
return false
134+
}
135+
}

0 commit comments

Comments
 (0)