<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/63135>63135</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Bazel] LLVM builds fail unless NVPTX backend is enabled in llvm_configure
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          j2kun
      </td>
    </tr>
</table>

<pre>
    When I set up the build rules for a project (https://github.com/google/heir/tree/2054509f517a1b2abaaeff0e592f99d223f383a6), I decided I only wanted to compile the X86 backend in `llvm_configure`.

The result was a build error like this when building most targets.

```
ERROR: /home/j2kun/.cache/bazel/_bazel_j2kun/fc8ffaa09c93321753c7c87483153cea/external/llvm-project/mlir/test/BUILD.bazel:591:11: no such target '@llvm-project//llvm:NVPTXCodeGen': target 'NVPTXCodeGen' not declared in package 'llvm' defined by /home/j2kun/.cache/bazel/_bazel_j2kun/fc8ffaa09c93321753c7c87483153cea/external/llvm-project/llvm/BUILD.bazel (Tip: use `query "@llvm-project//llvm:*"` to see all the targets in that package) and referenced by '@llvm-project//mlir/test:TestGPU'
```

This can be reproduced by checking out the above repository at `2054509f517a1b2abaaeff0e592f99d223f383a6` and commenting out [this line](https://github.com/google/heir/blob/2054509f517a1b2abaaeff0e592f99d223f383a6/bazel/setup_llvm.bzl#L15), and then running 

```
bazel build @llvm-project//mlir/...:all
```

It seems like these GPU-related targets should be conditionally included when the relevant backend targets are present.

I asked about this [on discord](https://discord.com/channels/636084430946959380/636732535434510338/1110974700978446368) and got no response. Seems like a minor bug, and I understand bazel support is best effort, so for now the workaround is just to compile `NVPTX` as well.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8Vd2O2zYTfRr6ZhCDIkX9XPjCG38ODOzXBukmzd2CEkcWY5p0-RN38_QFaTubBMGiuSlgCKZIjubMOXNGhqD3F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