Skip to content

Commit 0f9f247

Browse files
authored
Merge pull request #1023 from compnerd/clangxx
SwiftDriver: use `clang++` as linker driver with C++ Interop
2 parents 5d7fd3d + d3a6923 commit 0f9f247

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

Sources/SwiftDriver/Jobs/GenericUnixToolchain+LinkerSupport.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ extension GenericUnixToolchain {
102102
// Windows rather than msvcprt). When C++ interop is enabled, we will need to
103103
// surface this via a driver flag. For now, opt for the simpler approach of
104104
// just using `clang` and avoid a dependency on the C++ runtime.
105-
var clangPath = try getToolPath(.clang)
105+
var clangPath = try parsedOptions.hasArgument(.enableExperimentalCxxInterop)
106+
? getToolPath(.clangxx)
107+
: getToolPath(.clang)
106108
if let toolsDirPath = parsedOptions.getLastArgument(.toolsDirectory) {
107109
// FIXME: What if this isn't an absolute path?
108110
let toolsDir = try AbsolutePath(validating: toolsDirPath.asSingle)
109111

110112
// If there is a clang in the toolchain folder, use that instead.
111-
if let tool = lookupExecutablePath(filename: "clang", searchPaths: [toolsDir]) {
113+
if let tool = lookupExecutablePath(filename: parsedOptions.hasArgument(.enableExperimentalCxxInterop)
114+
? "clang++" : "clang",
115+
searchPaths: [toolsDir]) {
112116
clangPath = tool
113117
}
114118

Sources/SwiftDriver/Jobs/WindowsToolchain+LinkerSupport.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ extension WindowsToolchain {
4747
return try lookup(executable: librarian)
4848
}
4949

50-
var clang = try getToolPath(.clang)
50+
var clang = try parsedOptions.hasArgument(.enableExperimentalCxxInterop)
51+
? getToolPath(.clangxx)
52+
: getToolPath(.clang)
5153

5254
let targetTriple = targetInfo.target.triple
5355
if !targetTriple.triple.isEmpty {

Tests/SwiftDriverTests/SwiftDriverTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6058,6 +6058,22 @@ final class SwiftDriverTests: XCTestCase {
60586058
XCTAssertFalse(try doBuild())
60596059
XCTAssert(outputs.allSatisfy {!localFileSystem.exists($0)})
60606060
}
6061+
#endif
6062+
}
6063+
6064+
func testCxxLinking() throws {
6065+
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
6066+
throw XCTSkip("Darwin does not use clang as the linker driver")
6067+
#else
6068+
VirtualPath.resetTemporaryFileStore()
6069+
var driver = try Driver(args: [
6070+
"swiftc", "-enable-experimental-cxx-interop", "-emit-library", "-o", "library.dll", "library.obj"
6071+
])
6072+
let jobs = try driver.planBuild().removingAutolinkExtractJobs()
6073+
XCTAssertEqual(jobs.count, 1)
6074+
let job = jobs.first!
6075+
XCTAssertEqual(job.kind, .link)
6076+
XCTAssertTrue(job.tool.name.hasSuffix(executableName("clang++")))
60616077
#endif
60626078
}
60636079
}

0 commit comments

Comments
 (0)