Skip to content

Commit

Permalink
Use llvm-ar as default librarian on Unix platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
finagolfin committed Aug 18, 2023
1 parent 1826ef6 commit f847965
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
17 changes: 13 additions & 4 deletions Sources/PackageModel/UserToolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,7 @@ public final class UserToolchain: Toolchain {
}
return "link"
}
// TODO(compnerd) consider defaulting to `llvm-ar` universally with
// a fallback to `ar`.
return triple.isAndroid() ? "llvm-ar" : "ar"
return "llvm-ar"
}()

if let librarian = UserToolchain.lookup(
Expand All @@ -190,7 +188,18 @@ public final class UserToolchain: Toolchain {
if let librarian = try? UserToolchain.getTool(tool, binDirectories: binDirectories) {
return librarian
}
return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun)
if triple.isApple() || triple.isWindows() {
return try UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: useXcrun)
} else {
if let librarian = try? UserToolchain.findTool(tool, envSearchPaths: searchPaths, useXcrun: false) {
return librarian
}
// Fall back to looking for binutils `ar` if `llvm-ar` can't be found.
if let librarian = try? UserToolchain.getTool("ar", binDirectories: binDirectories) {
return librarian
}
return try UserToolchain.findTool("ar", envSearchPaths: searchPaths, useXcrun: false)
}
}

/// Determines the Swift compiler paths for compilation and manifest parsing.
Expand Down
2 changes: 1 addition & 1 deletion Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4244,7 +4244,7 @@ final class BuildPlanTests: XCTestCase {
description: "Archiving \(buildPath.appending(components: "library.a").escapedPathString())"
args: ["\(result.plan.buildParameters.toolchain.librarianPath.escapedPathString())","-static","-o","\(buildPath.appending(components: "library.a").escapedPathString())","@\(buildPath.appending(components: "rary.product", "Objects.LinkFileList").escapedPathString())"]
"""))
} else { // assume Unix `ar` is the librarian
} else { // assume `llvm-ar` is the librarian
XCTAssertMatch(contents, .contains("""
"C.rary-debug.a":
tool: shell
Expand Down
4 changes: 1 addition & 3 deletions Tests/BuildTests/MockBuildTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ struct MockToolchain: PackageModel.Toolchain {
let librarianPath = AbsolutePath("/fake/path/to/link.exe")
#elseif os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
let librarianPath = AbsolutePath("/fake/path/to/libtool")
#elseif os(Android)
let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
#else
let librarianPath = AbsolutePath("/fake/path/to/ar")
let librarianPath = AbsolutePath("/fake/path/to/llvm-ar")
#endif
let swiftCompilerPath = AbsolutePath("/fake/path/to/swiftc")
let includeSearchPaths = [AbsolutePath]()
Expand Down

0 comments on commit f847965

Please sign in to comment.