Skip to content

Use llvm-ar as default librarian on Unix platforms #6829

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
merged 1 commit into from
Sep 6, 2023
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
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