Skip to content

Commit 6cc63ec

Browse files
authored
SR-12050: lldb error: could not build C module 'CNIOBoringSSLShims' (Linux 5.1.3) when debugging (#3215)
When invoking the Swift compiler, SwiftPM was passing search paths to C headers as "-I" arguments. But it wasn't prefixing them with "-Xcc" so they were being interpreted by the Swift driver and not Clang. This meant that they weren't recorded as serialized import paths in the AST. It isn't fully clear why they are needed when building the module in response to the debugger or REPL but not when building using the compiler, but it is clear that these are C header search paths and not Swift module search paths, so they should indeed be passed using "-Xcc" prefixes. rdar://58709835
1 parent 95e5c3f commit 6cc63ec

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/Build/BuildPlan.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,15 +1668,15 @@ public class BuildPlan {
16681668
guard let moduleMap = target.moduleMap else { break }
16691669
swiftTarget.additionalFlags += [
16701670
"-Xcc", "-fmodule-map-file=\(moduleMap.pathString)",
1671-
"-I", target.clangTarget.includeDir.pathString,
1671+
"-Xcc", "-I", "-Xcc", target.clangTarget.includeDir.pathString,
16721672
]
16731673
case let target as SystemLibraryTarget:
16741674
swiftTarget.additionalFlags += ["-Xcc", "-fmodule-map-file=\(target.moduleMapPath.pathString)"]
16751675
swiftTarget.additionalFlags += pkgConfig(for: target).cFlags
16761676
case let target as BinaryTarget:
16771677
if let library = xcFrameworkLibrary(for: target) {
16781678
if let headersPath = library.headersPath {
1679-
swiftTarget.additionalFlags += ["-I", headersPath.pathString]
1679+
swiftTarget.additionalFlags += ["-Xcc", "-I", "-Xcc", headersPath.pathString]
16801680
}
16811681
swiftTarget.libraryBinaryPaths.insert(library.binaryPath)
16821682
}

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ final class BuildPlanTests: XCTestCase {
774774
XCTAssertEqual(lib.moduleMap, AbsolutePath("/path/to/build/debug/lib.build/module.modulemap"))
775775

776776
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
777-
XCTAssertMatch(exe, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-enable-testing", "-g", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-I", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
777+
XCTAssertMatch(exe, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-enable-testing", "-g", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-Xcc", "-I", "-Xcc", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
778778

779779
#if os(macOS)
780780
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
@@ -1610,7 +1610,7 @@ final class BuildPlanTests: XCTestCase {
16101610
XCTAssertEqual(lib.moduleMap, AbsolutePath("/path/to/build/debug/lib.build/module.modulemap"))
16111611

16121612
let exe = try result.target(for: "exe").swiftTarget().compileArguments()
1613-
XCTAssertMatch(exe, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-enable-testing", "-g", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-I", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
1613+
XCTAssertMatch(exe, ["-swift-version", "4", "-enable-batch-mode", "-Onone", "-enable-testing", "-g", .equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc", "-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap", "-Xcc", "-I", "-Xcc", "/Pkg/Sources/lib/include", "-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence])
16141614

16151615
XCTAssertEqual(try result.buildProduct(for: "exe").linkArguments(), [
16161616
"/fake/path/to/swiftc",
@@ -1681,7 +1681,7 @@ final class BuildPlanTests: XCTestCase {
16811681
"-swift-version", "4", "-enable-batch-mode", "-Onone", "-enable-testing", "-g",
16821682
.equal(j), "-DSWIFT_PACKAGE", "-DDEBUG","-Xcc",
16831683
"-fmodule-map-file=/path/to/build/debug/lib.build/module.modulemap",
1684-
"-I", "/Pkg/Sources/lib/include",
1684+
"-Xcc", "-I", "-Xcc", "/Pkg/Sources/lib/include",
16851685
"-module-cache-path", "/path/to/build/debug/ModuleCache", .anySequence
16861686
]
16871687
)

0 commit comments

Comments
 (0)