Skip to content

Commit

Permalink
Merge pull request swiftlang#1605 from etcwilde/ewilde/accept-clangxx…
Browse files Browse the repository at this point in the history
…-env-var

Allow setting the clang++ environment variable
  • Loading branch information
etcwilde authored May 14, 2024
2 parents 707ce7e + 43c1144 commit dd5bbca
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/SwiftDriver/Toolchains/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ extension Toolchain {

/// - Returns: String in the form of: `SWIFT_DRIVER_TOOLNAME_EXEC`
private func envVarName(for toolName: String) -> String {
let lookupName = toolName.replacingOccurrences(of: "-", with: "_").uppercased()
let lookupName = toolName
.replacingOccurrences(of: "-", with: "_")
.replacingOccurrences(of: "+", with: "X")
.uppercased()
return "SWIFT_DRIVER_\(lookupName)_EXEC"
}

Expand Down
35 changes: 35 additions & 0 deletions Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6823,6 +6823,41 @@ final class SwiftDriverTests: XCTestCase {
XCTAssertEqual(jobs.first!.tool.name, swiftHelp.pathString)
}

func testSwiftClangOverride() throws {
var env = ProcessEnv.vars
let swiftClang = try AbsolutePath(validating: "/A/Path/swift-clang")
env["SWIFT_DRIVER_CLANG_EXEC"] = swiftClang.pathString

var driver = try Driver(
args: ["swiftc", "-emit-library", "foo.swift", "bar.o", "-o", "foo.l"],
env: env)
let jobs = try driver.planBuild()
XCTAssertEqual(jobs.count, 2)
let linkJob = jobs[1]
XCTAssertEqual(linkJob.tool.name, swiftClang.pathString)
}

func testSwiftClangxxOverride() throws {
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
throw XCTSkip("Darwin always uses `clang` to link")
#else
var env = ProcessEnv.vars
let swiftClang = try AbsolutePath(validating: "/A/Path/swift-clang")
let swiftClangxx = try AbsolutePath(validating: "/A/Path/swift-clang++")
env["SWIFT_DRIVER_CLANG_EXEC"] = swiftClang.pathString
env["SWIFT_DRIVER_CLANGXX_EXEC"] = swiftClangxx.pathString

var driver = try Driver(
args: ["swiftc", "-cxx-interoperability-mode=swift-5.9", "-emit-library",
"foo.swift", "bar.o", "-o", "foo.l"],
env: env)

let jobs = try driver.planBuild()
let linkJob = jobs.last!
XCTAssertEqual(linkJob.tool.name, swiftClangxx.pathString)
#endif
}

func testSourceInfoFileEmitOption() throws {
// implicit
do {
Expand Down

0 comments on commit dd5bbca

Please sign in to comment.