Swift normally looks for the Clang resource dir in a subdir/symlink of its own resource dir. We provide a symlink to the Swift build-time Clang as a default there, but we also here patch a check to try locate it via NIX_CC. --- a/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift +++ b/Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +import Foundation import SwiftOptions import protocol TSCBasic.FileSystem @@ -26,6 +27,13 @@ extension Toolchain { for targetInfo: FrontendTargetInfo, parsedOptions: inout ParsedOptions ) throws -> VirtualPath { + let env = ProcessInfo.processInfo.environment + if let nixCC = env["NIX_CC"] { + return try VirtualPath(path: nixCC) + .appending(components: "resource-root", "lib", + targetInfo.target.triple.platformName(conflatingDarwin: true)!) + } + return VirtualPath.lookup(targetInfo.runtimeResourcePath.path) .appending(components: "clang", "lib", targetInfo.target.triple.platformName(conflatingDarwin: true)!)