Skip to content

Align Clang resource directory lookup with Clang driver logic #1895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Sources/SwiftDriver/Jobs/Toolchain+LinkerSupport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@ extension Toolchain {
for targetInfo: FrontendTargetInfo,
parsedOptions: inout ParsedOptions
) throws -> VirtualPath {
var platform = targetInfo.target.triple.platformName(conflatingDarwin: true)!
// compiler-rt moved these Android sanitizers into `lib/linux/` a couple
// years ago, llvm/llvm-project@a68ccba, so look for them there instead.
if platform == "android" {
platform = "linux"
}
let platform = targetInfo.target.triple.clangOSLibName

// NOTE(compnerd) Windows uses the per-target runtime directory for the
// Windows runtimes. This should also be done for the other platforms, but
Expand Down
23 changes: 22 additions & 1 deletion Sources/SwiftDriver/Utilities/Triple+Platforms.swift
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,28 @@ extension Triple {
}
}

/// The platform name, i.e. the name clang uses to identify this target in its

/// The "os" component of the Clang compiler resource library directory (`<ResourceDir>/lib/<OSName>`).
/// Must be kept in sync with Clang driver:
/// https://github.com/llvm/llvm-project/blob/llvmorg-20.1.4/clang/lib/Driver/ToolChain.cpp#L690
@_spi(Testing) public var clangOSLibName: String {
guard let os else {
return osName
}
if os.isDarwin {
return "darwin"
}

switch os {
case .freeBSD: return "freebsd"
case .netbsd: return "netbsd"
case .openbsd: return "openbsd"
case .aix: return "aix"
default: return osName
}
}

/// The platform name, i.e. the name Swift uses to identify this target in its
/// resource directory.
///
/// - Parameter conflatingDarwin: If true, all Darwin platforms will be
Expand Down
9 changes: 9 additions & 0 deletions Tests/SwiftDriverTests/TripleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,15 @@ final class TripleTests: XCTestCase {
shouldHaveJetPacks: true)
}

func testClangOSLibName() {
XCTAssertEqual("darwin", Triple("x86_64-apple-macosx").clangOSLibName)
XCTAssertEqual("darwin", Triple("arm64-apple-ios13.0").clangOSLibName)
XCTAssertEqual("linux", Triple("aarch64-unknown-linux-android24").clangOSLibName)
XCTAssertEqual("wasi", Triple("wasm32-unknown-wasi").clangOSLibName)
XCTAssertEqual("wasip1", Triple("wasm32-unknown-wasip1-threads").clangOSLibName)
XCTAssertEqual("none", Triple("arm64-unknown-none").clangOSLibName)
}

func testToolchainSelection() {
let diagnostics = DiagnosticsEngine()
struct None { }
Expand Down