diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl index 0591f9801..d63912a93 100644 --- a/swift/internal/swift_autoconfiguration.bzl +++ b/swift/internal/swift_autoconfiguration.bzl @@ -237,12 +237,6 @@ def _create_linux_toolchain(repository_ctx): Args: repository_ctx: The repository rule context. """ - cc = repository_ctx.os.environ.get("CC") or "" - if "clang" not in cc: - fail("ERROR: rules_swift uses Bazel's CROSSTOOL to link, but Swift " + - "requires that the driver used is clang. Please set `CC=clang` " + - "in your environment before invoking Bazel.") - path_to_swiftc = repository_ctx.which("swiftc") if not path_to_swiftc: fail("No 'swiftc' executable found in $PATH") diff --git a/swift/internal/swift_toolchain.bzl b/swift/internal/swift_toolchain.bzl index 05624ccdf..a9801aa57 100644 --- a/swift/internal/swift_toolchain.bzl +++ b/swift/internal/swift_toolchain.bzl @@ -266,6 +266,11 @@ def _swift_toolchain_impl(ctx): toolchain_root = ctx.attr.root cc_toolchain = find_cpp_toolchain(ctx) + if cc_toolchain.compiler != "clang": + fail("Swift requires the configured CC toolchain to be LLVM (clang). " + + "Either use the locally installed LLVM by setting `CC=clang` in your environment " + + "before invoking Bazel, or configure a Bazel LLVM CC toolchain.") + if ctx.attr.os == "windows": swift_linkopts_cc_info = _swift_windows_linkopts_cc_info( ctx.attr.arch,