diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl index 05593d3eb..51efe1451 100644 --- a/swift/internal/swift_autoconfiguration.bzl +++ b/swift/internal/swift_autoconfiguration.bzl @@ -283,6 +283,21 @@ alias( ) """) +def _toolchain_overriden_tools(toolchain_root, extension = ""): + tools = { + "ld": toolchain_root.get_child("lld" + extension), + "llvm-cov": toolchain_root.get_child("llvm-cov" + extension), + "llvm-profdata": toolchain_root.get_child("llvm-profdata" + extension), + "cpp": toolchain_root.get_child("clang-cpp" + extension), + "gcc": toolchain_root.get_child("clang" + extension), + } + + # llvm-ar is not shipped before Swift 5.8 + ar = toolchain_root.get_child("llvm-ar" + extension) + if ar.exists: + tools["ar"] = ar + return tools + def _create_linux_cc_toolchain(repository_ctx): """Creates BUILD targets for the Swift-provided C++ toolchain on Linux. @@ -292,14 +307,7 @@ def _create_linux_cc_toolchain(repository_ctx): toolchain_root = _toolchain_root(repository_ctx) cpu = get_cpu_value(repository_ctx) - configure_unix_toolchain(repository_ctx, cpu, overriden_tools = { - "ar": toolchain_root.get_child("llvm-ar"), - "ld": toolchain_root.get_child("lld"), - "llvm-cov": toolchain_root.get_child("llvm-cov"), - "llvm-profdata": toolchain_root.get_child("llvm-profdata"), - "cpp": toolchain_root.get_child("clang-cpp"), - "gcc": toolchain_root.get_child("clang"), - }) + configure_unix_toolchain(repository_ctx, cpu, overriden_tools = _toolchain_overriden_tools(toolchain_root)) def _create_windows_cc_toolchain(repository_ctx): """Creates BUILD targets for the Swift-provided C++ toolchain on Windows. @@ -309,14 +317,7 @@ def _create_windows_cc_toolchain(repository_ctx): """ toolchain_root = _toolchain_root(repository_ctx) - configure_windows_toolchain(repository_ctx, overriden_tools = { - "ar": toolchain_root.get_child("llvm-ar.exe"), - "ld": toolchain_root.get_child("lld.exe"), - "llvm-cov": toolchain_root.get_child("llvm-cov.exe"), - "llvm-profdata": toolchain_root.get_child("llvm-profdata.exe"), - "cpp": toolchain_root.get_child("clang-cpp.exe"), - "gcc": toolchain_root.get_child("clang.exe"), - }) + configure_windows_toolchain(repository_ctx, overriden_tools = _toolchain_overriden_tools(toolchain_root, ".exe")) def _create_linux_toolchain(repository_ctx): """Creates BUILD targets for the Swift toolchain on Linux.