Skip to content
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

Unix: Use llvm-ar by default #1244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,15 @@ extension GenericUnixToolchain {
commandLine.appendPath(outputFile)
return try resolvedTool(clangTool, pathOverride: clangPath)
case .staticLibrary:
// We're using 'ar' as a linker
// We're using 'llvm-ar' as a linker
commandLine.appendFlag("crs")
commandLine.appendPath(outputFile)

commandLine.append(contentsOf: inputs.lazy.filter {
lto == nil ? $0.type == .object
: $0.type == .object || $0.type == .llvmBitcode
}.map { .path($0.file) })
if targetTriple.environment == .android {
// Always use the LTO archiver llvm-ar for Android
return try resolvedTool(.staticLinker(.llvmFull))
} else {
return try resolvedTool(.staticLinker(lto))
}
return try resolvedTool(.staticLinker(.llvmFull))
}

}
Expand Down
5 changes: 1 addition & 4 deletions Sources/SwiftDriver/Toolchains/GenericUnixToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,7 @@ public final class GenericUnixToolchain: Toolchain {
switch tool {
case .swiftCompiler:
return try lookup(executable: "swift-frontend")
case .staticLinker(nil):
return try lookup(executable: "ar")
case .staticLinker(.llvmFull),
.staticLinker(.llvmThin):
case .staticLinker:
return try lookup(executable: "llvm-ar")
case .dynamicLinker:
// FIXME: This needs to look in the tools_directory first.
Expand Down
3 changes: 2 additions & 1 deletion Tests/SwiftDriverTests/SwiftDriverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,8 @@ final class SwiftDriverTests: XCTestCase {

let linkJob = plannedJobs[3]
let cmd = linkJob.commandLine
// we'd expect "ar crs libTest.a foo.o bar.o"
// we'd expect "llvm-ar crs libTest.a foo.o bar.o"
XCTAssertTrue(linkJob.tool.name.contains("llvm-ar"))
XCTAssertTrue(cmd.contains(.flag("crs")))
XCTAssertTrue(commandContainsTemporaryPath(cmd, "foo.o"))
XCTAssertTrue(commandContainsTemporaryPath(cmd, "bar.o"))
Expand Down