Skip to content

Commit 8ec7aee

Browse files
committed
Use llvm-ar as default librarian on Unix platforms
Resolves #5761
1 parent 28489b3 commit 8ec7aee

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Sources/PackageModel/UserToolchain.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ public final class UserToolchain: Toolchain {
172172
}
173173
return "link"
174174
}
175-
// TODO(compnerd) consider defaulting to `llvm-ar` universally with
176-
// a fallback to `ar`.
177-
return triple.isAndroid() ? "llvm-ar" : "ar"
175+
return "llvm-ar"
178176
}()
179177

180178
if let librarian = UserToolchain.lookup(
@@ -190,7 +188,18 @@ public final class UserToolchain: Toolchain {
190188
if let librarian = try? UserToolchain.getTool(tool, binDirectories: binDirectories) {
191189
return librarian
192190
}
193-
return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun)
191+
if triple.isApple() || triple.isWindows() {
192+
return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun)
193+
} else {
194+
if let librarian = try? UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: false) {
195+
return librarian
196+
}
197+
// Fall back to looking for binutils `ar` if `llvm-ar` can't be found.
198+
if let librarian = try? UserToolchain.getTool("ar", binDirectories: binDirectories) {
199+
return librarian
200+
}
201+
return try UserToolchain.findTool("ar", envSearchPaths: searchPaths, useXcrun: false)
202+
}
194203
}
195204

196205
/// Determines the Swift compiler paths for compilation and manifest parsing.

Tests/BuildTests/BuildPlanTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4244,7 +4244,7 @@ final class BuildPlanTests: XCTestCase {
42444244
description: "Archiving \(buildPath.appending(components: "library.a").escapedPathString())"
42454245
args: ["\(result.plan.buildParameters.toolchain.librarianPath.escapedPathString())","-static","-o","\(buildPath.appending(components: "library.a").escapedPathString())","@\(buildPath.appending(components: "rary.product", "Objects.LinkFileList").escapedPathString())"]
42464246
"""))
4247-
} else { // assume Unix `ar` is the librarian
4247+
} else { // assume `llvm-ar` is the librarian
42484248
XCTAssertMatch(contents, .contains("""
42494249
"C.rary-debug.a":
42504250
tool: shell

Tests/BuildTests/MockBuildTestHelper.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ struct MockToolchain: PackageModel.Toolchain {
2222
let librarianPath = AbsolutePath("/fake/path/to/link.exe")
2323
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
2424
let librarianPath = AbsolutePath("/fake/path/to/libtool")
25-
#elseif os(Android)
26-
let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
2725
#else
28-
let librarianPath = AbsolutePath("/fake/path/to/ar")
26+
let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
2927
#endif
3028
let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
3129
let includeSearchPaths = [AbsolutePath]()

0 commit comments

Comments
 (0)