Skip to content

Commit

Permalink
Make llvm-ar optional for Swift < 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gferon committed Sep 21, 2023
1 parent abde801 commit 3aba1f8
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 3aba1f8

Please sign in to comment.