Skip to content

Commit

Permalink
Move check for LLVM toolchain outside of repository_rule (#1090)
Browse files Browse the repository at this point in the history
Checking `CC=clang` in the implementation of the `repository_rule`
doesn't work when using `--incompatible_enable_cc_toolchain_resolution`
(for example when using https://github.com/grailbio/bazel-toolchain to
bring a hermetic LLVM toolchain).

Moving the check for LLVM the `repository_rule` to the Swift toolchain
impl used by all `rule`s instead solves this issue.

I tested that the check (the failure message) is triggered on Linux
with:
- only `gcc` installed
- a LLVM toolchain configured in `WORKSPACE` but without
`--incompatible_enable_cc_toolchain_resolution`

Fixes #991
  • Loading branch information
gferon authored Aug 16, 2023
1 parent 2675128 commit df485c2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 0 additions & 6 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 5 additions & 0 deletions swift/internal/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit df485c2

Please sign in to comment.